Skip to content

Commit

Permalink
show sourced per modal, add change history per story credit type as
Browse files Browse the repository at this point in the history
modal
  • Loading branch information
jochenGCD committed Nov 13, 2021
1 parent 420daec commit ea8c595
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 32 deletions.
18 changes: 6 additions & 12 deletions apps/gcd/models/creator.py
Expand Up @@ -128,7 +128,7 @@ class Meta:
default=Script.LATIN_PK)

def display_credit(self, credit, url=True, compare=False, search=False,
show_sources=False, full_path=''):
show_sources=False):
co_name = ''
as_name = ''
extra_name = ''
Expand Down Expand Up @@ -261,16 +261,11 @@ def display_credit(self, credit, url=True, compare=False, search=False,
if show_sources:
credit_text += ' (sourced: %s)' % esc(credit.sourced_by)
else:
if url and full_path:
credit_text += ' (<a href="%s' % full_path
if '?' in full_path:
credit_text += '&show_sources'
else:
credit_text += '?show_sources'
if hasattr(credit, 'story'):
credit_text += '#%d">sourced</a>)' % credit.story_id
else:
credit_text += '">sourced</a>)'
if url:
credit_text += ' <a hx-get="/credit/%d/source/"' % \
credit.id
credit_text += ' hx-target="body" hx-swap="beforeend"' +\
' style="color: #00e;">(sourced)</a>'
else:
credit_text += ' (sourced)'

Expand Down Expand Up @@ -420,7 +415,6 @@ def linked_issues_count(self):
story__credits__deleted=False)\
.distinct().count()


def has_death_info(self):
if str(self.death_date) != '':
return True
Expand Down
32 changes: 21 additions & 11 deletions apps/gcd/templatetags/credits.py
Expand Up @@ -290,7 +290,7 @@ def search_creator_credit(story, credit_type):
return mark_safe(credit_value)


def __credit_value(story, credit_type, url, show_sources=False, full_path=''):
def __credit_value(story, credit_type, url, show_sources=False):
# for results from elasticsearch
if '_object' in story.__dict__:
credits = story.object.active_credits.filter(
Expand All @@ -302,7 +302,7 @@ def __credit_value(story, credit_type, url, show_sources=False, full_path=''):
for credit in credits:
if credit.credit_type_id == CREDIT_TYPES[credit_type]:
displayed_credit = credit.creator.display_credit(
credit, url=url, show_sources=show_sources, full_path=full_path)
credit, url=url, show_sources=show_sources)
if credit_value:
credit_value += '; %s' % displayed_credit
else:
Expand All @@ -317,26 +317,36 @@ def __credit_value(story, credit_type, url, show_sources=False, full_path=''):


@register.simple_tag
def show_full_credits(story, credit_type, show_sources, full_path):
def show_full_credits(story, credit_type, show_sources):
return show_creator_credit(story, credit_type,
show_sources=show_sources, full_path=full_path)
show_sources=show_sources)


@register.filter
def show_creator_credit(story, credit_type, url=True,
show_sources=False, full_path=''):
show_sources=False):
credit_value = __credit_value(story, credit_type, url,
show_sources, full_path)
show_sources)
if credit_value and url:
return mark_safe(
'<dt class="credit_tag"><span class="credit_label">'
+ credit_type.capitalize() + '</span></dt>' +
'<dd class="credit_def"><span class="credit_value">'
+ credit_value + '</span></dd>')
val = '<dt class="credit_tag"><span class="credit_label">'
if type(story) == Story:
val += '<a hx-get="/story/%d/%s/history/" ' % (story.id,
credit_type) + \
'hx-target="body" hx-swap="beforeend" style="color: #00e;">'
val += credit_type.capitalize() + '</a></span></dt>' + \
'<dd class="credit_def"><span class="credit_value">' + \
credit_value + '</span></dd>'
return mark_safe(val)
else:
return credit_value


@register.filter
def show_creator_credit_bare(story, credit_type):
credit_value = __credit_value(story, credit_type, url=True)
return credit_value


@register.filter
def show_cover_letterer_credit(story):
if (story.letters == 'typeset' or story.letters == '?') and not\
Expand Down
7 changes: 7 additions & 0 deletions apps/gcd/urls.py
Expand Up @@ -287,6 +287,13 @@
url(r'^issue/(?P<issue_id>\d+)/image/$',
gcd_views.details.issue_images, name='issue_images'),

# Credits
url(r'^credit/(?P<credit_id>\d+)/source/$',
gcd_views.details.credit_source, name='credit_source'),
# Stories
url(r'^story/(?P<story_id>\d+)/(?P<credit_type>.+)/history/$',
gcd_views.details.credit_type_history, name='credit_type_history'),

