Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_app_order(sender, instance, **kwargs):
# check if another app have the same order
count = App.objects.filter(order=instance.order).count()
# set app correct order
if instance.order == 0 or count > 1:
max_order = App.objects.aggregate(
Max("order"))["order__max"]
if max_order:
instance.order = max_order+1
else:
instance.order = 1
# -*- coding: utf-8 -*-
from django.contrib import admin
from .models import App, AppStore, AppType, AppInstance
from guardian.admin import GuardedModelAdmin
# Register your models here.
@admin.register(App)
class AppModelAdmin(GuardedModelAdmin):
pass
@admin.register(AppStore)
class AppStoreModelAdmin(admin.ModelAdmin):
pass
@admin.register(AppType)
class AppTypeModelAdmin(admin.ModelAdmin):
pass
@admin.register(AppInstance)
class AppInstanceModelAdmin(admin.ModelAdmin):
def remove_unwanted(info):
dictionary = info.__dict__.get('_data', {}) if info else {}
app_fields = [
str(field.name)
for field in sorted(App._meta.fields + App._meta.many_to_many)
]
app_fields.append("type")
clean_data = {
k: v
for k, v in dictionary.items() if str(k) in app_fields
}
return clean_data
def delete_app(self):
try:
app = App.objects.get(name=self.name)
app.delete()
except App.DoesNotExist:
pass
active = bundle.obj.config.active
return active
def dehydrate_pending(self, bundle):
app = bundle.obj
cartoview_app = CartoviewApp.objects.get(app.name)
return cartoview_app.pending
def dehydrate_categories(self, bundle):
return [category.name for category in bundle.obj.category.all()]
def dehydrate_app_instance_count(self, bundle):
return bundle.obj.appinstance_set.all().count()
class Meta():
queryset = App.objects.all().order_by('order')
filtering = {
"id": ALL,
"name": ALL,
"title": ALL,
"store": ALL_WITH_RELATIONS,
"single_instance": ALL
}
can_edit = True
def _build_url_exp(self, view, single=False):
name = view + "_app"
if single:
exp = r"^(?P%s)/(?P\w[\w/-]*)/%s%s$" % (
self._meta.resource_name,
view,
trailing_slash(),
def remove_unwanted(cls, info):
dictionary = info.__dict__.get('_data', {})
app_fields = [
str(field.name)
for field in sorted(App._meta.fields + App._meta.many_to_many)
]
app_fields.append("type")
clean_data = {
k: v
for k, v in dictionary.items() if str(k) in app_fields
}
return clean_data