Exemplo n.º 1
0
class InvitationAdmin(admin.ModelAdmin):
    date_hierarchy = u'created'
    list_display = [
        u'id',
        u'email',
        u'created',
        decorate(
            lambda o: u'Accepted' if o.is_accepted else u'Expired'
            if o.is_expired else u'Pending' if o.is_pending else u'--',
            short_description=u'State',
        ),
        decorate(
            lambda o: admin_obj_format(
                o.invitor, u'{obj.first_name} {obj.last_name} <{obj.email}>'),
            short_description=u'Invitor',
            admin_order_field=u'invitor__email',
        ),
        decorate(
            lambda o: admin_obj_format(
                o.invitee, u'{obj.first_name} {obj.last_name} <{obj.email}>'),
            short_description=u'Invitee',
            admin_order_field=u'invitee__email',
        ),
    ]
    list_filter = [
        u'created',
        simple_list_filter_factory(u'State', u'state', [
            (u'1', u'Accepted', lambda qs: qs.accepted()),
            (u'2', u'Expired', lambda qs: qs.expired()),
            (u'3', u'Pending', lambda qs: qs.pending()),
        ]),
    ]
    search_fields = [
        u'=id',
        u'email',
        u'invitor__first_name',
        u'invitor__last_name',
        u'invitor__email',
        u'invitee__first_name',
        u'invitee__last_name',
        u'invitee__email',
    ]
    ordering = [
        u'-created',
        u'-id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'invitor',
        u'invitee',
        u'message',
    ]
    inlines = []

    def get_queryset(self, request):
        queryset = super(InvitationAdmin, self).get_queryset(request)
        queryset = queryset.select_related(u'invitor')
        queryset = queryset.select_related(u'invitee')
        return queryset
Exemplo n.º 2
0
class MessageAdmin(admin.ModelAdmin):
    date_hierarchy = u'created'
    list_display = [
            u'id',
            u'type',
            decorate(
                lambda o: o.from_formatted,
                short_description=u'From',
                admin_order_field=u'from_mail',
                ),
            decorate(
                lambda o: u'; '.join(u'{}: {}'.format(k, v) for k, v in [
                    (u'To', o.to_formatted),
                    (u'Cc', o.cc_formatted),
                    (u'Bcc', o.bcc_formatted),
                    ] if v),
                short_description=u'Recipients',
                ),
            u'created',
            u'processed',
            ]
    list_filter = [
            u'type',
            u'created',
            simple_list_filter_factory(u'Processed', u'processed', [
                (u'1', u'Yes', lambda qs: qs.processed()),
                (u'0', u'No',  lambda qs: qs.not_processed()),
                ]),
            ]
    search_fields = [
            u'=id',
            u'from_name',
            u'from_mail',
            u'recipient__name',
            u'recipient__mail',
            u'received_for',
            ]
    ordering = [
            u'-created',
            u'-id',
            ]
    exclude = [
            ]
    readonly_fields = [
            ]
    raw_id_fields = [
            ]
    inlines = [
            RecipientInline,
            ]

    def get_queryset(self, request):
        queryset = super(MessageAdmin, self).get_queryset(request)
        queryset = queryset.prefetch_related(Message.prefetch_recipients())
        return queryset
Exemplo n.º 3
0
class BranchAdmin(admin.ModelAdmin):
    date_hierarchy = None
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(o.inforequest),
            short_description=u'Inforequest',
            admin_order_field=u'inforequest',
        ),
        decorate(
            lambda o: admin_obj_format(o.obligee, u'{obj.name}'),
            short_description=u'Obligee',
            admin_order_field=u'obligee',
        ),
        decorate(
            lambda o: admin_obj_format(o.advanced_by),
            short_description=u'Advanced by',
            admin_order_field=u'advanced_by',
        ),
    ]
    list_filter = [
        simple_list_filter_factory(u'Advanced', u'advanced', [
            (u'1', u'Yes', lambda qs: qs.advanced()),
            (u'2', u'No', lambda qs: qs.main()),
        ]),
    ]
    search_fields = [
        u'=id',
        u'=inforequest__id',
        u'obligee__name',
        u'=advanced_by__id',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'inforequest',
        u'obligee',
        u'historicalobligee',
        u'advanced_by',
    ]
    inlines = []

    def get_queryset(self, request):
        queryset = super(BranchAdmin, self).get_queryset(request)
        queryset = queryset.select_related(u'inforequest')
        queryset = queryset.select_related(u'obligee')
        queryset = queryset.select_related(u'advanced_by')
        return queryset