# Feature
url(r'^feature/(?P<feature_id>\d+)/issues/$',
gcd_views.details.feature_issuelist_by_id, name='feature_issuelist_by_id'),
Expand Down
67 changes: 64 additions & 3 deletions apps/gcd/views/details.py
Expand Up @@ -14,7 +14,8 @@
import django.urls as urlresolvers
from django.shortcuts import get_object_or_404, \
render
from django.http import HttpResponseRedirect, Http404, JsonResponse
from django.http import HttpResponseRedirect, Http404, JsonResponse, \
HttpResponse
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.views.decorators.clickjacking import xframe_options_sameorigin
Expand All @@ -38,7 +39,7 @@
CreatorNonComicWork, CreatorSignature, \
Feature, FeatureLogo, FeatureRelation, \
Printer, IndiciaPrinter, School, Story, \
Character, Group, \
Character, Group, StoryCredit, \
CharacterRelation, GroupRelation, GroupMembership
from apps.gcd.models.creator import FeatureCreatorTable, SeriesCreatorTable,\
CharacterCreatorTable, GroupCreatorTable,\
Expand All @@ -50,7 +51,8 @@
IndiciaPublisherIssueTable,\
IssuePublisherTable, PublisherIssueTable
from apps.gcd.models.series import SeriesTable, CreatorSeriesTable
from apps.gcd.models.story import CORE_TYPES, AD_TYPES, StoryTable
from apps.gcd.models.story import CREDIT_TYPES, CORE_TYPES, AD_TYPES, \
StoryTable
from apps.gcd.views import paginate_response, ORDER_ALPHA, ORDER_CHRONO,\
ResponsePaginator
from apps.gcd.views.covers import get_image_tag, get_generic_image_tag, \
Expand Down Expand Up @@ -2856,6 +2858,65 @@ def show_issue(request, issue, preview=False):
})


def credit_source(request, credit_id):
"""
Show the source of a credit for use in a modal.
"""
credit = get_object_or_404(StoryCredit.objects.select_related(
'creator', 'credit_type', 'story__issue'), id=credit_id)

if credit.deleted or not credit.is_sourced:
return HttpResponse("")

issue_url = credit.story.issue.get_absolute_url()
issue_url += '?show_all&show_sources#%d' % credit.story.id

return render(request, 'gcd/bits/credit_source.html',
{'credit': credit, 'issue_url': issue_url})


def credit_type_history(request, story_id, credit_type):
from apps.oi.templatetags.compare import diff_list
from apps.oi.models import PreviewStory

if credit_type not in CREDIT_TYPES:
raise ValueError

story = get_object_or_404(Story, id=story_id)
storyrevisions = story.revisions.filter(changeset__state=states.APPROVED)\
.order_by('modified', 'id')\
.select_related('changeset__indexer')
old = getattr(storyrevisions[0], credit_type)
old_rev = storyrevisions[0]
changes = []
for storyrev in storyrevisions[1:]:
new = getattr(storyrev, credit_type)
changed = old.strip() != new.strip()
if not changed:
credits = storyrev.story_credit_revisions.filter(
credit_type__name=credit_type)
if credits:
for credit in credits:
credit.compare_changes()
if credit.is_changed:
changed = True
break
if changed:
changes.append((old_rev, storyrev))
old = new
old_rev = storyrev
change_data = []
for change in changes:
change_data.append((change[1].changeset, diff_list(change[0],
change[1],
credit_type)))

return render(request, 'gcd/bits/credit_type_history.html',
{'changes': change_data,
'first': PreviewStory.init(storyrevisions[0]),
'credit_type': credit_type})


@xframe_options_sameorigin
def daily_creators(request, offset=0):
today = datetime.today()
Expand Down
88 changes: 88 additions & 0 deletions static/css/gcd/default/modal.css
@@ -0,0 +1,88 @@
#modal {
/* Underlay covers entire screen. */
position: fixed;
top:0px;
bottom: 0px;
left:0px;
right:0px;
background-color:rgba(0,0,0,0.5);
z-index:1000;
font-size: 0.9em;

/* Flexbox centers the .modal-content vertically and horizontally */
display:flex;
flex-direction:column;
align-items:center;

/* Animate when opening */
animation-name: fadeIn;
animation-duration:150ms;
animation-timing-function: ease;
}

#modal > .modal-underlay {
/* underlay takes up the entire viewport. This is only
required if you want to click to dismiss the popup */
position: absolute;
z-index: -1;
top:0px;
bottom:0px;
left: 0px;
right: 0px;
}

#modal > .modal-content {
/* Position visible dialog near the top of the window */
margin-top:10vh;

/* Sizing for visible dialog */
width:80%;
max-width:800px;

/* Display properties for visible dialog*/
border:solid 1px #999;
border-radius:8px;
box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.3);
background-color:white;
padding:20px;

/* Animate when opening */
animation-name:zoomIn;
animation-duration:150ms;
animation-timing-function: ease;
}

#modal.closing {
/* Animate when closing */
animation-name: fadeOut;
animation-duration:150ms;
animation-timing-function: ease;
}

