Skip to content

Commit

Permalink
Improve input/display for publications/articles
Browse files Browse the repository at this point in the history
For #84, though there is probably still more to do
  • Loading branch information
dellsystem committed Sep 11, 2018
1 parent bb0d4fd commit 529d026
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 14 deletions.
11 changes: 10 additions & 1 deletion django/bookmarker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ def add_section(request, slug):
if section_form.is_valid() and author_form.is_valid():
section = section_form.save(author_form)
messages.success(request, u'Added section: {}'.format(section.title))
# If it's a publication, go straight to that section's page.
if not book.details:
return redirect(section)
else:
new_form = False
messages.error(request, 'Failed to add section')
Expand Down Expand Up @@ -211,7 +214,7 @@ def add_section(request, slug):

# If the book is an edited collection, set the author mode to custom.
author_initial = {}
if book.details and book.details.is_edited:
if book.details and book.details.is_edited or not book.details:
author_initial['mode'] = 'custom'
author_form = ArtefactAuthorForm(prefix='author', initial=author_initial)

Expand Down Expand Up @@ -535,6 +538,12 @@ def add_note(request, slug):
section_id = request.GET.get('section')

book = Book.objects.get(slug=slug)
# If the "book" is actually a publication, and there is no section passed
# as a GET param, just use the most recently-added article/section.
if not section_id and book.is_publication():
latest_article = book.sections.latest('pk')
if latest_article:
section_id = latest_article.pk

if not book.completed_sections and book.details:
messages.error(request, 'Sections need to be completed first')
Expand Down
11 changes: 10 additions & 1 deletion django/books/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

class SectionChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
if obj.is_article():
return u'{title} - {authors}'.format(
title=obj.title,
authors=', '.join(author.name for author in obj.authors.all())
)

return u'{title} ({page})'.format(
title=obj.title,
page=obj.page_number,
Expand Down Expand Up @@ -113,7 +119,7 @@ def save(self, author_form, book=None):
note.save()
self.save_m2m()

if author_form.cleaned_data['mode'] == 'default' and note.book.details:
if author_form.cleaned_data['mode'] == 'default':
note.set_default_authors()
elif author_form.cleaned_data['mode'] == 'custom':
note.authors.add(*author_form.cleaned_data['authors'])
Expand All @@ -139,6 +145,9 @@ def __init__(self, book, *args, **kwargs):
super(SectionForm, self).__init__(*args, **kwargs)
if book.details is None:
self.fields.pop('page_number')
self.fields.pop('number')
else:
self.fields.pop('date')

def save(self, author_form):
"""Convert the string 'page' input into an integer (and set in_preface
Expand Down
9 changes: 8 additions & 1 deletion django/books/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class Book(models.Model):
def __unicode__(self):
return self.title

def is_publication(self):
return self.details is None

def get_citation_data(self):
details = self.details
if details is None:
Expand Down Expand Up @@ -244,6 +247,7 @@ class Section(PageArtefact):
related_to = models.ForeignKey('self', blank=True, null=True)
slug = models.SlugField(blank=True) # only for link-worthy sections
skipped = models.BooleanField(default=False, help_text='Not yet read')
date = models.DateField(blank=True, null=True) # only publications

class Meta:
ordering = ['-in_preface', 'page_number']
Expand All @@ -254,6 +258,9 @@ def __unicode__(self):
book=self.book.title
)

def is_article(self):
return self.book.is_publication()

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

Expand All @@ -277,7 +284,7 @@ def has_default_authors(self):
set(a.pk for a in details.default_authors.all())
)
else:
return True
return False

def get_citation(self):
"""Gandy, O. H. (2009). Rational discrimination. In _Coming to terms
Expand Down
2 changes: 1 addition & 1 deletion django/templates/add_note.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% include 'book_header.html' with book=book only %}
</div>
<div class="three wide center aligned column">
{% if not book.is_processed %}
{% if not book.is_processed and not book.is_publication %}
<form method="post" action="{% url 'mark_complete' book.id %}">
{% csrf_token %}
<button class="ui fluid black icon button"
Expand Down
6 changes: 3 additions & 3 deletions django/templates/note_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
</div>
<div class="computer only row">
{% if show_page %}
{% if not hide_page %}
<div class="one wide column">
<div class="ui big circular label">
{{ x.get_page_display }}
Expand All @@ -14,11 +14,11 @@
{% else %}
<div class="sixteen wide column">
{% endif %}
{% include 'note_body.html' with note=x highlight=highlight hide_section=hide_section hide_page=True only %}
{% include 'note_body.html' with note=x highlight=highlight hide_section=hide_section hide_page=hide_page only %}
</div>
</div>
<div class="mobile tablet only row">
<div class="sixteen wide column">
{% include 'note_body.html' with note=x highlight=highlight hide_section=hide_section %}
{% include 'note_body.html' with note=x highlight=highlight hide_section=hide_section hide_page=hide_page %}
</div>
</div>
12 changes: 12 additions & 0 deletions django/templates/section_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@
</div>
{% endwith %}
</div>
{% else %}
<div class="{% if section_form.number %}two{% else %}three{% endif %} wide collapsed column">
{% with error=section_form.date.errors %}
<div class="{% if error %}error{% endif %} field"
{% if error %}title="{{ error|join:"/" }}"{% endif %}>
<label>Date</label>
{{ section_form.date }}
</div>
{% endwith %}
</div>
{% endif %}
{% if section_form.number %}
<div class="one wide collapsed column">
<div class="field">
<label>Number</label>
{{ section_form.number }}
</div>
</div>
{% endif %}
<div class="six wide column">
<div class="field">
<label>Subtitle</label>
Expand Down
2 changes: 2 additions & 0 deletions django/templates/section_link.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<strong title="{{ section.subtitle }}{% if section.authors.count %} by {{ section.authors.all|join:", " }}{% endif %}">
{{ section.title|markdownify_title }}
</strong>
{% if not section.is_article %}
({{ section.get_page_display }})
{% endif %}
</a>
7 changes: 7 additions & 0 deletions django/templates/section_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
{% endifchanged %}
{% endif %}
<div class="computer only row">
{% if section.is_article %}
<div class="twelve wide column">
{% else %}
<div class="one wide column">
<div class="ui large circular label {% if section.skipped %}black{% endif %}"
{% if section.skipped %}title="Not read yet"{% endif %}>
{{ section.get_page_display }}
</div>
</div>
<div class="eleven wide column">
{% endif %}
<h4 class="ui {% if related %}disabled{% endif %} header">
{% if section.number %}{{ section.number }}.{% endif %}
{% if related %}
Expand All @@ -36,6 +40,9 @@ <h4 class="ui {% if related %}disabled{% endif %} header">
<div class="ui heart rating display-rating" data-rating="{{ section.rating }}">
</div>
{% endif %}
{% if section.date %}
{{ section.date }}
{% endif %}
{% if section.source_url %}
<a href="{{ section.source_url }}">
<i class="external icon"></i>
Expand Down
4 changes: 2 additions & 2 deletions django/templates/term_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
{% endifchanged %}
<div class="computer only row">
{% if show_page %}
{% if not hide_page %}
<div class="center aligned one wide column">
<div class="ui big circular label">
{{ x.get_page_display }}
Expand All @@ -20,7 +20,7 @@
{% else %}
<div class="sixteen wide column">
{% endif %}
{% include 'term_occurrence_display.html' with o=x hide_section=hide_section hide_page=True only %}
{% include 'term_occurrence_display.html' with o=x hide_section=hide_section hide_page=hide_page only %}
</div>
</div>
<div class="mobile tablet only row">
Expand Down
15 changes: 13 additions & 2 deletions django/templates/view_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
{% load markdown_filter %}

