Skip to content

Commit

Permalink
Adds custom template tag for project info
Browse files Browse the repository at this point in the history
The tag shows if project is private, archived, who created it and when.
  • Loading branch information
oliverroick committed Aug 25, 2015
1 parent 0fe6e5f commit acd7673
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
18 changes: 18 additions & 0 deletions geokey/projects/templatetags/project_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django import template
from django.template.loader import render_to_string


register = template.Library()


@register.simple_tag
def project_attributes(project):
return render_to_string(
'projects/project_attributes.html',
{
'creator': project.creator.display_name,
'created_at': project.created_at.strftime("%d %B %Y, %H:%M"),
'private_label': ('Private' if project.isprivate else 'Public'),
'inactive': project.status == 'inactive'
}
)
49 changes: 47 additions & 2 deletions geokey/projects/tests/test_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import datetime

from django.test import TestCase
from ..templatetags import count
from ..templatetags import count, project_attributes

from geokey.users.models import User
from geokey.projects.models import Project


class TemplateTagTest(TestCase):
class CountTest(TestCase):
def test_more_link_text(self):
self.assertEqual(
count.more_link_text(6, 'category', 'categories'),
Expand All @@ -23,3 +28,43 @@ def test_more_link_text(self):
count.more_link_text(6, 'category', 'categories', 4),
'Show 2 more categories'
)


class ProjectAttributesTest(TestCase):
def test_project_attributes(self):
user = User(display_name='Test Name')
project = Project(
isprivate=True,
creator=user,
created_at=datetime.datetime.now(),
status='active'
)
html = project_attributes.project_attributes(project)

self.assertIn(
('Created by %s on %s') % (
user.display_name,
project.created_at.strftime("%d %B %Y, %H:%M")
),
html
)
self.assertIn('<span class="label label-primary">Private</span>', html)
self.assertNotIn('Archived', html)

project = Project(
isprivate=False,
creator=user,
created_at=datetime.datetime.now(),
status='inactive'
)
html = project_attributes.project_attributes(project)

self.assertIn(
('Created by %s on %s') % (
user.display_name,
project.created_at.strftime("%d %B %Y, %H:%M")
),
html
)
self.assertIn('<span class="label label-primary">Public</span>', html)
self.assertIn('<span class="label label-warning">Archived</span>', html)
10 changes: 4 additions & 6 deletions geokey/templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends "base.html" %}

{% load project_attributes %}

{% block title %} | Dashboard{% endblock %}

{% block main %}
Expand All @@ -23,13 +25,9 @@ <h3 class="header">
{% endif %}

<li>
<h3>
<a href="{% url 'admin:project_overview' project.id %}">{{project.name}}</a>
{% if project.isprivate %}<span class="label label-info">Private</span>{% else %}<span class="label label-info">Public</span>{% endif %}
{% if project.status == status_types.inactive %}<span class="label label-default">Inactive</span>{% endif %}
</h3>
<h3><a href="{% url 'admin:project_overview' project.id %}">{{project.name}}</a></h3>
{% if project.description %}<p>{{project.description}}</p>{% endif %}
<p class="meta">Created by {{ project.creator.display_name }}</p>
{% project_attributes project %}
</li>

{% if forloop.last %}
Expand Down
5 changes: 5 additions & 0 deletions geokey/templates/projects/project_attributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>
<span class="label label-primary">{{ private_label }}</span>
{% if inactive %}<span class="label label-warning">Archived</span>{% endif %}
</p>
<p class="meta">Created by {{ creator }} on {{ created_at }}</p>
4 changes: 4 additions & 0 deletions geokey/templates/superusertools/projects_list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends "base.html" %}

{% load project_attributes %}

{% block title %} | Superuser tools{% endblock %}

{% block main %}
Expand Down Expand Up @@ -30,6 +32,8 @@ <h3 class="header">Manage all projects</h3>
<li>
<h4><a href="{% url 'admin:project_overview' project.id %}">{{ project.name }}</a></h4>
{% if project.description %}<p>{{ project.description }}</p>{% endif %}
{% project_attributes project %}

</li>

{% if forloop.last %}
Expand Down

0 comments on commit acd7673

Please sign in to comment.