Exemplo n.º 4
0
class ProfileAdmin(admin.ModelAdmin):
    date_hierarchy = None
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(
                o.user, u'{obj.first_name} {obj.last_name} <{obj.email}>'),
            short_description=u'User',
            admin_order_field=u'user__email',
        ),
        u'street',
        u'city',
        u'zip',
        decorate(
            lambda o: o.undecided_emails_count,
            short_description=u'Undecided E-mails',
            admin_order_field=u'undecided_emails_count',
        ),
    ]
    list_filter = [
        simple_list_filter_factory(u'Undecided E-mail', u'undecided', [
            (u'1', u'With',
             lambda qs: qs.filter(undecided_emails_count__gt=0)),
            (u'0', u'Without', lambda qs: qs.filter(undecided_emails_count=0)),
        ]),
    ]
    search_fields = [
        u'=id',
        u'user__first_name',
        u'user__last_name',
        u'user__email',
        u'street',
        u'city',
        u'zip',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'user',
    ]
    inlines = []

    def get_queryset(self, request):
        queryset = super(ProfileAdmin, self).get_queryset(request)
        queryset = queryset.select_related(u'user')
        queryset = queryset.select_undecided_emails_count()
        return queryset
Exemplo n.º 5
0
class HistoricalObligeeAdmin(admin.ModelAdmin):
    date_hierarchy = u'history_date'
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(o.history_object),
            short_description=u'Obligee',
            admin_order_field=u'id',
        ),
        u'name',
        u'status',
        u'history_date',
        u'history_type',
    ]
    list_filter = [
        u'status',
        u'history_date',
        u'history_type',
    ]
    search_fields = [
        u'=id',
        u'name',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'history_user',
    ]
    inlines = []
Exemplo n.º 6
0
class DistrictAdmin(admin.ModelAdmin):
    date_hierarchy = None
    list_display = [
        u'id',
        u'name',
        decorate(
            lambda o: admin_obj_format(o.region, u'{obj.name}'),
            short_description=u'Region',
            admin_order_field=u'region__name',
        ),
    ]
    list_filter = [
        u'region__name',
    ]
    search_fields = [
        u'=id',
        u'name',
        u'=region__id',
        u'region__name',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = [
        u'slug',
    ]
    raw_id_fields = [
        u'region',
    ]
    inlines = []
Exemplo n.º 7
0
class ObligeeAliasAdmin(admin.ModelAdmin):
    date_hierarchy = None
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(o.obligee, u'{obj.name}'),
            short_description=u'Obligee',
            admin_order_field=u'obligee__name',
        ),
        u'name',
    ]
    list_filter = [
        u'obligee__type',
        u'obligee__status',
    ]
    search_fields = [
        u'=id',
        u'name',
        u'obligee__name',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = [
        u'slug',
    ]
    raw_id_fields = [
        u'obligee',
    ]
    inlines = []
Exemplo n.º 8
0
class NeighbourhoodAdmin(admin.ModelAdmin):
    date_hierarchy = None
    list_display = [
        u'id',
        u'name',
        decorate(
            lambda o: admin_obj_format(o.municipality, u'{obj.name}'),
            short_description=u'Municipality',
            admin_order_field=u'municipality__name',
        ),
        decorate(
            lambda o: admin_obj_format(o.district, u'{obj.name}'),
            short_description=u'District',
            admin_order_field=u'district__name',
        ),
        decorate(
            lambda o: admin_obj_format(o.region, u'{obj.name}'),
            short_description=u'Region',
            admin_order_field=u'region__name',
        ),
    ]
    list_filter = [
        u'district__name',
        u'region__name',
    ]
    search_fields = [
        u'=id',
        u'name',
        u'=municipality__id',
        u'municipality__name',
        u'=district__id',
        u'district__name',
        u'=region__id',
        u'region__name',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'municipality',
        u'district',
        u'region',
    ]
    inlines = []
Exemplo n.º 9
0
class InforequestDraftAdmin(admin.ModelAdmin):
    date_hierarchy = u'modified'
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(
                o.applicant, u'{obj.first_name} {obj.last_name} <{obj.email}>'
            ),
            short_description=u'Applicant',
            admin_order_field=u'applicant__email',
        ),
        decorate(
            lambda o: admin_obj_format(o.obligee, u'{obj.name}'),
            short_description=u'Obligee',
            admin_order_field=u'obligee',
        ),
        u'modified',
    ]
    list_filter = [
        u'modified',
    ]
    search_fields = [
        u'=id',
        u'applicant__first_name',
        u'applicant__last_name',
        u'applicant__email',
        u'obligee__name',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'applicant',
        u'obligee',
    ]
    inlines = []

    def get_queryset(self, request):
        queryset = super(InforequestDraftAdmin, self).get_queryset(request)
        queryset = queryset.select_related(u'applicant')
        queryset = queryset.select_related(u'obligee')
        return queryset
