diff options
| -rw-r--r-- | ishtar/ishtar_base/menus.py | 5 | ||||
| -rw-r--r-- | ishtar/ishtar_base/models.py | 61 | ||||
| -rw-r--r-- | ishtar/ishtar_base/views.py | 8 | ||||
| -rw-r--r-- | ishtar/templates/dashboard_file.html | 82 | 
4 files changed, 153 insertions, 3 deletions
| diff --git a/ishtar/ishtar_base/menus.py b/ishtar/ishtar_base/menus.py index 7ffdce960..a5a0e17ec 100644 --- a/ishtar/ishtar_base/menus.py +++ b/ishtar/ishtar_base/menus.py @@ -99,7 +99,7 @@ class Menu:                      model=models.IshtarUser,                      access_controls=['add_ishtaruser',]),              ]), -        SectionItem('file_management', _(u"Archaelogical file"), +        SectionItem('file_management', _(u"Archaeological file"),              childs=[                      MenuItem('file_search', _(u"Search"),                          model=models.File, @@ -286,6 +286,9 @@ class Menu:                      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_file', _(u"Files"),                      #    model=models.File,                      #    access_controls=['change_file',]), diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py index 89cb8e605..6f29196ce 100644 --- a/ishtar/ishtar_base/models.py +++ b/ishtar/ishtar_base/models.py @@ -363,6 +363,46 @@ class UserDashboard:          self.types = types.annotate(number=Count('pk')).order_by(                                                         'person__person_type') +class FileDashboard: +    def __init__(self): +        main_dashboard = Dashboard(File) + +        self.total_number = main_dashboard.total_number + +        types = File.objects.values('file_type', 'file_type__label') +        self.types = types.annotate(number=Count('pk')).order_by('file_type') + +        self.by_years = main_dashboard.values + +        now = datetime.date.today() +        limit = datetime.date(now.year, now.month, 1) - datetime.timedelta(365) +        by_month = File.objects.filter(creation_date__gt=limit).extra( +                        {'month':"date_trunc('month', creation_date)"}) +        self.by_month = by_month.values('month').annotate(number=Count('pk') +                                                        ).order_by('-month') + +        # programmed +        self.prog = {} +        prog_type = FileType.objects.get(txt_idx='prog') +        progs = File.objects.filter(file_type=prog_type) +        self.prog['total_number'] = progs.count() +        by_year = progs.extra({'year':"date_trunc('year', creation_date)"}) +        self.prog['by_year'] = by_year.values('year').annotate(number=Count('pk') +                                                        ).order_by('-year') +        by_month = progs.filter(creation_date__gt=limit).extra( +                        {'month':"date_trunc('month', creation_date)"}) +        self.prog['by_month'] = by_month.values('month').annotate( +                                      number=Count('pk')).order_by('-month') + +        self.prog['by_dpts'] = FileByDepartment.objects.filter( +                       file__file_type=prog_type).values('department' +                       ).annotate(number=Count('file')).order_by('-number') +        FileTown = File.towns.through +        self.prog['towns'] = FileTown.objects.filter( +                       file__file_type=prog_type).values('town' +                       ).annotate(number=Count('file')).order_by('-number') + +  class Dashboard:      def __init__(self, model):          self.model = model @@ -386,7 +426,6 @@ class Dashboard:                      # deleted object are always referenced in history                      continue                  obj.history_date = idx['hd'] -                print unicode(obj), obj.pk                  last_lst.append(obj)          # years          self.years = model.get_years() @@ -643,7 +682,8 @@ class File(BaseHistorizedItem, OwnPerms):      permit_reference = models.CharField(_(u"Permit reference"),                                            max_length=60, blank=True, null=True)      is_active = models.BooleanField(_(u"Is active?"), default=True) -    towns = models.ManyToManyField("Town", verbose_name=_(u"Towns")) +    towns = models.ManyToManyField("Town", verbose_name=_(u"Towns"), +                                   related_name='file')      creation_date = models.DateField(_(u"Creation date"),                                       default=datetime.date.today)      reception_date = models.DateField(_(u'Reception date'), blank=True, @@ -732,6 +772,23 @@ class File(BaseHistorizedItem, OwnPerms):      def is_preventive(self):          return FileType.is_preventive(self.file_type.pk) +class FileByDepartment(models.Model): +    ''' +    Database view: don't forget to create it + +create view file_department (department_id, file_id) as +    select town."departement_id", file_towns."file_id" +        from ishtar_base_town town +    inner join ishtar_base_file_towns file_towns on +        file_towns."town_id"=town."id" order by town."departement_id"; +    ''' +    file = models.ForeignKey(File, verbose_name=_(u"File")) +    department = models.ForeignKey(Departement, verbose_name=_(u"Department"), +                                   blank=True, null=True) +    class Meta: +        managed = False +        db_table = 'file_department' +  class OperationType(GeneralType):      class Meta:          verbose_name = _(u"Operation type") diff --git a/ishtar/ishtar_base/views.py b/ishtar/ishtar_base/views.py index 6527dec3a..e0a96063c 100644 --- a/ishtar/ishtar_base/views.py +++ b/ishtar/ishtar_base/views.py @@ -662,3 +662,11 @@ def dashboard_main(request, dct, obj_id=None, *args, **kwargs):      return render_to_response('dashboard_main.html', dct,                                context_instance=RequestContext(request)) +def dashboard_file(request, dct, obj_id=None, *args, **kwargs): +    """ +    Main dashboard +    """ +    dct = {'dashboard': models.FileDashboard()} +    return render_to_response('dashboard_file.html', dct, +                              context_instance=RequestContext(request)) + diff --git a/ishtar/templates/dashboard_file.html b/ishtar/templates/dashboard_file.html new file mode 100644 index 000000000..e710dbe16 --- /dev/null +++ b/ishtar/templates/dashboard_file.html @@ -0,0 +1,82 @@ +{% extends "base.html" %} +{% load i18n %} +{% load range %} +{% block extra_head %} +{{form.media}} +{% endblock %} +{% block content %} +<div class='dashboard'> +{% for lbl, dashboard in items %} +  <div> +    <h3>{{lbl}}</h3> +    <h4>{% trans "Numbers" %}</h4> +    <p><strong>{% trans "Total:" %}</strong> {{dashboard.total_number}}</p> +    <div class='table'> +    <table> +    {% for idx, lbl, values in dashboard.values %} +      <tr class='idx {% if forloop.counter0|divisibleby:"2" %}even{%else%}odd{%endif%}'> +      <th>{{lbl}}</th> +      {% for value in values %}<td>{{value}}</td>{% endfor%} +      </tr> +    {% endfor%} +    </table> +    </div> +    {% if dashboard.years %} +    <h4>{% trans "By years" %}</h4> +    <ul> +      <li><strong>{% trans "Average:" %}</strong> {{dashboard.average}}</li> +      <li><strong>{% trans "Variance:" %}</strong> {{dashboard.variance}}</li> +      <li><strong>{% trans "Standard deviation:" %}</strong> {{dashboard.standard_deviation}}</li> +      <li><strong>{% trans "Median:" %}</strong> {{dashboard.median}}</li> +      <li><strong>{% trans "Mode:" %}</strong> {{dashboard.mode}}</li> +    </ul> +    {% endif %} +    {% if dashboard.operation_average %} +    <h4>{% trans "By operations" %}</h4> +    <ul> +      <li><strong>{% trans "Average:" %}</strong> {{dashboard.operation_average}}</li> +      <li><strong>{% trans "Variance:" %}</strong> {{dashboard.operation_variance}}</li> +      <li><strong>{% trans "Standard deviation:" %}</strong> {{dashboard.operation_standard_deviation}}</li> +      <li><strong>{% trans "Median:" %}</strong> {{dashboard.operation_median}}</li> +      <li><strong>{% trans "Mode:" %}</strong> {{dashboard.operation_mode}}</li> +    </ul> +    {% endif %} +    <h4>{% trans "Created last" %}</h4> +    <div class='table'> +    <table> +      <tr><th>{{lbl}}</th><th>{% trans "Created" %}</th><th></th></tr> +      {% for item in dashboard.lasts %}<tr> +        <td class='ref'>{{item}}</td> +        <td>{{item.history_date}}</td> +        <td>{% if item.get_show_url %}<a href="#" onclick='load_window("{{item.get_show_url}}")'>{%trans "Show"%}</a>{%endif%}</td> +      </tr>{% endfor %} +    </table> +    </div> +    <h4>{% trans "Recent changes" %}</h4> +    <div class='table'> +    <table> +      <tr><th>{{lbl}}</th><th>{% trans "Modified" %}</th><th></th></tr> +      {% for item in dashboard.recents %}<tr> +        <td class='ref'>{{item}}</td> +        <td>{{item.history_date}}</td> +        <td>{% if item.get_show_url %}<a href="#" onclick='load_window("{{item.get_show_url}}")'>{%trans "Show"%}</a>{%endif%}</td> +      </tr>{% endfor %} +    </table> +    </div> +  </div> +{% endfor%} +  <div> +    <h3>{% trans "Users" %}</h3> +    <div class='table'> +    <table> +      <tr><th>{% trans "User type" %}</th><th>{% trans "Number" %}</th></tr> +    {% for user_type in ishtar_users.types %} +      <tr> +        <td class='string'>{{user_type.person__person_type__label}}</td> +        <td>{{user_type.number}}</td> +      </tr> +    {% endfor%} +    </table> +    </div> +</div> +{% endblock %} | 