#modal.closing > .modal-content {
/* Aniate when closing */
animation-name: zoomOut;
animation-duration:150ms;
animation-timing-function: ease;
}

@keyframes fadeIn {
0% {opacity: 0;}
100% {opacity: 1;}
}

@keyframes fadeOut {
0% {opacity: 1;}
100% {opacity: 0;}
}

@keyframes zoomIn {
0% {transform: scale(0.9);}
100% {transform: scale(1);}
}

@keyframes zoomOut {
0% {transform: scale(1);}
100% {transform: scale(0.9);}
}

14 changes: 14 additions & 0 deletions templates/gcd/bits/credit_source.html
@@ -0,0 +1,14 @@
{% load static %}
<link rel="stylesheet" type="text/css"
href="{% static "css/gcd/default/modal.css" %}"/>
<script src="https://unpkg.com/hyperscript.org"></script>
<div id="modal" _="on closeModal add .closing then wait for animationend then remove me">
<div class="modal-underlay" _="on click trigger closeModal"></div>
<div class="modal-content">
<p>The source of the <b>{{ credit.credit_type }}</b> credit for <b>{{ credit.creator.name }}</b> is:
<br>
{{ credit.sourced_by }}
</p>
<button _="on click trigger closeModal">Close</button> <a style="float: right;" href="{{ issue_url }}">Show All Sources</a>
</div>
</div>
45 changes: 45 additions & 0 deletions templates/gcd/bits/credit_type_history.html
@@ -0,0 +1,45 @@
{% load compare %}
{% load display %}
{% load static %}
{% load credits %}

<script src="https://unpkg.com/hyperscript.org"></script>
<link rel="stylesheet" type="text/css"
href="{% static "css/gcd/default/listing.css" %}">
</link>
<link rel="stylesheet" type="text/css"
href="{% static "css/oi/default/edit.css" %}">
</link>
<link rel="stylesheet" type="text/css"
href="{% static "css/gcd/default/modal.css" %}"/>

<div id="modal" _="on closeModal add .closing then wait for animationend then remove me">
<div class="modal-underlay" _="on click trigger closeModal"></div>
<div class="modal-content">
<table class="sortable_listing">
<tr>
<th>Date Approved</th>
<th>Indexer</th>
<th>Previous</th>
<th>Change</th>
</tr>
{% with changeset=first.revision.changeset %}
<tr>
<td><a href="{% url "compare" changeset.id %}">{{ changeset.modified }}</a></td>
<td>{{ changeset.indexer.indexer|absolute_url }}</td>
<td>{{ first|show_creator_credit_bare:credit_type }}</td>
<td></td>
</tr>
{% endwith %}
{% for change in changes %}
<tr>
<td><a href="{% url "compare" change.0.id %}">{{ change.0.modified }}</a></td>
<td>{{ change.0.indexer.indexer|absolute_url }}</td>
<td>{{ change.1|show_diff:"orig" }}</td>
<td>{{ change.1|show_diff:"change" }}</td>
</tr>
{% endfor %}
</table>
<button _="on click trigger closeModal">Close</button>
</div>
</div>
3 changes: 3 additions & 0 deletions templates/gcd/details/issue.html
Expand Up @@ -18,6 +18,9 @@
<link rel="stylesheet" type="text/css"
href="{% static "css/gcd/default/single_story.css" %}"/>
{% endblock %}
{% block css_raw %}
<script src="https://unpkg.com/htmx.org@1.6.0" integrity="sha384-G4dtlRlMBrk5fEiRXDsLjriPo8Qk5ZeHVVxS8KhX6D7I9XXJlNqbdvRlp9/glk5D" crossorigin="anonymous"></script>
{% endblock %}

{% block view_body %}

Expand Down
12 changes: 6 additions & 6 deletions templates/gcd/details/single_story.html
Expand Up @@ -45,16 +45,16 @@ <h3 class="sequence_header feature">
{% if story.has_credits %}
<dl class="credits">
{% with full_path=request.get_full_path %}
{% show_full_credits story "script" show_sources full_path %}
{% show_full_credits story "pencils" show_sources full_path %}
{% show_full_credits story "inks" show_sources full_path %}
{% show_full_credits story "colors" show_sources full_path %}
{% show_full_credits story "script" show_sources %}
{% show_full_credits story "pencils" show_sources %}
{% show_full_credits story "inks" show_sources %}
{% show_full_credits story "colors" show_sources %}
{% if is_cover and not preview and user.is_authenticated and user.indexer.cover_letterer_creator_only %}
{{ story|show_cover_letterer_credit }}
{% else %}
{% show_full_credits story "letters" show_sources full_path %}
{% show_full_credits story "letters" show_sources %}
{% endif %}
{% show_full_credits story "editing" show_sources full_path %}
{% show_full_credits story "editing" show_sources %}
{% endwith %}
</dl>
{% endif %}
Expand Down

1 comment on commit ea8c595

@jochengcd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.