예제 #1
0
 class Meta:
     model = User
     fields = '__all__'
     widgets = {
         'permissions': PrettyJSONWidget(),
         'executions': PrettyJSONWidget(),
     }
예제 #2
0
 class Meta:
     model = PerformanceData
     exclude = []
     widgets = {
         'data': PrettyJSONWidget(),
         'playlist_performances': PrettyJSONWidget(),
     }
예제 #3
0
 class Meta:
     model = UsageLog
     fields = '__all__'
     widgets = {
         'request': PrettyJSONWidget(),
         'response': PrettyJSONWidget(),
         'comments': PrettyJSONWidget(),
     }
예제 #4
0
class JSONFieldAdmin(admin.ModelAdmin):
    list_per_page = 20
    formfield_overrides = {
        JSONField: {
            "widget": PrettyJSONWidget(attrs={"initial": "parsed"})
        }
    }
예제 #5
0
class AccreditedCenterAdmin(admin.ModelAdmin):

    list_display = [
        'id', 'short_code', get_city, get_sro_member, 'active',
        'temporary_suspend_date', 'direction'
    ]
    list_filter = [
        'direction', 'active', 'temporary_suspend_date', SroStatusFilter
    ]
    search_fields = ('short_code', )
    # import pdb; pdb.set_trace()

    formfield_overrides = {
        JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }

    def save_model(self, request, obj, form, change):
        if 'active' in form.changed_data:
            if obj.active is True and obj.sro_member.status == 'na':
                messages.add_message(
                    request, messages.WARNING, 'Организация \
                    исключена из реестра СРО, активность центра не может быть \
                        установлена')
        super(AccreditedCenterAdmin, self).save_model(request, obj, form,
                                                      change)
예제 #6
0
class SettingsAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }
    list_display = ('id', 'name', 'isActive')
    list_display_links = (
        'id',
        'name',
    )
    actions = [delete_selected]

    # Defines delete permissions. Returns a delete button for Settings models as long as there are models present AND they aren't the default profile.
    def has_delete_permission(self, request, obj=None):
        return super().has_delete_permission(
            request, obj) and (not obj or obj.isActive is not True)

    # Checks to see if active profile status changed, and then makes it the only active profile if so.
    def save_model(self, request, obj, form, change):
        try:
            if obj.isActive:
                # Checks if there are other active profiles and deactivates them.
                active_profiles = Settings.objects.filter(
                    isActive=True).exclude(name=obj.name)
                if active_profiles:
                    active_profiles.update(isActive=False)
                super().save_model(request, obj, form, change)
            else:
                super().save_model(request, obj, form, change)
        except fastjsonschema.JsonSchemaValueException as e:
            self.message_user(request, e, level=messages.ERROR)
            logger.exception(e)
            return HttpResponseRedirect(request)
예제 #7
0
class IngestJobAdmin(BaseJobAdmin):
    list_display = (
        'id',
        'source_config_',
        'suid_',
        'status_',
        'date_started',
        'share_version',
    )
    list_select_related = BaseJobAdmin.list_select_related + ('suid', )
    readonly_fields = BaseJobAdmin.readonly_fields + (
        'suid', 'raw', 'transformer_version', 'regulator_version',
        'ingested_normalized_data', 'retries')
    fake_readonly_fields = ('transformed_datum', 'regulated_datum')
    formfield_overrides = {
        DateTimeAwareJSONField: {
            'widget':
            PrettyJSONWidget(attrs={
                'initial': 'parsed',
                'cols': 120,
                'rows': 20
            })
        }
    }

    def get_form(self, *args, **kwargs):
        form = super().get_form(*args, **kwargs)
        for field_name in self.fake_readonly_fields:
            form.base_fields[field_name].disabled = True
        return form

    def suid_(self, obj):
        return obj.suid.identifier
예제 #8
0
 class Meta:
     model = Exercise
     exclude = ['authored_by']
     widgets = {
         'data': PrettyJSONWidget(attrs={'initial': 'parsed'}),
         'id': forms.TextInput(attrs={'readonly': 'readonly'}),
     }