Exemplo n.º 10
0
class ActionAdmin(admin.ModelAdmin):
    date_hierarchy = u'created'
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(o.branch),
            short_description=u'Branch',
            admin_order_field=u'branch',
        ),
        decorate(
            lambda o: admin_obj_format(o.email),
            short_description=u'E-mail',
            admin_order_field=u'email',
        ),
        u'type',
        u'created',
    ]
    list_filter = [
        u'type',
        u'created',
    ]
    search_fields = [
        u'=id',
        u'=branch__id',
        u'=email__id',
    ]
    ordering = [
        u'-created',
        u'-id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'branch',
        u'email',
    ]
    inlines = []

    def get_queryset(self, request):
        queryset = super(ActionAdmin, self).get_queryset(request)
        queryset = queryset.select_related(u'branch')
        queryset = queryset.select_related(u'email')
        return queryset
Exemplo n.º 11
0
class ObligeeAdmin(admin.ModelAdmin):
    date_hierarchy = None
    list_display = [
        u'id',
        u'name',
        u'city',
        u'type',
        u'status',
        decorate(
            lambda o: u' '.join(t.key for t in o.tags.all()),
            short_description=u'Tags',
        ),
        decorate(
            lambda o: u' '.join(t.key for t in o.groups.all()),
            short_description=u'Groups',
        ),
    ]
    list_filter = [
        u'type',
        u'status',
    ]
    search_fields = [
        u'=id',
        u'name',
        u'ico',
        u'city',
        u'emails',
        u'tags__key',
        u'groups__key',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = [
        u'slug',
    ]
    raw_id_fields = [
        u'tags',
        u'groups',
    ]
    inlines = []
Exemplo n.º 12
0
class InvitationSupplyAdmin(admin.ModelAdmin):
    date_hierarchy = None
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(
                o.user, u'{obj.first_name} {obj.last_name} <{obj.email}>'),
            short_description=u'User',
            admin_order_field=u'user__email',
        ),
        u'enabled',
        u'unlimited',
        u'supply',
    ]
    list_filter = [
        u'enabled',
        u'unlimited',
    ]
    search_fields = [
        u'=id',
        u'user__first_name',
        u'user__last_name',
        u'user__email',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'user',
    ]
    inlines = []

    def get_queryset(self, request):
        queryset = super(InvitationSupplyAdmin, self).get_queryset(request)
        queryset = queryset.select_related(u'user')
        return queryset
Exemplo n.º 13
0
class WizardDraftAdmin(admin.ModelAdmin):
    date_hierarchy = u'modified'
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(
                o.owner, u'{obj.first_name} {obj.last_name} <{obj.email}>'),
            short_description=u'Owner',
            admin_order_field=u'owner__email',
        ),
        u'step',
        u'modified',
    ]
    list_filter = [
        u'modified',
    ]
    search_fields = [
        u'id',  # ID contains wizard name
        u'owner__first_name',
        u'owner__last_name',
        u'owner__email',
        u'step',
    ]
    ordering = [
        u'id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'owner',
    ]
    inlines = []

    def get_queryset(self, request):
        queryset = super(WizardDraftAdmin, self).get_queryset(request)
        queryset = queryset.select_related(u'owner')
        return queryset
