Skip to content

Commit

Permalink
Merge pull request #507 from cillian/homepage-projects-panel
Browse files Browse the repository at this point in the history
Show most active projects on the homepage. #502
  • Loading branch information
bhaugen authored Jul 1, 2016
2 parents e816823 + 7a14393 commit 31e12cc
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 65 deletions.
17 changes: 11 additions & 6 deletions valuenetwork/templates/_creations_panel.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{% load i18n %}
{% load thumbnail %}

{% if layout.creations_panel_headline %}
{{ layout.creations_panel_headline|safe|urlize|linebreaks }}
{% else %}
<legend>Value being created</legend>
<legend>
{% if layout.creations_panel_headline %}
{{ layout.creations_panel_headline|safe|urlize }}
{% else %}
Value being created
{% endif %}
</legend>

{% if not layout.creations_panel_headline %}
<p style="font-style: italic;" >
Our designs are open source. We seek partners in evolving our products.
</p>
Expand All @@ -24,7 +29,7 @@
{% trans "use this?" %}
</a>
</div>

</li>
{% endfor %}
</ul>
</ul>
17 changes: 11 additions & 6 deletions valuenetwork/templates/_needs_panel.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{% load i18n %}
{% load thumbnail %}

{% if layout.needs_panel_headline %}
{{ layout.needs_panel_headline|safe|urlize|linebreaks }}
{% else %}
<legend>Resources we need</legend>
<legend>
{% if layout.needs_panel_headline %}
{{ layout.needs_panel_headline|safe|urlize }}
{% else %}
Resources we need
{% endif %}
</legend>

{% if not layout.needs_panel_headline %}
<p style="font-style: italic;" >
Your contributions will be eligible for income sharing.
</p>
Expand All @@ -14,7 +19,7 @@
{% for resource_type, qty in stuff_to_buy.items %}
<li>
<b>{{ resource_type.name }}:</b> {{ qty}} {{ resource_type.unit }}

<div style="display: inline;" >
<a href="" role="button" class="btn btn-info" title="This button does not work yet. It will soon.">
{% trans "get this for us?" %}
Expand All @@ -25,4 +30,4 @@
{% endif %}
</li>
{% endfor %}
</ul>
</ul>
13 changes: 13 additions & 0 deletions valuenetwork/templates/_projects_panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load i18n %}

{% if active_projects|length > 0 %}
<legend>Most active projects</legend>

<ul>
{% for project in active_projects %}
<li>
<a href="{{ project.get_absolute_url }}">{{ project.name }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
13 changes: 9 additions & 4 deletions valuenetwork/templates/_work_panel.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{% load i18n %}
{% load thumbnail %}

{% if layout.work_panel_headline %}
{{ layout.work_panel_headline|safe|urlize|linebreaks }}
{% else %}
<legend> Work to do </legend>
<legend>
{% if layout.work_panel_headline %}
{{ layout.work_panel_headline|safe|urlize }}
{% else %}
Work to do
{% endif %}
</legend>

{% if not layout.work_panel_headline %}
<p style="font-style: italic;" >
Your work will be eligible for income sharing.
</p>
Expand Down
69 changes: 33 additions & 36 deletions valuenetwork/templates/theme_bootstrap/banner_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,58 @@
{% 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">
{% block column-1 %}

{% if layout %}
{% if layout %}
<div class="row-fluid">
<div class="span{{layout.column_width}}">
{% include "_projects_panel.html" %}
</div>
{% if layout.use_work_or_html_panel %}
<div class="span{{layout.column_width}}">
{% block column-1 %}

{% if layout.use_work_panel %}
{% include "_work_panel.html" %}
{% else %}
{{ layout.panel_1|safe|urlize|linebreaks }}
{% endif %}
{% else %}
<p>Panel 1</p>
{% endif %}

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

{% if layout %}

{% endblock %}
</div>
{% endif %}
{% if layout.use_needs_or_html_panel %}
<div class="span{{layout.column_width}}">
{% block column-2 %}

{% if layout.use_needs_panel %}
{% include "_needs_panel.html" %}
{% else %}
{{ layout.panel_2|safe|urlize|linebreaks }}
{% endif %}
{% else %}
<p>Panel 2</p>
{% endif %}


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

{% if layout %}

{% endblock %}
</div>
{% endif %}
{% if layout.use_creations_or_html_panel %}
<div class="span{{layout.column_width}}">
{% block column-3 %}

{% if layout.use_creations_panel %}
{% include "_creations_panel.html" %}
{% else %}
{{ layout.panel_3|safe|urlize|linebreaks }}
{% endif %}
{% else %}
<p>Panel 3</p>
{% endif %}


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


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

</div>
{% endblock %}
54 changes: 47 additions & 7 deletions valuenetwork/valueaccounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,27 @@ class HomePageLayout(models.Model):
panel_3 = models.TextField(_('panel 3'), blank=True, null=True,
help_text=_("HTML text for Panel 3"))
footer = models.TextField(_('footer'), blank=True, null=True)


FULL_WIDTH = 12

class Meta:
verbose_name_plural = _('home page layout')


def column_width(self):
return self.FULL_WIDTH / self.__column_count()

def use_creations_or_html_panel(self):
return self.use_creations_panel or len(self.panel_3.strip()) > 0

def use_needs_or_html_panel(self):
return self.use_needs_panel or len(self.panel_2.strip()) > 0

def use_work_or_html_panel(self):
return self.use_work_panel or len(self.panel_1.strip()) > 0

def __column_count(self):
use_project_panel = True
return sum([use_project_panel, self.use_creations_or_html_panel(), self.use_needs_or_html_panel(), self.use_work_or_html_panel()])

#for help text
PAGE_CHOICES = (
Expand Down Expand Up @@ -429,17 +446,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 @@ -9909,7 +9940,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 31e12cc

Please sign in to comment.