예제 #9
0
class ConfigurationAdmin(admin.ModelAdmin):
    list_display = ("name", "image", "traffic")
    list_editable = ("traffic", )
    readonly_fields = ("name", "image")
    formfield_overrides = {
        JSONField: {'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})},
    }
예제 #10
0
class UserAdmin(BaseUserAdmin):
    add_form = AccountUserCreationForm
    list_display = [
        'id',
        'name',
        'email',
    ]
    list_filter = [
        'is_active',
        'is_staff',
        'roles',
    ]
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('name', 'email', 'first_name', 'last_name', ),
        }),
    )

    fieldsets = (
        (None, {
            'fields': (
                'id',
                'name',
                'email',
                'first_name',
                'last_name',
                'user_metadata',
                'roles',
                'image',
                # 'app_metadata',
                'created',
                'modified',
            )
        }),
    )
    search_fields = [
        'email',
        'name',
        'first_name',
        'last_name',
    ]
    ordering = (
        'last_name',
        'first_name',
    )
    filter_horizontal = ()
    readonly_fields = [
        'id',
        'created',
        'modified',
    ]
    autocomplete_fields = [
        'roles',
    ]
    formfield_overrides = {
        JSONField: {'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})}
    }
예제 #11
0
파일: admin.py 프로젝트: split2021/API
class LogAdmin(admin.ModelAdmin):
    """
    """
    list_display = ('method', 'path', 'date')
    readonly_fields = ('path', 'method', 'body')
    formfield_overrides = {
        postgres.JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }
예제 #12
0
 class Meta:
     model = PageMeta
     fields = "__all__"
     widgets = {
         'json_ld':
         PrettyJSONWidget(attrs={
             'initial': 'parsed',
             'class': 'test'
         })
     }
예제 #13
0
 class Meta:
     model = View
     fields = '__all__'
     widgets = {
         'config':
         PrettyJSONWidget(attrs={
             'initial': 'parsed',
             'class': 'test'
         })
     }
예제 #14
0
class CityAdmin(admin.ModelAdmin):
    formfield_overrides = {
        JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }
    list_display = ('city', 'point', 'timezone', 'is_active', 'is_default')
    list_editable = (
        'is_active',
        'is_default',
    )
    inlines = (PlaceTypeTabularInline, )
예제 #15
0
class OrderAdmin(admin.ModelAdmin):
    model = Order
    list_display = ('product', 'procedure_datetime', 'physician', 'status')
    fields = ('status', 'product', 'procedure_datetime', 'physician',
              'cost_type', 'discounts')
    readonly_fields = ('product', 'procedure_datetime', 'physician',
                       'cost_type')
    list_filter = ['physician__client', 'product__category__specialty']
    formfield_overrides = {
        JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }
예제 #16
0
 class Meta:
     model = MapServerLayer
     fields = [
         'mapserver_layer_name',
         'wms_extent',
         'wms_enable_request',
         'units',
         'status',
         'mapfile',
         'mapfile_json',
     ]
     widgets = {
         'mapfile_json': PrettyJSONWidget(attrs={'initial': 'parsed'}),
     }
예제 #17
0
class CoinAdmin(DynamicRawIDMixin, admin.ModelAdmin):
    formfield_overrides = {
        JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }
    list_display = (
        'catalog_coin',
        'get_serie',
        'get_country',
        'owner',
        'get_year',
        'status',
        'get_mint',
    )
    list_select_related = (
        'catalog_coin',
        'owner',
        'catalog_coin__serie',
    )
    list_filter = (
        ('catalog_coin__serie', admin.RelatedOnlyFieldListFilter),
        'status',
        'catalog_coin__country',
        'catalog_coin__year',
        'catalog_coin__face_value',
        'catalog_coin__currency',
        'owner',
        'created',
    )
    ordering = ('catalog_coin__theme', )
    dynamic_raw_id_fields = ('catalog_coin', )

    @staticmethod
    def get_serie(instance):
        return instance.catalog_coin.serie.name

    @staticmethod
    def get_mint(instance):
        return instance.catalog_coin.mint

    @staticmethod
    def get_year(instance):
        return instance.catalog_coin.year

    @staticmethod
    def get_country(instance):
        return instance.catalog_coin.country
예제 #18
0
class ModelAdmin(DjangoModelAdmin):
    formfield_overrides = {
        JSONField: {
            "widget": PrettyJSONWidget(attrs={"initial": "parsed"})
        }
    }

    @cached_property
    def readonly_fields(self):
        field_names = Model.field_names
        return tuple(f for f in field_names
                     if f not in ("data", "computed", "raw"))

    @cached_property
    def list_display(self):
        return "__str__", "id", "type", "uri"
예제 #19
0
class NormalizedDataAdmin(admin.ModelAdmin):
    date_hierarchy = 'created_at'
    list_filter = [
        'source',
    ]
    raw_id_fields = ('tasks', )
    paginator = FuzzyPaginator
    formfield_overrides = {
        DateTimeAwareJSONField: {
            'widget':
            PrettyJSONWidget(attrs={
                'initial': 'parsed',
                'cols': 120,
                'rows': 20
            })
        }
    }
예제 #20
0
파일: admin.py 프로젝트: rswei026/Compiler
class AttendanceAdmin(ImportExportModelAdmin):
    resource_class = AttendanceResource
    fields = (
        'school',
        'attendance_date',
        'validation_status',
        'validation_date',
        'validation_owner',
        'close_reason',
        'students',
        'owner',
    )
    list_display = ('school', 'attendance_date', 'total_enrolled',
                    'total_attended', 'total_attended_male',
                    'total_attended_female', 'total_absences',
                    'total_absent_male', 'total_absent_female',
                    'validation_date', 'validation_status', 'close_reason',
                    'created', 'modified')
    list_filter = (
        'school',
        'school_type',
        LocationFilter,
        GovernorateFilter,
        'attendance_date',
        'validation_date',
        'validation_status',
        'alp_round',
        'education_year',
        'close_reason',
        SchoolStatusFilter,
    )
    date_hierarchy = 'attendance_date'

    formfield_overrides = {
        JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }

    def get_export_formats(self):
        from student_registration.users.utils import get_default_export_formats
        return get_default_export_formats()
예제 #21
0
class RawMessageAdmin(admin.ModelAdmin):
    formfield_overrides = {
        JSONField: {
            "widget": PrettyJSONWidget(attrs={"initial": "parsed"})
        }
    }
    list_display = (created_iso, "devid", "status")
    readonly_fields = ("devid", "status", "json_data")

    def reprocess(modeladmin, request, queryset):
        """ Action function for reprocessing messages. """
        for message in queryset:
            message.delete()
            parse_data.process_message(message.data)

    reprocess.short_description = "Reprocess messages through parser"
    actions = [reprocess]

    # TODO: Exclude temporarily to prevent crashing due to binascii.Error: Incorrect padding
    exclude = ("data", )
예제 #22
0
파일: admin.py 프로젝트: dustin2551/mex
class BaseModelAdmin(admin.ModelAdmin):

    actions = None

    formfield_overrides = {
        JSONField: {
            "widget": PrettyJSONWidget(attrs={"initial": "parsed"})
        }
    }

    def has_view_permission(self, request, obj=None):
        return True

    def has_change_permission(self, request, obj=None):
        return True

    def has_delete_permission(self, request, obj=None):
        return False

    def has_add_permission(self, request):
        return False
예제 #23
0
class RegistryRecordPersonalAdmin(admin.ModelAdmin):
    # form = JsonForm
    list_display = ('id', 'fio', 'udost_number', 'obl_att', 'place_of_att',
                    'date_created')
    list_display_links = ('id', 'fio')
    fields = ('fio', 'data', 'company', 'date_created', 'active_since',
              'active_until', 'extension_date', 'edo_id')
    list_filter = (('date_created', DateRangeFilter), )
    search_fields = ['fio', 'data']
    readonly_fields = ('company', 'edo_id')

    formfield_overrides = {
        JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }

    def obl_att(self, instance):
        try:
            activity = instance.data['activity']
            gtus = instance.data['gtus']
            return '{}-{}'.format(activity, gtus)
        except Exception as e:
            return 'ошибка обл. атт.: {}'.format(e)

    def udost_number(self, instance):
        try:
            udost_number = instance.data['udost']
            return '{}'.format(udost_number)
        except Exception as e:
            return 'ошибка номера: {}'.format(e)

    def place_of_att(self, instance):
        try:
            place_of_att = instance.data['place_of_att']
            return place_of_att
        except Exception:
            return '-'
    def test_widget_renders_parsed_view_when_requested(self):
        widget = PrettyJSONWidget(attrs={'initial': 'parsed'})

        result = widget.render(mock.MagicMock(), mock.MagicMock())

        self.assertIn('data-initial="parsed"', result)
    def test_widget_without_args_renders_raw_view(self):
        widget = PrettyJSONWidget()

        result = widget.render(mock.MagicMock(), mock.MagicMock())

        self.assertIn('data-initial="raw"', result)
예제 #26
0
 class Meta:
     model = Category
     fields = '__all__'
     widgets = {'properties': PrettyJSONWidget()}
예제 #27
0
 class Meta:
     model = Process
     fields = '__all__'
     widgets = {
         'type': PrettyJSONWidget(),
     }
예제 #28
0
class LexicalEntryAdmin(admin.ModelAdmin):
    formfield_overrides = {
        JSONField: {
            'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})
        }
    }
예제 #29
0
class PopulartimesAdmin(admin.ModelAdmin):
    formfield_overrides = {
        JSONField: {'widget': PrettyJSONWidget(attrs={'initial': 'parsed'})}
    }
예제 #30
0
 class Meta:
     model = StorageTable
     fields = '__all__'
     widgets = {
         'data': PrettyJSONWidget(),
     }
    def test_widget_renders_raw_view_when_invalid_requested(self):
        widget = PrettyJSONWidget(attrs={'initial': 'invalid_view'})

        result = widget.render(mock.MagicMock(), mock.MagicMock())

        self.assertIn('data-initial="raw"', result)
예제 #32
0
 class Meta:
     model = None
     fields = '__all__'
     widgets = {
         'data': PrettyJSONWidget(attrs={'initial': 'parsed', 'rows': 80, 'cols': 80}),
     }
예제 #33
0
 class Meta:
     model = Group
     fields = '__all__'
     widgets = {
         'permissions': PrettyJSONWidget(),
     }