Skip to content

Commit

Permalink
Sort people by new
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgleason committed Feb 1, 2019
1 parent 98bf217 commit 4420c8e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
23 changes: 23 additions & 0 deletions project_tier/network/migrations/0004_auto_20190131_1813.py
@@ -0,0 +1,23 @@
# Generated by Django 2.1.3 on 2019-01-31 23:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('network', '0003_auto_20181011_0927'),
]

operations = [
migrations.AddField(
model_name='person',
name='joined_on',
field=models.DateField(blank=True, help_text='Date this member joined the TIER network. Not publicly visible - used to calculate NEW tags.', null=True),
),
migrations.AlterField(
model_name='person',
name='fellowship_year',
field=models.IntegerField(blank=True, choices=[(2010, '2010–2011'), (2011, '2011–2012'), (2012, '2012–2013'), (2013, '2013–2014'), (2014, '2014–2015'), (2015, '2015–2016'), (2016, '2016–2017'), (2017, '2017–2018'), (2018, '2018–2019'), (2019, '2019–2020')], null=True),
),
]
16 changes: 15 additions & 1 deletion project_tier/network/models.py
@@ -1,4 +1,6 @@
from django.utils import timezone
from django.db import models
from django.db.models import F
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.search import index
Expand Down Expand Up @@ -43,6 +45,10 @@ class Person(models.Model):
show_in_network = models.BooleanField(default=True, blank=False)
show_in_people = models.BooleanField(default=False, blank=False)

joined_on = models.DateField(blank=True, null=True,
help_text="Date this member joined the TIER network. Not publicly "
"visible - used to calculate NEW tags.")

CATEGORIES = (
('fellow', 'Fellows'),
('advisory_board', 'Advisory Board'),
Expand All @@ -68,6 +74,12 @@ class Person(models.Model):
null=True
)

def is_new(self):
""" The person became a member within the past 30 days. """
today = timezone.now().date()
joined = self.joined_on
return joined and (today - joined).days <= 30

panels = [
MultiFieldPanel(
[
Expand Down Expand Up @@ -103,6 +115,7 @@ class Person(models.Model):
FieldPanel('show_in_network'),
FieldPanel('show_in_people'),
FieldPanel('fellowship_year'),
FieldPanel('joined_on'),
],
heading="Display Settings"
),
Expand Down Expand Up @@ -210,7 +223,8 @@ def get_context(self, request):
@property
def people(self):
people = Person.objects.filter(show_in_network=True).order_by('last_name')
return people
# Put new people at the top. Convert is_new to a string that can be ordered.
return sorted(people, key = lambda p: ('A' if p.is_new() else 'Z', p.last_name))

class Meta:
verbose_name = 'Network List Page'
Expand Up @@ -22,7 +22,7 @@ <h2 class="section-title">{{group}}</h2>
{% else %}
<img class="placeholder img-thumbnail" />
{% endif %}
<h2>{{ person.first_name }} {{ person.last_name }}{% if person.academic_title %},<span class="academic-title"> {{ person.academic_title }}</span>{% endif %}, <span class="job-title">{{ person.main_job_title }}</span></h2>
<h2>{{ person.first_name }} {{ person.last_name }}{% if person.academic_title %},<span class="academic-title"> {{ person.academic_title }}</span>{% endif %}, <span class="job-title">{{ person.main_job_title }}</span>{% if person.is_new %} <span class="new"></span>{% endif %}</h2>
</div>
<div class="card-section">
{{ person.affiliation }}
Expand Down
12 changes: 12 additions & 0 deletions project_tier/static/css/_people.scss
Expand Up @@ -179,4 +179,16 @@ ul.accordion .accordion-content ul li.column::before {
.job-title {
font-weight: normal;
}
.new::before {
content: 'new';
text-transform: uppercase;
background: #1d7ac9;
color: white;
font-size: 12px;
padding: 0 3px;
display: inline-block;
transform: translateY(-3px);
margin-left: 6px;
border-radius: 2px;
}
}

0 comments on commit 4420c8e

Please sign in to comment.