From 8fcdf5b63e3e54d566e6532a65fb1945d7c1492e Mon Sep 17 00:00:00 2001 From: Bruno Leupi Date: Sat, 2 Feb 2019 15:20:04 +0100 Subject: [PATCH] Add Project Identifier to Project. Closes #19 --- tracker/admin.py | 6 +++--- tracker/models/project.py | 4 +++- tracker/templates/tracker/project/details.html | 6 ++++++ tracker/templates/tracker/user/monthly_distribution.html | 3 +++ tracker/templates/tracker/user/weekly_time.html | 3 +++ tracker/views/project/project.py | 3 ++- tracker/views/user.py | 2 ++ 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tracker/admin.py b/tracker/admin.py index c08a78f..20deb33 100644 --- a/tracker/admin.py +++ b/tracker/admin.py @@ -26,11 +26,11 @@ class ProfileAdmin(admin.ModelAdmin): class ProjectAdmin(admin.ModelAdmin): fieldsets = [ - (None, {'fields': ['name', 'organization']}), + (None, {'fields': ['name', 'identifier', 'organization']}), ('User Management', {'fields': ['admins', 'editors'], 'classes': ['collapse']}) ] - list_display = ('name', 'organization') - search_fields = ['name'] + list_display = ('name', 'identifier', 'organization') + search_fields = ['name', 'identifier'] class SettingAdmin(admin.ModelAdmin): diff --git a/tracker/models/project.py b/tracker/models/project.py index 553b9cf..a683fad 100644 --- a/tracker/models/project.py +++ b/tracker/models/project.py @@ -12,8 +12,10 @@ class Project(models.Model): name = models.CharField(max_length=200, null=False, blank=False) + identifier = models.CharField(max_length=200, null=False, blank=True) - admins = models.ManyToManyField(get_user_model(), related_name='administrated_projects', verbose_name='Administrators') + admins = models.ManyToManyField(get_user_model(), related_name='administrated_projects', + verbose_name='Administrators') editors = models.ManyToManyField(get_user_model(), blank=True, related_name='editable_projects') organization = models.ForeignKey(Organization, on_delete=models.CASCADE) diff --git a/tracker/templates/tracker/project/details.html b/tracker/templates/tracker/project/details.html index b4bbabd..6bfa003 100644 --- a/tracker/templates/tracker/project/details.html +++ b/tracker/templates/tracker/project/details.html @@ -49,6 +49,12 @@ + {% if project.identifier %} +
+

{{ project.name }} ({{ project.identifier }})

+
+ {% endif %} + {% if members %}
Members
diff --git a/tracker/templates/tracker/user/monthly_distribution.html b/tracker/templates/tracker/user/monthly_distribution.html index 801bf72..4e8e27e 100644 --- a/tracker/templates/tracker/user/monthly_distribution.html +++ b/tracker/templates/tracker/user/monthly_distribution.html @@ -33,6 +33,7 @@ Project + {% if show_identifier %}Identifier{% endif %} Duration @@ -44,6 +45,7 @@ {{ row.project.name }} + {% if show_identifier %}{{ row.project.identifier }}{% endif %} {% if setting.duration_format == 1 %} {{ row.duration }} @@ -57,6 +59,7 @@ Total + {% if show_identifier %}{% endif %} {% if setting.duration_format == 1 %} {{ total }} diff --git a/tracker/templates/tracker/user/weekly_time.html b/tracker/templates/tracker/user/weekly_time.html index a371a93..de8fbc8 100644 --- a/tracker/templates/tracker/user/weekly_time.html +++ b/tracker/templates/tracker/user/weekly_time.html @@ -33,6 +33,7 @@ Project + {% if show_identifier %}Identifier{% endif %} {% for date in dates %} {{ date|date:"SHORT_DATE_FORMAT" }} {% endfor %} @@ -46,6 +47,7 @@ {{ row.project.name }} + {% if show_identifier %}{{ row.project.identifier }}{% endif %} {% for entry in row.duration %} {% if setting.duration_format == 1 %} @@ -61,6 +63,7 @@ Total + {% if show_identifier %}{% endif %} {% for entry in totals %} {% if setting.duration_format == 1 %} diff --git a/tracker/views/project/project.py b/tracker/views/project/project.py index a1e3763..709269e 100644 --- a/tracker/views/project/project.py +++ b/tracker/views/project/project.py @@ -23,12 +23,13 @@ def create(request, organization): try: project_name = request.POST['project_name'] + identifier = request.POST['identifier'] if not project_name.strip(): raise KeyError() except KeyError: return projects(request, organization=organization.name, error_message="You didn't enter a project name.") - project = Project(name=project_name, organization=organization) + project = Project(name=project_name, identifier=identifier, organization=organization) project.save() project.admins.add(request.user) project.save() diff --git a/tracker/views/user.py b/tracker/views/user.py index 3e00d60..07745a2 100644 --- a/tracker/views/user.py +++ b/tracker/views/user.py @@ -78,6 +78,7 @@ def fd(d, f='DATE_FORMAT'): context = { 'setting': setting, + 'show_identifier': any(p.identifier for p in projects), 'matrix': matrix, 'total': total, 'chart': json.dumps(chart), @@ -137,6 +138,7 @@ def fd(d, f='DATE_FORMAT'): context = { 'setting': setting, + 'show_identifier': any(p.identifier for p in projects), 'projects': projects, 'dates': dates, 'matrix': matrix,