summaryrefslogtreecommitdiff
path: root/ishtar/ishtar_base/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-07-25 09:42:39 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-07-25 09:42:39 +0200
commitf1cfa62fbd53230313fee6c4262f35ccfa881f3d (patch)
tree9c6ac9dbd23b678f820e6c85b85e410785fe5ec9 /ishtar/ishtar_base/models.py
parent48db6c74f82de04dd714accf4030f005ba791143 (diff)
downloadIshtar-f1cfa62fbd53230313fee6c4262f35ccfa881f3d.tar.bz2
Ishtar-f1cfa62fbd53230313fee6c4262f35ccfa881f3d.zip
Complete the general panel for dashboard (closes #520)
Diffstat (limited to 'ishtar/ishtar_base/models.py')
-rw-r--r--ishtar/ishtar_base/models.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py
index cbf362b83..89cb8e605 100644
--- a/ishtar/ishtar_base/models.py
+++ b/ishtar/ishtar_base/models.py
@@ -25,8 +25,9 @@ import datetime
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.validators import validate_slug
from django.utils.translation import ugettext_lazy as _, ugettext
-from django.db.utils import DatabaseError
from django.utils.safestring import SafeUnicode, mark_safe
+from django.core.urlresolvers import reverse, NoReverseMatch
+from django.db.utils import DatabaseError
from django.db.models import Q, Max, Count
from django.db.models.signals import m2m_changed
@@ -339,6 +340,13 @@ class BaseHistorizedItem(models.Model):
values[k] = getattr(self, k)
return values
+ def get_show_url(self):
+ try:
+ return reverse('show-'+self.__class__.__name__.lower(),
+ args=[self.pk, ''])
+ except NoReverseMatch:
+ return
+
class LightHistorizedItem(BaseHistorizedItem):
history_date = models.DateTimeField(default=datetime.datetime.now)
class Meta:
@@ -348,10 +356,38 @@ class LightHistorizedItem(BaseHistorizedItem):
super(LightHistorizedItem, self).save(*args, **kwargs)
return True
+class UserDashboard:
+ def __init__(self):
+ types = IshtarUser.objects.values('person__person_type',
+ 'person__person_type__label')
+ self.types = types.annotate(number=Count('pk')).order_by(
+ 'person__person_type')
+
class Dashboard:
def __init__(self, model):
self.model = model
self.total_number = model.get_total_number()
+ history_model = self.model.history.model
+ # last edited - created
+ self.recents, self.lasts = [], []
+ for last_lst, modif_type in ((self.lasts, '+'), (self.recents, '~')):
+ last_ids = history_model.objects.values('id').annotate(hd=\
+ Max('history_date'))
+ last_ids = last_ids.filter(history_type=modif_type)
+ if self.model == Item:
+ last_ids = last_ids.filter(downstream_treatment_id__isnull=True)
+ if modif_type == '+':
+ last_ids = last_ids.filter(upstream_treatment_id__isnull=True)
+ last_ids = last_ids.order_by('-hd').distinct().all()[:5]
+ for idx in last_ids:
+ try:
+ obj = self.model.objects.get(pk=idx['id'])
+ except:
+ # 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()
self.years.sort()