From 6fb4cdd3c7581f21d423078fbb56c9a35485e99c Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 24 Jun 2016 21:35:00 +0100 Subject: [PATCH] Show most active projects on the homepage. #502 --- valuenetwork/templates/_projects_panel.html | 11 +++++++ .../theme_bootstrap/banner_base.html | 29 ++++++++-------- valuenetwork/valueaccounting/models.py | 33 ++++++++++++++++--- valuenetwork/valueaccounting/views.py | 9 ++--- 4 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 valuenetwork/templates/_projects_panel.html diff --git a/valuenetwork/templates/_projects_panel.html b/valuenetwork/templates/_projects_panel.html new file mode 100644 index 000000000..6e801ef92 --- /dev/null +++ b/valuenetwork/templates/_projects_panel.html @@ -0,0 +1,11 @@ +{% load i18n %} + +Most active projects + + diff --git a/valuenetwork/templates/theme_bootstrap/banner_base.html b/valuenetwork/templates/theme_bootstrap/banner_base.html index bba860b53..6736742d4 100644 --- a/valuenetwork/templates/theme_bootstrap/banner_base.html +++ b/valuenetwork/templates/theme_bootstrap/banner_base.html @@ -6,16 +6,19 @@ {% block body_base %}
{% include "_messages.html" %} - +
{% block banner %} {% endblock %}
-
+
+ {% include "_projects_panel.html" %} +
+
{% block column-1 %} - + {% if layout %} {% if layout.use_work_panel %} {% include "_work_panel.html" %} @@ -25,12 +28,12 @@ {% else %}

Panel 1

{% endif %} - + {% endblock %}
-
+
{% block column-2 %} - + {% if layout %} {% if layout.use_needs_panel %} {% include "_needs_panel.html" %} @@ -40,13 +43,13 @@ {% else %}

Panel 2

{% endif %} - - + + {% endblock %}
-
+
{% block column-3 %} - + {% if layout %} {% if layout.use_creations_panel %} {% include "_creations_panel.html" %} @@ -56,11 +59,11 @@ {% else %}

Panel 3

{% endif %} - - + + {% endblock %}
- +
{% endblock %} diff --git a/valuenetwork/valueaccounting/models.py b/valuenetwork/valueaccounting/models.py index 4e074ce63..d0b24c72e 100644 --- a/valuenetwork/valueaccounting/models.py +++ b/valuenetwork/valueaccounting/models.py @@ -429,17 +429,31 @@ class EconomicAgent(models.Model): related_name='agents_changed', blank=True, null=True, editable=False) changed_date = models.DateField(auto_now=True, blank=True, null=True, editable=False) objects = AgentManager() - + class Meta: ordering = ('nick',) - + + @classmethod + def __project_ids_on(cls, work_events): + project_ids = [] + for work_event in work_events: + if work_event.context_agent: + project_ids.append(work_event.context_agent.id) + return project_ids + + @classmethod + def active_projects(cls, days_ago=180): + work_events = EconomicEvent.work_events_since(days_ago=days_ago) + active_project_ids = cls.__project_ids_on(work_events) + return EconomicAgent.objects.context_agents().filter(id__in=active_project_ids).order_by("name") + def __unicode__(self): return self.nick - + def save(self, *args, **kwargs): unique_slugify(self, self.nick) super(EconomicAgent, self).save(*args, **kwargs) - + def delete(self, *args, **kwargs): aus = self.users.all() if aus: @@ -9895,7 +9909,16 @@ def __unicode__(self): quantity_string, resource_string, ]) - + + @classmethod + def work_events_since(cls, days_ago=180): + end = datetime.date.today() + start = end - datetime.timedelta(days=days_ago) + + return cls.objects.filter( + event_type__relationship="work", + event_date__range=(start, end)) + def undistributed_description(self): if self.unit_of_quantity: quantity_string = " ".join([str(self.undistributed_amount()), self.unit_of_quantity.abbrev]) diff --git a/valuenetwork/valueaccounting/views.py b/valuenetwork/valueaccounting/views.py index a446bdc8d..d9c0f7482 100644 --- a/valuenetwork/valueaccounting/views.py +++ b/valuenetwork/valueaccounting/views.py @@ -82,6 +82,8 @@ def home(request): rts.append(vc.resource_type) value_creations.append(vc) template_params["value_creations"] = value_creations + + template_params["active_projects"] = EconomicAgent.active_projects() return render_to_response("homepage.html", template_params, context_instance=RequestContext(request)) @@ -3887,12 +3889,7 @@ def this_week(request): agent = get_agent(request) end = datetime.date.today() start = end - datetime.timedelta(days=7) - #start = end - datetime.timedelta(days=40) - #import pdb; pdb.set_trace() - - work_events = EconomicEvent.objects.filter( - event_type__relationship="work", - event_date__range=(start, end)) + work_events = EconomicEvent.work_events_since(days_ago=7) participants = [e.from_agent for e in work_events if e.from_agent] total_participants = len(list(set(participants))) total_hours = sum(event.quantity for event in work_events)