diff options
17 files changed, 86 insertions, 44 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 64772627b..c558587aa 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -169,8 +169,9 @@ class ContextRecord(BaseHistorizedItem, OwnPerms):      def get_years(cls):          years = set()          for res in list(cls.objects.values('operation__start_date')): -            yr = res['operation__start_date'].year -            years.add(yr) +            if res['operation__start_date']: +                yr = res['operation__start_date'].year +                years.add(yr)          return list(years)      @classmethod diff --git a/archaeological_files/ishtar_menu.py b/archaeological_files/ishtar_menu.py index 398b43f4b..236c47776 100644 --- a/archaeological_files/ishtar_menu.py +++ b/archaeological_files/ishtar_menu.py @@ -61,5 +61,33 @@ MENU_SECTIONS = [                    access_controls=['delete_file', 'delete_own_file']),                  ],),          ]), -    ) +    ), +    (100, SectionItem('dashboard', _(u"Dashboard"), +        childs=[ +                MenuItem('dashboard_main', _(u"General informations"), +                    model=models.File, +                    access_controls=['change_file', 'change_own_file']), +                MenuItem('dashboard_file', _(u"Archaeological files"), +                    model=models.File, +                    access_controls=['change_file', 'change_own_file']), +        ]), +    ),  ] +""" +        SectionItem('dashboard', _(u"Dashboard"), +            childs=[ +                    MenuItem('dashboard_main', _(u"General informations"), +                        model=models.File, +                        access_controls=['change_file', 'change_own_file']), +                    MenuItem('dashboard_file', _(u"Archaeological files"), +                        model=models.File, +                        access_controls=['change_file', 'change_own_file']), +                    #MenuItem('dashboard_treatment', _(u"Treatments"), +                    #   model=models.Treatment, +                    #    access_controls=['change_treatment',]), +                    #MenuItem('dashboard_warehouse', _(u"Warehouses"), +                    #    model=models.Warehouse, +                    #    access_controls=['change_warehouse',]), +            ]), +        ] +""" diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 0b95c021a..a91f6ed69 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -180,6 +180,7 @@ class FileByDepartment(models.Model):  class FileDashboard:      def __init__(self): +        from archaeological_operations.models import AdministrativeAct          main_dashboard = Dashboard(File)          self.total_number = main_dashboard.total_number @@ -266,7 +267,8 @@ class FileDashboard:          self.rescue['with_associated_operation'] = rescues\                          .filter(operations__isnull=False).count() -        self.rescue['with_associated_operation_percent'] = round( +        if self.rescue['total_number']: +            self.rescue['with_associated_operation_percent'] = round(                  float(self.rescue['with_associated_operation'])\                  /self.rescue['total_number']*100, 2) diff --git a/ishtar_common/templates/dashboard_file.html b/archaeological_files/templates/ishtar/dashboards/dashboard_file.html index cebd147f4..cebd147f4 100644 --- a/ishtar_common/templates/dashboard_file.html +++ b/archaeological_files/templates/ishtar/dashboards/dashboard_file.html diff --git a/archaeological_files/urls.py b/archaeological_files/urls.py index 4c5d923a2..72a6e2df7 100644 --- a/archaeological_files/urls.py +++ b/archaeological_files/urls.py @@ -59,4 +59,5 @@ urlpatterns += patterns('archaeological_files.views',             'show_file', name='show-historized-file'),       url(r'revert-file/(?P<pk>.+)/(?P<date>.+)$',             'revert_file', name='revert-file'), +     url(r'dashboard_file/$', 'dashboard_file', name='dashboard-file')  ) diff --git a/archaeological_files/views.py b/archaeological_files/views.py index 84ee84136..3ef8c0f28 100644 --- a/archaeological_files/views.py +++ b/archaeological_files/views.py @@ -70,12 +70,12 @@ get_administrativeactfile = get_item(AdministrativeAct,                            'operation__towns':'operation__towns__pk',                            'act_type__intented_to':'act_type__intented_to'}) -def dashboard_file(request, dct, obj_id=None, *args, **kwargs): +def dashboard_file(request, *args, **kwargs):      """      Main dashboard      """      dct = {'dashboard': models.FileDashboard()} -    return render_to_response('dashboard_file.html', dct, +    return render_to_response('ishtar/dashboards/dashboard_file.html', dct,                                context_instance=RequestContext(request))  file_search_wizard = SearchWizard.as_view( diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index cb305a93a..a02cb4402 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -140,8 +140,9 @@ class Find(BaseHistorizedItem, OwnPerms):              if not bi:                  continue              bi = bi[0] -            yr = bi.context_record.operation.start_date.year -            years.add(yr) +            if bi.context_record.operation.start_date: +                yr = bi.context_record.operation.start_date.year +                years.add(yr)          return list(years)      @classmethod diff --git a/archaeological_operations/ishtar_menu.py b/archaeological_operations/ishtar_menu.py index faf749480..7790087d9 100644 --- a/archaeological_operations/ishtar_menu.py +++ b/archaeological_operations/ishtar_menu.py @@ -84,5 +84,16 @@ MENU_SECTIONS = [                                                'change_own_operation']),                  ])          ]), -    ) +    ), +    (102, SectionItem('dashboard', _(u"Dashboard"), +        childs=[ +                MenuItem('dashboard_main', _(u"General informations"), +                    model=models.File, +                    access_controls=['change_file', 'change_own_file']), +                MenuItem('dashboard_operation', _(u"Operations"), +                    model=models.Operation, +                    access_controls=['change_operation', +                                     'change_own_operation']), +        ]), +    ),  ] diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 831190342..082a0072d 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -645,6 +645,8 @@ class OperationDashboard:                  cost_means, cost_sums = [], []                  for idx, year in enumerate(years):                      vals = [r_years[idx] for lbl, r_years in dct_res[res_key]] +                    if not vals: +                        continue                      sum_area = sum([a for a, c in vals])                      sum_cost = sum([c for a, c in vals])                      area_means.append(sum_area/len(vals)) diff --git a/ishtar_common/templates/dashboard_operation.html b/archaeological_operations/templates/ishtar/dashboards/dashboard_operation.html index 28f1dd9c6..28f1dd9c6 100644 --- a/ishtar_common/templates/dashboard_operation.html +++ b/archaeological_operations/templates/ishtar/dashboards/dashboard_operation.html diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py index 89e1a63fc..23632f1cf 100644 --- a/archaeological_operations/urls.py +++ b/archaeological_operations/urls.py @@ -71,4 +71,6 @@ urlpatterns += patterns('archaeological_operations.views',             'get_administrativeactop', name='get-administrativeactop'),       url(r'get-operationsource/(?P<type>.+)?$',             'get_operationsource', name='get-operationsource'), +     url(r'dashboard_operation/$', 'dashboard_operation', +         name='dashboard-operation')  ) diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index a9200cafa..502461130 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -89,12 +89,12 @@ get_administrativeactop = get_item(models.AdministrativeAct,                          'act_type__intented_to':'act_type__intented_to'}) -def dashboard_operation(request, dct, obj_id=None, *args, **kwargs): +def dashboard_operation(request, *args, **kwargs):      """      Operation dashboard      """      dct = {'dashboard': models.OperationDashboard()} -    return render_to_response('dashboard_operation.html', dct, +    return render_to_response('ishtar/dashboards/dashboard_operation.html', dct,                                context_instance=RequestContext(request))  operation_search_wizard = SearchWizard.as_view([ diff --git a/ishtar_common/menus.py b/ishtar_common/menus.py index 4802a369d..77dcabcd3 100644 --- a/ishtar_common/menus.py +++ b/ishtar_common/menus.py @@ -37,7 +37,7 @@ for app in settings.INSTALLED_APPS:  # sort  __section_items = [menu for order, menu in sorted(_extra_menus, -                                                 key=lambda x:x[0])] +                                                  key=lambda x:x[0])]  # regroup menus  _section_items, __keys = [], []  for section_item in __section_items: @@ -45,29 +45,11 @@ for section_item in __section_items:          __keys.append(section_item.idx)          _section_items.append(section_item)          continue -    _section_items[__keys.index(section_item.idx)].childs += section_item.childs -""" -        SectionItem('dashboard', _(u"Dashboard"), -            childs=[ -                    MenuItem('dashboard_main', _(u"General informations"), -                        model=models.File, -                        access_controls=['change_file', 'change_own_file']), -                    MenuItem('dashboard_file', _(u"Archaeological files"), -                        model=models.File, -                        access_controls=['change_file', 'change_own_file']), -                    MenuItem('dashboard_operation', _(u"Operations"), -                        model=models.Operation, -                        access_controls=['change_operation', -                                         'change_own_operation']), -                    #MenuItem('dashboard_treatment', _(u"Treatments"), -                    #   model=models.Treatment, -                    #    access_controls=['change_treatment',]), -                    #MenuItem('dashboard_warehouse', _(u"Warehouses"), -                    #    model=models.Warehouse, -                    #    access_controls=['change_warehouse',]), -            ]), -        ] -""" +    section_childs = _section_items[__keys.index(section_item.idx)].childs +    childs_idx = [child.idx for child in section_childs] +    for child in section_item.childs: +        if child.idx not in childs_idx: +            section_childs.append(child)  class Menu:      childs = _section_items diff --git a/ishtar_common/models.py b/ishtar_common/models.py index d8d3c3213..cff55ea5b 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -407,6 +407,7 @@ class Dashboard:              last_ids = history_model.objects.values('id')\                                              .annotate(hd=Max('history_date'))              last_ids = last_ids.filter(history_type=modif_type) +            from archaeological_finds.models import Find              if self.model == Find:                  last_ids = last_ids.filter(downstream_treatment_id__isnull=True)                  if modif_type == '+': diff --git a/ishtar_common/templates/dashboard_main.html b/ishtar_common/templates/ishtar/dashboards/dashboard_main.html index e710dbe16..e710dbe16 100644 --- a/ishtar_common/templates/dashboard_main.html +++ b/ishtar_common/templates/ishtar/dashboards/dashboard_main.html diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index cebea1dbe..597327379 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -48,8 +48,8 @@ actions = r"|".join(actions)  # other views  urlpatterns += patterns('ishtar_common.views',       # General -     url(r'(?P<action_slug>' + actions + r')/$', 'action', -           name='action'), +     url(r'dashboard-main/$', 'dashboard_main', +           name='dashboard-main'),       url(r'update-current-item/$', 'update_current_item',             name='update-current-item'),       url(r'new-person/(?P<parent_name>.+)?/$', @@ -66,4 +66,6 @@ urlpatterns += patterns('ishtar_common.views',             'new_organization', name='new-organization'),       url(r'autocomplete-organization/([0-9_]+)?$',             'autocomplete_organization', name='autocomplete-organization'), +     url(r'(?P<action_slug>' + actions + r')/$', 'action', +           name='action'),  ) diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 6c682c932..d0a5af7b7 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -535,6 +535,7 @@ def action(request, action_slug, obj_id=None, *args, **kwargs):      associated_wizard = action_slug + '_wizard'      dct = {}      globals_dct = globals() +    print action_slug      if action_slug in globals_dct:          return globals_dct[action_slug](request, dct, obj_id, *args, **kwargs)      elif hasattr(ishtar_forms, action_slug + "_wizard"): @@ -547,12 +548,20 @@ def dashboard_main(request, dct, obj_id=None, *args, **kwargs):      """      Main dashboard      """ -    dct = {'items':[ -        (_(u"Archaeological files"), models.Dashboard(models.File)), -        (_(u"Operations"), models.Dashboard(models.Operation)), -        (_(u"Context records"), models.Dashboard(models.ContextRecord)), -        (_(u"Archaeological items"), models.Dashboard(models.Item)), -        ], +    items = [] +    if 'archaeological_files' in settings.INSTALLED_APPS: +        from archaeological_files.models import File +        items.append((_(u"Archaeological files"), +                     models.Dashboard(File))) +    from archaeological_operations.models import Operation +    items.append((_(u"Operations"), models.Dashboard(Operation))) +    if 'archaeological_context_records' in settings.INSTALLED_APPS: +        from archaeological_context_records.models import ContextRecord +        items.append((_(u"Context records"), models.Dashboard(ContextRecord))) +    if 'archaeological_finds' in settings.INSTALLED_APPS: +        from archaeological_finds.models import Find +        items.append((_(u"Context records"), models.Dashboard(Find))) +    dct = {'items':items,             'ishtar_users':models.UserDashboard()} -    return render_to_response('dashboard_main.html', dct, +    return render_to_response('ishtar/dashboards/dashboard_main.html', dct,                                 context_instance=RequestContext(request)) | 