Exemplo n.º 14
0
    def test_as_function(self):
        func = decorate(lambda a, b: a + b, moo=4, foo=7)

        self.assertEqual(func.moo, 4)
        self.assertEqual(func.foo, 7)
        self.assertEqual(func(2, 3), 5)
Exemplo n.º 15
0
class AttachmentAdmin(admin.ModelAdmin):
    date_hierarchy = u'created'
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(o.generic_object),
            short_description=u'Generic Object',
            admin_order_field=u'generic_type__name',
        ),
        decorate(
            lambda o: admin_obj_format(o, u'{obj.file.name}', link=u'download'
                                       ),
            short_description=u'File',
            admin_order_field=u'file',
        ),
        u'name',
        u'content_type',
        u'created',
        decorate(
            lambda o: filesize(o.size),
            short_description=u'Size',
            admin_order_field=u'size',
        ),
    ]
    list_filter = [
        u'created',
        u'content_type',
        u'generic_type',
    ]
    search_fields = [
        u'=id',
        u'=generic_id',
        u'generic_type__name',
        u'file',
        u'name',
        u'content_type',
    ]
    ordering = [
        u'-id',
    ]
    exclude = [
        u'file',
    ]
    readonly_fields = []
    raw_id_fields = []
    inlines = []

    def get_queryset(self, request):
        queryset = super(AttachmentAdmin, self).get_queryset(request)
        queryset = queryset.prefetch_related(u'generic_object')
        return queryset

    def download_view(self, request, attachment_pk):
        attachment = Attachment.objects.get_or_404(pk=attachment_pk)
        return download(request, attachment)

    def get_urls(self):
        info = self.model._meta.app_label, self.model._meta.model_name
        download_view = self.admin_site.admin_view(self.download_view)
        urls = patterns(
            '',
            url(r'^(.+)/download/$',
                download_view,
                name=u'{}_{}_download'.format(*info)),
        )
        return urls + super(AttachmentAdmin, self).get_urls()
Exemplo n.º 16
0
    def test_as_function(self):
        func = decorate(lambda a, b: a + b, moo=4, foo=7)

        self.assertEqual(func.moo, 4)
        self.assertEqual(func.foo, 7)
        self.assertEqual(func(2, 3), 5)
Exemplo n.º 17
0
class InforequestAdmin(admin.ModelAdmin):
    date_hierarchy = u'submission_date'
    list_display = [
        u'id',
        decorate(
            lambda o: admin_obj_format(
                o.applicant, u'{obj.first_name} {obj.last_name} <{obj.email}>'
            ),
            short_description=u'Applicant',
            admin_order_field=u'applicant__email',
        ),
        decorate(
            lambda o: admin_obj_format(o.main_branch.obligee, u'{obj.name}'),
            short_description=u'Obligee',
            admin_order_field=u'branch__obligee__name',
        ),
        u'subject',
        u'submission_date',
        decorate(
            lambda o: o.undecided_emails_count,
            short_description=u'Undecided E-mails',
            admin_order_field=u'undecided_emails_count',
        ),
        u'closed',
    ]
    list_filter = [
        u'submission_date',
        simple_list_filter_factory(u'Undecided E-mail', u'undecided', [
            (u'1', u'With',
             lambda qs: qs.filter(undecided_emails_count__gt=0)),
            (u'0', u'Without', lambda qs: qs.filter(undecided_emails_count=0)),
        ]),
        u'closed',
    ]
    search_fields = [
        u'=id',
        u'applicant__first_name',
        u'applicant__last_name',
        u'applicant__email',
        u'branch__obligee__name',
        u'unique_email',
        u'subject',
    ]
    ordering = [
        u'-submission_date',
        u'-id',
    ]
    exclude = []
    readonly_fields = []
    raw_id_fields = [
        u'applicant',
    ]
    inlines = []

    def get_queryset(self, request):
        queryset = super(InforequestAdmin, self).get_queryset(request)
        queryset = queryset.select_related(u'applicant')
        queryset = queryset.select_undecided_emails_count()
        queryset = queryset.prefetch_related(
            Inforequest.prefetch_main_branch(
                None, Branch.objects.select_related(u'obligee')))
        return queryset