summaryrefslogtreecommitdiff
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
commit45f2c89cc92bfbf6af73ac2f32791f3b20ae801e (patch)
tree9c6ac9dbd23b678f820e6c85b85e410785fe5ec9
parent4a4e49cabf7604a60ac67f92191d3ec7d502fda6 (diff)
downloadIshtar-45f2c89cc92bfbf6af73ac2f32791f3b20ae801e.tar.bz2
Ishtar-45f2c89cc92bfbf6af73ac2f32791f3b20ae801e.zip
Complete the general panel for dashboard (closes #520)
-rw-r--r--ishtar/ishtar_base/models.py38
-rw-r--r--ishtar/ishtar_base/views.py4
-rw-r--r--ishtar/templates/dashboard_main.html35
-rw-r--r--static/media/style.css6
4 files changed, 78 insertions, 5 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()
diff --git a/ishtar/ishtar_base/views.py b/ishtar/ishtar_base/views.py
index ff55169c5..6527dec3a 100644
--- a/ishtar/ishtar_base/views.py
+++ b/ishtar/ishtar_base/views.py
@@ -243,7 +243,6 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
table_cols = full and [field.name for field in model._meta.fields
if field.name not in PRIVATE_FIELDS] \
or model.TABLE_COLS
- print table_cols
for item in items:
data = [item.pk]
for k in table_cols:
@@ -658,7 +657,8 @@ def dashboard_main(request, dct, obj_id=None, *args, **kwargs):
(_(u"Operations"), models.Dashboard(models.Operation)),
(_(u"Context records"), models.Dashboard(models.ContextRecord)),
(_(u"Archaeological items"), models.Dashboard(models.Item)),
- ]}
+ ],
+ 'ishtar_users':models.UserDashboard()}
return render_to_response('dashboard_main.html', dct,
context_instance=RequestContext(request))
diff --git a/ishtar/templates/dashboard_main.html b/ishtar/templates/dashboard_main.html
index ae243f7c2..e710dbe16 100644
--- a/ishtar/templates/dashboard_main.html
+++ b/ishtar/templates/dashboard_main.html
@@ -41,7 +41,42 @@
<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 %}
diff --git a/static/media/style.css b/static/media/style.css
index a6cd7487e..676867ff8 100644
--- a/static/media/style.css
+++ b/static/media/style.css
@@ -384,13 +384,15 @@ table.confirm tr.spacer td:last-child{
border:1px solid #EEE;
}
-#window table td.string{
+#window table td.string, .dashboard table td.string{
text-align:left;
}
-#window table td.ref{
+#window table td.ref, .dashboard table td.ref{
text-align:left;
white-space:nowrap;
+ font-family:monospace;
+ font-size:9pt;
}
#window table td.no_items{