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..93c25e20d 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): #todo not sure if 90 right + 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..48d6be0c3 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))