| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | |
|---|
| 3 | from django.contrib import admin |
|---|
| 4 | from django.utils.translation import ugettext as _ |
|---|
| 5 | |
|---|
| 6 | from repository.models import * |
|---|
| 7 | |
|---|
| 8 | from polyglot.admin import TranslationInline, TranslationAdmin |
|---|
| 9 | |
|---|
| 10 | tabular_inline_models = [Descriptor, TrialNumber, PublicContact, ScientificContact, |
|---|
| 11 | TrialSecondarySponsor, TrialSupportSource] |
|---|
| 12 | tabular_inlines = [] |
|---|
| 13 | for model in tabular_inline_models: |
|---|
| 14 | cls_name = model.__name__+'line' |
|---|
| 15 | cls = type(cls_name, (admin.TabularInline,), {'model':model}) |
|---|
| 16 | tabular_inlines.append(cls) |
|---|
| 17 | |
|---|
| 18 | class OutcomeInline(admin.StackedInline): |
|---|
| 19 | model = Outcome |
|---|
| 20 | |
|---|
| 21 | class ClinicalTrialTranslationInline(TranslationInline): |
|---|
| 22 | model = ClinicalTrialTranslation |
|---|
| 23 | |
|---|
| 24 | class ClinicalTrialAdmin(admin.ModelAdmin): |
|---|
| 25 | inlines = tabular_inlines + [OutcomeInline, ClinicalTrialTranslationInline] |
|---|
| 26 | list_display = ('updated_str','identifier','short_title','recruitment_status',) |
|---|
| 27 | list_display_links = ('identifier','short_title',) |
|---|
| 28 | search_fields = ('scientific_title', 'public_title', 'i_freetext',) |
|---|
| 29 | list_filter = ('updated', 'study_type', 'phase', 'recruitment_status', 'status',) |
|---|
| 30 | date_hierarchy = 'updated' |
|---|
| 31 | save_on_top = True |
|---|
| 32 | actions = ['publish_action'] |
|---|
| 33 | |
|---|
| 34 | def publish_action(self, request, queryset): |
|---|
| 35 | rows_updated = 0 |
|---|
| 36 | |
|---|
| 37 | for obj in queryset: |
|---|
| 38 | if obj.status != 'published': |
|---|
| 39 | obj.status = 'published' |
|---|
| 40 | obj.save() |
|---|
| 41 | rows_updated += 1 |
|---|
| 42 | |
|---|
| 43 | if rows_updated == 0: |
|---|
| 44 | message = _("No clinical trial was published.") |
|---|
| 45 | elif rows_updated == 1: |
|---|
| 46 | message = "1 %s" % _("clinical trial was published.") |
|---|
| 47 | else: |
|---|
| 48 | message = "%s %s" % (rows_updated, _("clinical trials were published.")) |
|---|
| 49 | self.message_user(request, message) |
|---|
| 50 | |
|---|
| 51 | publish_action.short_description = _("Publish the selected clinical trials") |
|---|
| 52 | |
|---|
| 53 | class DescriptorAdmin(admin.ModelAdmin): |
|---|
| 54 | list_display = ('trial_identifier','vocabulary','code', 'text') |
|---|
| 55 | |
|---|
| 56 | if ClinicalTrial not in admin.site._registry: |
|---|
| 57 | admin.site.register(ClinicalTrial, ClinicalTrialAdmin) |
|---|
| 58 | |
|---|
| 59 | if Descriptor not in admin.site._registry: |
|---|
| 60 | admin.site.register(Descriptor, DescriptorAdmin) |
|---|
| 61 | |
|---|
| 62 | if Institution not in admin.site._registry: |
|---|
| 63 | admin.site.register(Institution) |
|---|
| 64 | |
|---|
| 65 | if Contact not in admin.site._registry: |
|---|
| 66 | admin.site.register(Contact) |
|---|