Skip to content

Commit

Permalink
Metadata on templates, misc bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
c-e-p committed Aug 2, 2023
1 parent f3eaa41 commit 6717993
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 43 deletions.
2 changes: 1 addition & 1 deletion ourchive_app/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def update(self, chapter, validated_data):
if 'text' in validated_data:
validated_data['word_count'] = 0 if not validated_data['text'] else len(
validated_data['text'].split())
validated_data['text'] = nh3.clean(validated_data['text']) if validated_data['text'] is not None else ''
validated_data['text'] = nh3.clean(validated_data['text']) if 'text' in validated_data and validated_data['text'] is not None else ''
if 'attributes' in validated_data:
attributes = validated_data.pop('attributes')
chapter = AttributeValueSerializer.process_attributes(chapter, validated_data, attributes)
Expand Down

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions ourchive_app/frontend/templates/bookmark_collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ <h1 id="bkcol-header-h1" class="uk-heading">{{bkcol.title}}</h1>
<span id="bkcol-draft-span" class="uk-label uk-label-warning"><strong id="bkcol-draft-text">DRAFT</strong></span>
</div>
{% endif %}
<p class="uk-article-meta">{{ bkcol.short_description }}</p>
<p id="bkcol-{{bkcol.id}}-tile-attributes-p">{% include "object_attributes.html" with object='bkcol' object_id=bkcol.id attributes=bkcol.attributes %}</p>
</div>
<div class="uk-text-right uk-width-1-3" id="bkcol-user-controls-parent">
{% if bkcol.user == request.user.username %}
{% if bkcol.draft %}
<a id="bookmark-collection-publish-link" href="/bookmark-collections/{{ bkcol.id }}/publish"><span uk-icon="icon: check" title="Publish"></span> </a>
{% endif %}
<a id="bkcol-edit-link" href="/bookmark-collections/{{ bkcol.id }}/edit"><span uk-icon="icon: file-edit"></span> </a>
<a id="bookmark-collection-delete-link" uk-toggle="target: #bookmark-collection-{{bkcol.id}}-modal-delete"><span uk-icon="icon: trash"></span> </a>
{% include "delete_modal.html" with object='bookmark-collection' object_friendly='bookmark collection' object_id=bkcol.id %}
{% endif %}
</div>
<div id="bkcol-content" class="uk-width-1-1">
<p class="uk-article-meta uk-width-1-1">{{ bkcol.short_description }}</p>
<p class="uk-width-1-1" id="bkcol-{{bkcol.id}}-tile-attributes-p">{% include "object_attributes.html" with object='bkcol' object_id=bkcol.id attributes=bkcol.attributes %}</p>
{% include "tag_partial.html" with obj_name='bkcol' tags=bkcol.tags.items %}
<div class="uk-align-right">{% include 'bookmark_collection_metadata.html' with bookmark_collection=bkcol %}</div>
</div>
<div class="uk-text-right uk-width-1-3" id="bkcol-user-controls-parent">
{% if bkcol.user == request.user.username %}
{% if bkcol.draft %}
<a id="bookmark-collection-publish-link" href="/bookmark-collections/{{ bkcol.id }}/publish"><span uk-icon="icon: check" title="Publish"></span> </a>
{% endif %}
<a id="bkcol-edit-link" href="/bookmark-collections/{{ bkcol.id }}/edit"><span uk-icon="icon: file-edit"></span> </a>
<a id="bookmark-collection-delete-link" uk-toggle="target: #bookmark-collection-{{bkcol.id}}-modal-delete"><span uk-icon="icon: trash"></span> </a>
{% include "delete_modal.html" with object='bookmark-collection' object_friendly='bookmark collection' object_id=bkcol.id %}
{% endif %}
</div>
<div class="uk-margin-remove-bottom uk-width-1-1"><hr id="bkcol-title-hr"/></div>
<div id="bkcol-description-parent" class="uk-width-1-1">
<span class="uk-text-medium" id="bkcol-description-text">{{bkcol.description|safe}}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load i18n %}
<div class="uk-align-right"><p id="bk-metadata-p" class="uk-article-meta"><span id="bkcol-metadata-complete" class="uk-inline uk-text-bold">{% if bookmark_collection.is_complete %}{% translate 'Complete' %}{% else %}{% translate 'Incomplete' %}{% endif %}</span> | {% if settings.AllowComments %}<span id="bk-metadata-comment-count" class="uk-inline uk-text-bold">{% blocktranslate with cc=bookmark_collection.comment_count %}{{ cc }} Comments{% endblocktranslate %}{% endif %}</span></p></div>
16 changes: 9 additions & 7 deletions ourchive_app/frontend/templates/bookmark_collection_tile.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load i18n %}
<div id="bkcol-tile-parent" class="uk-margin">
<div id="bkcol-tile-card" class="uk-card uk-card-default">
<div id="bkcol-tile-header-parent" class="uk-card-header">
Expand All @@ -6,6 +7,13 @@
<a id="bkcol-tile-title-link" href="/bookmark-collections/{{bookmark_collection.id}}" class="uk-inline"><h3 id="bkcol-tile-title" class="uk-card-title uk-margin-remove-bottom">{{bookmark_collection.title}}</h3></a>
<p id="bkcol-tile-creator" class="uk-text-meta uk-margin-remove-top">{{ bookmark_collection.user }}</p>
</div>
{% if bookmark_collection.user == request.user.username %}
<div id="bkcol-tile-actions-parent" class="uk-align-right">
<a id="bkcol-tile-edit-link" href="/bookmark-collections/{{bookmark_collection.id}}/edit"><span id="bkcol-tile-edit-span" uk-icon="icon: file-edit" title="Edit"></span> </a>
<a id="bkcol-tile-delete-link" uk-toggle="target: #bookmark-collection-{{bookmark_collection.id}}-modal-delete"><span uk-icon="icon: trash" id="bkcol-tile-delete-span" title="Delete"></span> </a>
<p>{% include "delete_modal.html" with object='bookmark-collection' object_friendly='bookmark collection' object_id=bookmark_collection.id %}</p>
</div>
{% endif %}
</div>
</div>
<div id="bkcol-tile-tags" class="uk-card-body">
Expand All @@ -17,13 +25,7 @@
</div>
<div class="uk-card-footer" id="bkcol-tile-footer-parent">
<a id="bkcol-tile-readmore-link" href="/bookmark-collections/{{bookmark_collection.id}}" class="uk-button uk-button-text">Read more</a>
{% if bookmark_collection.user == request.user.username %}
<div id="bkcol-tile-actions-parent" class="uk-align-right">
<a id="bkcol-tile-edit-link" href="/bookmark-collections/{{bookmark_collection.id}}/edit"><span id="bkcol-tile-edit-span" uk-icon="icon: file-edit" title="Edit"></span> </a>
<a id="bkcol-tile-delete-link" uk-toggle="target: #bookmark-collection-{{bookmark_collection.id}}-modal-delete"><span uk-icon="icon: trash" id="bkcol-tile-delete-span" title="Delete"></span> </a>
<p>{% include "delete_modal.html" with object='bookmark-collection' object_friendly='bookmark collection' object_id=bookmark_collection.id %}</p>
</div>
{% endif %}
{% include 'bookmark_collection_metadata.html' %}
</div>
</div>
</div>
16 changes: 9 additions & 7 deletions ourchive_app/frontend/templates/bookmark_tile.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load i18n %}
<div id="bk-tile-parent" class="uk-margin">
<div id="bk-tile-card" class="uk-card uk-card-default">
<div id="bk-tile-header-parent" class="uk-card-header">
Expand All @@ -8,6 +9,13 @@
{% else %}
<a id="bk-tile-work-link" href="/bookmarks/{{bookmark.id}}?draft={{bookmark.draft}}" class="uk-inline"><h3 id="bk-tile-work-title" class="uk-card-title uk-margin-remove-bottom">Bookmark - {{bookmark.work.title}}</h3></a>
{% endif %}
{% if bookmark.user == request.user.username %}
<div id="bk-tile-actions-parent" class="uk-align-right">
<a id="bk-tile-edit-link" href="/bookmarks/{{ bookmark.id }}/edit"><span id="bk-tile-edit-span" uk-icon="icon: file-edit" title="Edit"></span> </a>
<a id="bk-tile-delete-link" uk-toggle="target: #bookmark-{{bookmark.id}}-modal-delete"><span uk-icon="icon: trash" id="bk-tile-delete-span" title="Delete"></span> </a>
{% include "delete_modal.html" with object='bookmark' object_id=bookmark.id %}
</div>
{% endif %}
<span id="bk-tile-rating-span" class="uk-inline uk-align-right">{% for stars in rating_range %}
{% if stars <= bookmark.rating %}
<span id="bk-tile-rating-star-filled" uk-icon="icon: star; ratio:1.1" id="rating_{{stars}}" class="rating-star uk-text-middle"></span>
Expand All @@ -28,13 +36,7 @@
</div>
<div class="uk-card-footer" id="bk-tile-footer-parent">
<a id="bk-tile-readmore-link" href="/bookmarks/{{bookmark.id}}" class="uk-button uk-button-text">Read more</a>
{% if bookmark.user == request.user.username %}
<div id="bk-tile-actions-parent" class="uk-align-right">
<a id="bk-tile-edit-link" href="/bookmarks/{{ bookmark.id }}/edit"><span id="bk-tile-edit-span" uk-icon="icon: file-edit" title="Edit"></span> </a>
<a id="bk-tile-delete-link" uk-toggle="target: #bookmark-{{bookmark.id}}-modal-delete"><span uk-icon="icon: trash" id="bk-tile-delete-span" title="Delete"></span> </a>
{% include "delete_modal.html" with object='bookmark' object_id=bookmark.id %}
</div>
{% endif %}
<div class="uk-align-right"><p id="bk-metadata-p" class="uk-article-meta">{% if settings.AllowComments %}<span id="bk-metadata-comment-count" class="uk-inline uk-text-bold">{% blocktranslate with cc=bookmark.comment_count %}{{ cc }} Comments{% endblocktranslate %}{% endif %}</span></p></div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion ourchive_app/frontend/templates/work.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h1 id="work-title-h1" class="uk-article-title" style="display: inline;"><a clas
<div id="work-summary-div"><span id="work-summary-span" class="uk-text-large">Summary</span></div>
<div id="work-summary-text-div"><span id="work-summary-text-span" class="uk-text-medium">{% autoescape off %}{{ work.summary|default_if_none:'' }}{% endautoescape %}</span></div>
<div class="uk-text-right" id="work-metadata-parent">
<p id="work-metadata-p" class="uk-article-meta"><span id="work-metadata-fingerguns" class="uk-inline uk-text-bold">{{ work.fingerguns }} Fingerguns</span> | <span class="uk-inline uk-text-bold" id="work-metadata-word-count">{{ work.word_count }} Words</span> {% if settings.AllowComments %}| <span id="work-metadata-comment-count" class="uk-inline uk-text-bold">{{ work.comment_count }} Comments{% endif %}</p>
{% include 'work_metadata.html' %}
</div>
{% if work.notes %}
<div id="summary-notes-divider-div" class="uk-margin-top"><hr id="summary-notes-divider-hr"/></div>
Expand Down
2 changes: 2 additions & 0 deletions ourchive_app/frontend/templates/work_metadata.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load i18n %}
<p id="work-metadata-p" class="uk-article-meta"><span id="work-metadata-complete" class="uk-inline uk-text-bold">{% if work.is_complete %}{% translate 'Complete' %}{% else %}{% translate 'Incomplete' %}{% endif %}</span> | <span id="work-metadata-updated" class="uk-inline uk-text-bold">{% translate 'Last Updated' %}: {{work.updated_on|date:'d M Y'}}</span> | <span id="work-metadata-fingerguns" class="uk-inline uk-text-bold">{% blocktranslate with fg=work.fingerguns %}{{ fg }} Fingerguns{% endblocktranslate %}</span> | <span class="uk-inline uk-text-bold" id="work-metadata-word-count">{% blocktranslate with wc=work.word_count %}{{ wc }} Words{% endblocktranslate %}</span> {% if settings.AllowComments %}| <span id="work-metadata-comment-count" class="uk-inline uk-text-bold">{% blocktranslate with cc=work.comment_count %}{{ cc }} Comments{% endblocktranslate %}{% endif %}</span></p>
23 changes: 10 additions & 13 deletions ourchive_app/frontend/templates/work_tile.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
{% endif %}
<div class="uk-width-expand" id="work-{{work.id}}-tile-title-parent">
{% if work.draft == True %}
<h3 id="work-{{work.id}}-tile-draft-title" class="uk-card-title uk-margin-remove-bottom"><a id="work-{{work.id}}-tile-draft-title-link" href="/works/{{work.id}}?draft=true">{{work.title}}</a></h3>
<h3 id="work-{{work.id}}-tile-draft-title" class="uk-card-title uk-margin-remove-bottom uk-inline"><a id="work-{{work.id}}-tile-draft-title-link" href="/works/{{work.id}}?draft=true">{{work.title}}</a></h3>
<span class="uk-label uk-inline uk-label-warning uk-margin-left" id="work-{{work.id}}-tile-draft-button-span"><strong>DRAFT</strong></span>
{% else %}
<h3 id="work-{{work.id}}-tile-title" class="uk-card-title uk-margin-remove-bottom"><a id="work-{{work.id}}-tile-title-link" href="/works/{{work.id}}">{{work.title}}</a></h3>
{% endif %}
<p id="work-{{work.id}}-tile-user-link" class="uk-text-meta uk-margin-remove-top">{{ work.user }}</p>
</div>
{% if work.draft %}
<div class="uk-width-auto" id="work-{{work.id}}-tile-draft-button-div">
<span class="uk-label uk-label-warning" id="work-{{work.id}}-tile-draft-button-span"><strong>DRAFT</strong></span>
</div>
{% endif %}
{% if work.user == request.user.username %}
<div class="uk-align-right" id="work-{{work.id}}-footer-user-controls">
<a id="work-{{work.id}}-footer-edit-link" href="/works/{{ work.id }}/edit"><span id="work-{{work.id}}-footer-edit-span" uk-icon="icon: file-edit" title="Edit"></span> </a>
<a id="work-{{work.id}}-footer-delete-link" uk-toggle="target: #work-{{work.id}}-modal-delete"><span id="work-{{work.id}}-footer-delete-span" uk-icon="icon: trash" title="Delete"></span> </a>
{% include "delete_modal.html" with object='work' object_id=work.id %}
</div>
{% endif %}
</div>
</div>
<div class="uk-card-body" id="work-{{work.id}}-tile-card-body">
Expand All @@ -29,13 +32,7 @@ <h3 id="work-{{work.id}}-tile-title" class="uk-card-title uk-margin-remove-botto
</div>
<div class="uk-card-footer" id="work-{{work.id}}-tile-footer-parent">
<a id="work-{{work.id}}-tile-footer-readmore" href="/works/{{work.id}}" class="uk-button uk-button-text">Read more</a>
{% if work.user == request.user.username %}
<div class="uk-align-right" id="work-{{work.id}}-footer-user-controls">
<a id="work-{{work.id}}-footer-edit-link" href="/works/{{ work.id }}/edit"><span id="work-{{work.id}}-footer-edit-span" uk-icon="icon: file-edit" title="Edit"></span> </a>
<a id="work-{{work.id}}-footer-delete-link" uk-toggle="target: #work-{{work.id}}-modal-delete"><span id="work-{{work.id}}-footer-delete-span" uk-icon="icon: trash" title="Delete"></span> </a>
{% include "delete_modal.html" with object='work' object_id=work.id %}
</div>
{% endif %}
<div class="uk-align-right">{% include 'work_metadata.html' %}</div>
</div>

</div>
Expand Down
3 changes: 3 additions & 0 deletions ourchive_app/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.utils.translation import gettext as _
from api import utils
from django.views.decorators.cache import never_cache
from dateutil.parser import *

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -739,6 +740,8 @@ def works(request):
works = response.response_data['results'] if 'results' in response.response_data else []
works = get_object_tags(works)
works = get_array_attributes_for_display(works, 'attributes')
for work in works:
work['updated_on'] = parse(work['updated_on']).date()
return render(request, 'works.html', {
'works': works,
'next': f"/works/{works_response['next_params']}" if works_response['next_params'] is not None else None,
Expand Down
3 changes: 2 additions & 1 deletion ourchive_app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ audioread
django-cors-headers
django-anymail[mailgun]
nh3
whitenoise
whitenoise
python-dateutil

0 comments on commit 6717993

Please sign in to comment.