Skip to content

Commit

Permalink
Add Project Identifier to Project. Closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
leupibr committed Feb 2, 2019
1 parent f4b29a7 commit 8fcdf5b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tracker/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion tracker/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tracker/templates/tracker/project/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ <h5 class="modal-title">Delete project {{ project.name }}?</h5>
</div>
</div>

{% if project.identifier %}
<div class="container-fluid mt-3">
<h4>{{ project.name }} ({{ project.identifier }})</h4>
</div>
{% endif %}

{% if members %}
<div class="container-fluid mt-3">
<h5>Members</h5>
Expand Down
3 changes: 3 additions & 0 deletions tracker/templates/tracker/user/monthly_distribution.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<thead>
<tr>
<th>Project</th>
{% if show_identifier %}<th>Identifier</th>{% endif %}
<th class="text-right">Duration</th>
</tr>
</thead>
Expand All @@ -44,6 +45,7 @@
{{ row.project.name }}
</a>
</td>
{% if show_identifier %}<td>{{ row.project.identifier }}</td>{% endif %}
<td class="text-right">
{% if setting.duration_format == 1 %}
{{ row.duration }}
Expand All @@ -57,6 +59,7 @@
<tfoot>
<tr>
<th>Total</th>
{% if show_identifier %}<th></th>{% endif %}
<th class="text-right">
{% if setting.duration_format == 1 %}
{{ total }}
Expand Down
3 changes: 3 additions & 0 deletions tracker/templates/tracker/user/weekly_time.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<thead>
<tr>
<th>Project</th>
{% if show_identifier %}<th>Identifier</th>{% endif %}
{% for date in dates %}
<th class="text-right">{{ date|date:"SHORT_DATE_FORMAT" }}</th>
{% endfor %}
Expand All @@ -46,6 +47,7 @@
{{ row.project.name }}
</a>
</td>
{% if show_identifier %}<td>{{ row.project.identifier }}</td>{% endif %}
{% for entry in row.duration %}
<td class="text-right">
{% if setting.duration_format == 1 %}
Expand All @@ -61,6 +63,7 @@
<tfoot>
<tr>
<th>Total</th>
{% if show_identifier %}<th></th>{% endif %}
{% for entry in totals %}
<th class="text-right">
{% if setting.duration_format == 1 %}
Expand Down
3 changes: 2 additions & 1 deletion tracker/views/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions tracker/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8fcdf5b

Please sign in to comment.