Skip to content

Commit

Permalink
Show most active projects on the homepage. valnet#502
Browse files Browse the repository at this point in the history
  • Loading branch information
cillian committed Jun 24, 2016
1 parent 7ab53e0 commit 6fb4cdd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
11 changes: 11 additions & 0 deletions valuenetwork/templates/_projects_panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load i18n %}

<legend>Most active projects</legend>

<ul>
{% for project in active_projects %}
<li>
<a href="{{ project.get_absolute_url }}">{{ project.name }}</a>
</li>
{% endfor %}
</ul>
29 changes: 16 additions & 13 deletions valuenetwork/templates/theme_bootstrap/banner_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
{% block body_base %}
<div class="container">
{% include "_messages.html" %}

<div class="hero-unit well">
{% block banner %}
{% endblock %}
</div>

<div class="row-fluid">
<div class="span4">
<div class="span3">
{% include "_projects_panel.html" %}
</div>
<div class="span3">
{% block column-1 %}

{% if layout %}
{% if layout.use_work_panel %}
{% include "_work_panel.html" %}
Expand All @@ -25,12 +28,12 @@
{% else %}
<p>Panel 1</p>
{% endif %}

{% endblock %}
</div>
<div class="span4">
<div class="span3">
{% block column-2 %}

{% if layout %}
{% if layout.use_needs_panel %}
{% include "_needs_panel.html" %}
Expand All @@ -40,13 +43,13 @@
{% else %}
<p>Panel 2</p>
{% endif %}


{% endblock %}
</div>
<div class="span4">
<div class="span3">
{% block column-3 %}

{% if layout %}
{% if layout.use_creations_panel %}
{% include "_creations_panel.html" %}
Expand All @@ -56,11 +59,11 @@
{% else %}
<p>Panel 3</p>
{% endif %}


{% endblock %}
</div>
</div>

</div>
{% endblock %}
33 changes: 28 additions & 5 deletions valuenetwork/valueaccounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down
9 changes: 3 additions & 6 deletions valuenetwork/valueaccounting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6fb4cdd

Please sign in to comment.