Skip to content

Commit

Permalink
Add view for a single TermOccurrence
Browse files Browse the repository at this point in the history
Very basic. Closes #50.
  • Loading branch information
dellsystem committed Jul 16, 2017
1 parent f55d0f2 commit 84078e1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bookmarker/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
name='edit_note'),
url(r'^term/(?P<term_id>\d+)$', bookmarker.views.view_term,
name='view_term'),
url(r'^occurrence/(?P<occurrence_id>\d+)$',
bookmarker.views.view_occurrence,
name='view_occurrence'),
url(r'^author/(?P<author_id>\d+)$', bookmarker.views.view_author,
name='view_author'),
url(r'^tag/(?P<slug>[^/]+)$', bookmarker.views.view_tag,
Expand Down
14 changes: 14 additions & 0 deletions bookmarker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ def view_note(request, note_id):
return render(request, 'view_note.html', context)


def view_occurrence(request, occurrence_id):
occurrence = TermOccurrence.objects.get(pk=occurrence_id)
query = request.GET.get('q')

context = {
'occurrence': occurrence,
'term': occurrence.term,
'book': occurrence.book,
'query': query,
}

return render(request, 'view_occurrence.html', context)


def view_term(request, term_id):
term = Term.objects.get(pk=term_id)
query = request.GET.get('q')
Expand Down
4 changes: 3 additions & 1 deletion templates/term_occurrence_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
{% endif %}
<div class="ui label {{ o.category }}-category">{{ o.category }}</div>
<i class="ellipsis vertical icon"></i>
<span title="{{ o.added }}">{{ o.added|timesince }} ago</a>
<a href="{{ o.get_absolute_url }}" title="{{ o.added }}">
{{ o.added|timesince }} ago
</a>
<i class="ellipsis vertical icon"></i>
<a href="{% url 'admin:vocab_termoccurrence_change' o.pk %}">
<i class="edit icon"></i>
Expand Down
17 changes: 17 additions & 0 deletions templates/view_occurrence.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "base.html" %}

{% block breadcrumbs %}
<a class="section" href="{{ term.get_absolute_url }}">View term</a>
<i class="right angle icon divider"></i>
<div class="active section">View occurrence</div>
{% endblock %}

{% block content %}
{% include 'term_header.html' with term=term highlight=query %}

{% include 'book_header.html' with book=book %}
<br />

{% include 'term_occurrence_display.html' with o=occurrence highlight=query %}

{% endblock %}
3 changes: 3 additions & 0 deletions vocab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class Meta:
def display_template(self):
return 'term_display.html'

def get_absolute_url(self):
return reverse('view_occurrence', args=[str(self.id)])

def save(self, *args, **kwargs):
self.section = self.determine_section()
super(TermOccurrence, self).save(*args, **kwargs)
Expand Down

0 comments on commit 84078e1

Please sign in to comment.