-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date and time fields use browser-default selection widgets #4202
Changes from 10 commits
3e981b8
6d933d9
8e07aa1
85b3d43
f122062
6988cd3
977eaec
074d7b0
9fa0397
e740dbc
0ca2178
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from django.contrib.admin.views.decorators import staff_member_required | ||
from django.contrib.auth.decorators import login_required | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.contrib.humanize.templatetags.humanize import naturaltime | ||
from django.templatetags.static import static | ||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | ||
from django.core.files.base import ContentFile | ||
|
@@ -1016,6 +1017,7 @@ def publish_article(request, article_id): | |
:param article_id: Article PK | ||
:return: contextualised django template | ||
""" | ||
from submission import forms as submission_forms | ||
article = get_object_or_404( | ||
submission_models.Article, | ||
Q(stage=submission_models.STAGE_READY_FOR_PUBLICATION) | | ||
|
@@ -1028,14 +1030,14 @@ def publish_article(request, article_id): | |
doi_data, doi = logic.get_doi_data(article) | ||
issues = request.journal.issues | ||
new_issue_form = issue_forms.NewIssue(journal=article.journal) | ||
pub_date_form = submission_forms.PubDateForm(instance=article) | ||
notify_author_email_form = core_forms.SimpleTinyMCEForm( | ||
'email_to_author', | ||
initial = { | ||
'email_to_author': logic.get_notify_author_text(request, article) | ||
} | ||
) | ||
modal = request.GET.get('m', None) | ||
pubdate_errors = [] | ||
|
||
if request.POST: | ||
if 'assign_issue' in request.POST: | ||
|
@@ -1083,19 +1085,33 @@ def publish_article(request, article_id): | |
) | ||
|
||
if 'pubdate' in request.POST: | ||
date_set, pubdate_errors = logic.handle_set_pubdate( | ||
request, | ||
article, | ||
pub_date_form = submission_forms.PubDateForm( | ||
request.POST, | ||
instance=article, | ||
) | ||
if not pubdate_errors: | ||
return redirect( | ||
reverse( | ||
'publish_article', | ||
kwargs={'article_id': article.pk}, | ||
if pub_date_form.is_valid(): | ||
article = pub_date_form.save() | ||
if article.date_published: | ||
messages.add_message( | ||
request, messages.SUCCESS, | ||
_( | ||
f'Publication date set to { article.date_published.strftime("%Y-%m-%d %H:%M %Z") } ' | ||
f'({ naturaltime(article.date_published) })' | ||
) | ||
) | ||
else: | ||
messages.add_message( | ||
request, messages.SUCCESS, | ||
_('Publication date unset') | ||
) | ||
) | ||
else: | ||
modal = 'pubdate' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this unset on purpose? When the form is invalid generally we'd want to open the modal again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I unset it because there is a general redirect that resets the view and keeps the |
||
messages.add_message( | ||
request, messages.WARNING, | ||
_( | ||
f'Something went wrong when trying to save the form. ' | ||
f'Please try again.' | ||
) | ||
) | ||
|
||
if 'author' in request.POST: | ||
logic.notify_author(request, article) | ||
|
@@ -1201,7 +1217,7 @@ def publish_article(request, article_id): | |
'issues': issues, | ||
'new_issue_form': new_issue_form, | ||
'modal': modal, | ||
'pubdate_errors': pubdate_errors, | ||
'pub_date_form': pub_date_form, | ||
'notify_author_email_form': notify_author_email_form, | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,3 +524,19 @@ def utility_clean_orcid(orcid): | |
|
||
# ORCID is None. | ||
return orcid | ||
|
||
|
||
class PubDateForm(forms.ModelForm): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great. |
||
class Meta: | ||
model = models.Article | ||
fields = ('date_published',) | ||
|
||
def save(self, commit=True): | ||
article = super().save(commit=commit) | ||
if commit: | ||
article.fixedpubcheckitems.set_pub_date = bool( | ||
article.date_published | ||
) | ||
article.fixedpubcheckitems.save() | ||
article.save() | ||
return article |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.2.20 on 2024-05-24 17:29 | ||
|
||
import core.model_utils | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('submission', '0075_auto_20240312_0922'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='article', | ||
name='date_published', | ||
field=core.model_utils.DateTimePickerModelField(blank=True, null=True), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<input | ||
type="datetime-local" | ||
name="{{ widget.name }}" | ||
{% if widget.value != None %} | ||
value="{{ widget.value|slice:'0:10'}}T{{widget.value|slice:'11:'}}" | ||
{% endif %} | ||
{% include "django/forms/widgets/attrs.html" %}> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
<h4><i class="fa fa-folder-open-o"> </i>Set Publication Date/Time</h4> | ||
</div> | ||
<div class="card-section"> | ||
{% include "elements/forms/generic_errors.html" with errors=pubdate_errors %} | ||
<h5>Publication Date/Time</h5> | ||
<p>You can set the publication date and time here so that even when an article is marked as published, users will not | ||
be able to view it until the date/time has past.</p> | ||
|
@@ -18,21 +17,8 @@ <h5>Publication Date/Time</h5> | |
{% endif %} | ||
<form method="POST"> | ||
{% csrf_token %} | ||
<div class="callout"> | ||
<div class="row"> | ||
<div class="large-8 columns"> | ||
<label for="date">Date</label> | ||
<input type="text" name="date" id="date" required {% if article.date_published %}value="{{ article.date_published|date:'Y-m-d' }}"{% endif %}> | ||
</div> | ||
<div class="large-4 columns"> | ||
<label for="time">Time</label> | ||
<input type="text" name="time" id="time" required {% if article.date_published %}value="{{ article.date_published|date:'H:i' }}"{% endif %}> | ||
</div> | ||
<div class="large-12 columns"> | ||
<button type="submit" name="pubdate" class="small success button">Set Publication Date</button> | ||
</div> | ||
</div> | ||
</div> | ||
{{ pub_date_form }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, that is wild. Firefox clears it in my inspector pane (after parsing the HTML) but I can see it when I inspect the source. Is this a Django default feature, or something we have configured? In any case, I've added the foundation filter. |
||
<button type="submit" name="pubdate" class="small success button">Set Publication Date</button> | ||
</form> | ||
<button class="close-button" data-close aria-label="Close reveal" type="button"> | ||
<span aria-hidden="true">×</span> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does having this import in the head cause a circular import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I believe so. There is another function in this file that has the same import.