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
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
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 = []
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 = []
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 = []
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 = []
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
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
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
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
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
def branch_applicant_live(self, branch): user = branch.inforequest.applicant if branch else None return admin_obj_format(user, u'{tag}\n{obj.first_name} {obj.last_name} <{obj.email}>')
def branch_details_live(self, branch): return admin_obj_format(branch)
def email_column(self, action): email = action.email return admin_obj_format(email)
def branch_applicant_column(self, action): user = action.branch.inforequest.applicant return admin_obj_format(user, u'{obj.first_name} {obj.last_name} <{obj.email}>')
def branch_column(self, action): branch = action.branch return admin_obj_format(branch)
def obligee_column(self, obligee): return admin_obj_format(obligee, link=False)
def user_column(self, profile): user = profile.user return admin_obj_format(user, u"{obj.first_name} {obj.last_name} <{obj.email}>")
def invitee_details_live(self, invitee): user = invitee return admin_obj_format(user, u'{tag}\n{obj.first_name} {obj.last_name} <{obj.email}>')
def invitee_column(self, invitation): user = invitation.invitee return admin_obj_format(user, u'{obj.first_name} {obj.last_name} <{obj.email}>')
def invitation_column(self, invitation): return admin_obj_format(invitation, link=False)
def message_column(self, message): return admin_obj_format(message, link=False)
def inforequest_field(self, branch): inforequest = branch.inforequest return admin_obj_format(inforequest)
def inforequest_applicant_field(self, branch): user = branch.inforequest.applicant return admin_obj_format(user, u'{obj.first_name} {obj.last_name} <{obj.email}>')
def email_details_live(self, email): return admin_obj_format(email)
def obligee_field(self, branch): obligee = branch.obligee return admin_obj_format(obligee, u'{obj.name}')
def message_details_live(self, message): return admin_obj_format(message)
def profile_field(self, user): profile = user.profile return admin_obj_format(profile)
def invitationsupply_column(self, invitationsupply): return admin_obj_format(invitationsupply, link=False)
def action_column(self, action): return admin_obj_format(action, link=False)
def user_column(self, profile): user = profile.user return admin_obj_format(user, u'{obj.first_name} {obj.last_name} <{obj.email}>')
def branch_inforequest_column(self, action): inforequest = action.branch.inforequest return admin_obj_format(inforequest)
def user_details_field(self, invitationsupply): user = invitationsupply.user return admin_obj_format(user, u'{tag}\n{obj.first_name} {obj.last_name} <{obj.email}>')
def branch_obligee_column(self, action): obligee = action.branch.obligee return admin_obj_format(obligee, u'{obj.name}')
def invitationsupply_field(self, user): invitationsupply = user.invitationsupply return admin_obj_format(invitationsupply)
def inforequest_field(self, action): inforequest = action.branch.inforequest if action else None return admin_obj_format(inforequest)
def branch_field(self, branch): return admin_obj_format(branch)
def branch_inforequest_live(self, branch): inforequest = branch.inforequest if branch else None return admin_obj_format(inforequest)
def action_field(self, message): action = try_except(lambda: message.action, None) return admin_obj_format(action)
def branch_obligee_live(self, branch): obligee = branch.obligee if branch else None return admin_obj_format(obligee, u'{tag}\n{obj.name}')
def inforequest_field(self, inforequest): return admin_obj_format(inforequest)
def obligee_field(self, inforequest): obligee = inforequest.main_branch.obligee return admin_obj_format(obligee, u'{obj.name}')
def profile_column(self, profile): return admin_obj_format(profile, link=False)
def inforequestdraft_field(self, draft): return admin_obj_format(draft)
def user_details_field(self, profile): user = profile.user return admin_obj_format(user, u"{tag}\n{obj.first_name} {obj.last_name} <{obj.email}>")
def obligee_field(self, draft): obligee = draft.obligee return admin_obj_format(obligee, u'{obj.name}')
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