Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def reorder(self, request, **kwargs):
ids_list = request.POST.get("apps", None)
if ids_list is not None:
ids_list = ids_list.split(",")
else:
ids_list = json.loads(request.body)["apps"]
for i in range(0, len(ids_list)):
app = App.objects.get(id=ids_list[i])
app.order = i + 1
app.save()
cartoview_app = CartoviewApp.objects.get(app.name)
if cartoview_app:
cartoview_app.order = app.order
cartoview_app.commit()
if i == (len(ids_list) - 1):
CartoviewApp.save()
self.log_throttled_access(request)
return self.create_response(request, {'success': True})
def save_instance(self, instance_id, owner, title, config, abstract,
map_id):
if instance_id is None:
instance_obj = AppInstance()
instance_obj.app = App.objects.get(name=self.app_name)
instance_obj.owner = owner
else:
instance_obj = AppInstance.objects.get(pk=instance_id)
instance_obj.title = title
instance_obj.config = config
instance_obj.abstract = abstract
instance_obj.map_id = map_id
instance_obj.save()
return instance_obj
def delete_app(self):
try:
app = App.objects.get(name=self.name)
app.delete()
except App.DoesNotExist:
pass
def obj_create(self, bundle, **kwargs):
"""
A ORM-specific implementation of ``obj_create``.
"""
bundle.obj = AppInstance()
bundle.obj.owner = bundle.request.user
app_name = bundle.data['appName']
bundle.obj.app = App.objects.get(name=app_name)
for key, value in list(kwargs.items()):
setattr(bundle.obj, key, value)
bundle = self.full_hydrate(bundle)
return self.save(bundle)
if request.method == 'POST':
apps_list = request.POST.get('apps', None)
if apps_list:
try:
apps = json.loads(apps_list)
menu_apps = apps['menu_apps']
non_menu_apps = apps['non_menu_apps']
for idx, val in enumerate(menu_apps):
app = App.objects.get(id=int(val['id']))
app.order = idx
app.in_menu = True
app.save()
for idx, val in enumerate(non_menu_apps):
app = App.objects.get(id=int(val['id']))
app.order = idx + len(menu_apps)
app.in_menu = False
app.save()
ajax_vars = {'success': True}
except BaseException:
ajax_vars = {'success': False}
return HttpResponse(
json.dumps(ajax_vars), content_type="application/json")
return HttpResponse(json.dumps(ajax_vars), content_type="application/json")
def move_down(request, app_id):
app = App.objects.get(id=app_id)
next_app = App.objects.get(
order=App.objects.filter(
order__gt=app.order).aggregate(Min('order'))['order__min'])
order = app.order
app.order = next_app.order
next_app.order = order
app.save()
next_app.save()
return HttpResponse(
json.dumps({
"success": True
}), content_type="application/json")
def install(self, restart=True):
with lock:
self.upgrade = False
if os.path.exists(self.app_dir):
try:
installed_app = App.objects.get(name=self.name)
if installed_app.version < self.version.version:
self.upgrade = True
else:
raise AppAlreadyInstalledException()
except App.DoesNotExist:
# NOTE:the following code handle if app downloaded and for
# some reason not added to the portal
self._rollback()
installed_apps = []
for name, version in list(self.version.dependencies.items()):
# use try except because AppInstaller.__init__ will handle
# upgrade if version not match
try:
app_installer = AppInstaller(
name, self.store.id, version, user=self.user)
installed_apps += app_installer.install(restart=False)
"You don't have permission to install <> app".
format(app_name)}, status=403)
if parse_version(version) <= parse_version(qs.first().version):
return Response({"details": "app already installed"},
status=400)
try:
installer = AppInstaller(
app_name, store_id, version, user=request.user)
installer.install()
except BaseException as e:
if isinstance(e, AppAlreadyInstalledException):
logger.warn(e)
return Response({"details": str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
serializer = AppSerializer(App.objects.get(name=app_name))
return Response(serializer.data,
status=status.HTTP_202_ACCEPTED)