Show
Ignore:
Timestamp:
11/05/10 17:55:50 (3 years ago)
Author:
rafael.soares
Message:

Implemented action in the admin to publish an clinical trial, close #206

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/opentrials/repository/admin.py

    r611 r679  
    22 
    33from django.contrib import admin 
     4from django.utils.translation import ugettext as _ 
     5 
    46from repository.models import * 
    57 
     
    2527    list_display_links = ('identifier','short_title',) 
    2628    search_fields = ('scientific_title', 'public_title', 'i_freetext',) 
    27     list_filter = ('updated', 'study_type', 'phase', 'recruitment_status',) 
     29    list_filter = ('updated', 'study_type', 'phase', 'recruitment_status', 'status',) 
    2830    date_hierarchy = 'updated' 
    2931    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") 
    3052 
    3153class DescriptorAdmin(admin.ModelAdmin):