{% block breadcrumbs %}
<div class="active section">View book</div>
<div class="active section">View
{% if book.is_publication %}
publication
{% else %}
book
{% endif %}
</div>
{% endblock %}

{% block content %}
Expand Down Expand Up @@ -35,7 +41,12 @@ <h2 class="ui header">
{% if not book.completed_sections %}
<div class="ui fluid buttons">
<a class="ui blue icon button" href="{% url 'add_section' book.slug %}">
<i class="plus icon"></i> Add section
<i class="plus icon"></i> Add
{% if book.is_publication %}
article
{% else %}
chapter
{% endif %}
</a>
{% if book.details %}
<button class="ui green icon button"
Expand Down
2 changes: 1 addition & 1 deletion django/templates/view_note.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
<div class="ui divider"></div>

{% include 'note_header.html' with note=note highlight=query only %}
{% include 'note_body.html' with note=note highlight=query only %}
{% include 'note_body.html' with note=note hide_page=note.section.is_article highlight=query only %}
{% endblock %}
8 changes: 7 additions & 1 deletion django/templates/view_notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@


{% block breadcrumbs %}
<a class="section" href="{{ book.get_absolute_url }}">View book</a>
<a class="section" href="{{ book.get_absolute_url }}">View
{% if book.is_publication %}
publication
{% else %}
book
{% endif %}
</a>
<i class="right angle icon divider"></i>
<div class="active section">View notes</div>
{% endblock %}
Expand Down
7 changes: 6 additions & 1 deletion django/templates/view_section.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ <h3 class="ui header">
{% if not section.has_default_authors %}
{% include 'author_list.html' with authors=section.authors %}
{% endif %}
{% if section.date %}
/ {{ section.date }}
{% endif %}
{% else %}
(missing author)
{% endif %}
Expand Down Expand Up @@ -124,8 +127,10 @@ <h3 class="ui header">

<div class="ui divider"></div>
<div class="ui grid">
{% with is_article=section.is_article %}
{% for artefact in section.get_artefacts %}
{% include artefact.display_template with x=artefact show_page=True hide_section=True %}
{% include artefact.display_template with x=artefact hide_page=is_article hide_section=True %}
{% endfor %}
{% endwith %}
</div>
{% endblock %}

0 comments on commit 529d026

Please sign in to comment.