diff --git a/commentaries/models.py b/commentaries/models.py index 903ed64694b73410a780c92581ba4df1243e8d2c..0da8b2bce3415abcf394799c535f3c324702829a 100644 --- a/commentaries/models.py +++ b/commentaries/models.py @@ -1,16 +1,17 @@ -from django.utils import timezone from django.db import models from django.contrib.postgres.fields import JSONField from django.template import Template, Context -from journals.models import SCIPOST_JOURNALS_DOMAINS, SCIPOST_JOURNALS_SPECIALIZATIONS +from journals.models import SCIPOST_JOURNALS_DOMAINS from scipost.models import TimeStampedModel, Contributor -from scipost.constants import SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS +from scipost.constants import SCIPOST_DISCIPLINES, DISCIPLINE_PHYSICS, SCIPOST_SUBJECT_AREAS +COMMENTARY_PUBLISHED = 'published' +COMMENTARY_PREPRINT = 'preprint' COMMENTARY_TYPES = ( - ('published', 'published paper'), - ('preprint', 'arXiv preprint'), - ) + (COMMENTARY_PUBLISHED, 'published paper'), + (COMMENTARY_PREPRINT, 'arXiv preprint'), +) class CommentaryManager(models.Manager): @@ -20,6 +21,7 @@ class CommentaryManager(models.Manager): def awaiting_vetting(self, **kwargs): return self.filter(vetted=False, **kwargs) + class Commentary(TimeStampedModel): """ A Commentary contains all the contents of a SciPost Commentary page for a given publication. @@ -30,7 +32,8 @@ class Commentary(TimeStampedModel): vetted = models.BooleanField(default=False) vetted_by = models.ForeignKey(Contributor, blank=True, null=True, on_delete=models.CASCADE) type = models.CharField(max_length=9, choices=COMMENTARY_TYPES) - discipline = models.CharField(max_length=20, choices=SCIPOST_DISCIPLINES, default='physics') + discipline = models.CharField(max_length=20, + choices=SCIPOST_DISCIPLINES, default=DISCIPLINE_PHYSICS) domain = models.CharField(max_length=3, choices=SCIPOST_JOURNALS_DOMAINS) subject_area = models.CharField( max_length=10, choices=SCIPOST_SUBJECT_AREAS, @@ -50,8 +53,7 @@ class Commentary(TimeStampedModel): metadata = JSONField(default={}, blank=True, null=True) arxiv_or_DOI_string = models.CharField( max_length=100, - verbose_name='string form of arxiv nr or DOI for commentary url', - default='') + verbose_name='string form of arxiv nr or DOI for commentary url') author_list = models.CharField(max_length=1000) # Authors which have been mapped to contributors: @@ -126,8 +128,8 @@ class Commentary(TimeStampedModel): 'author_list': self.author_list, 'latest_activity': self.latest_activity.strftime('%Y-%m-%d %H:%M')}) header = ('<li>' - #'<div class="flex-container">' - #'<div class="flex-whitebox0">' + # '<div class="flex-container">' + # '<div class="flex-whitebox0">' '<p><a href="{{ scipost_url }}" ' 'class="pubtitleli">{{ pub_title }}</a></p>' '<p>by {{ author_list }}') @@ -144,7 +146,7 @@ class Commentary(TimeStampedModel): header += '<p> (published {{ pub_date }}) - ' context['pub_date'] = str(self.pub_date) header += ('latest activity: {{ latest_activity }}</p>' - #'</div></div>' + # '</div></div>' '</li>') template = Template(header) @@ -179,7 +181,7 @@ class Commentary(TimeStampedModel): elif self.arxiv_identifier: self.arxiv_or_DOI_string = 'arXiv:' + self.arxiv_identifier self.arxiv_link = 'http://arxiv.org/abs/' + self.arxiv_identifier - else: # should never come here + else: # should never come here pass self.save() diff --git a/commentaries/test_forms.py b/commentaries/test_forms.py index bd41e58a1a4105431445cd280f0ddb6fbb3589f0..4f203579623abbd09d6a8bec9a265b0b35fc6c9b 100644 --- a/commentaries/test_forms.py +++ b/commentaries/test_forms.py @@ -60,7 +60,7 @@ class TestVetCommentaryForm(TestCase): self.assertFalse(Commentary.objects.awaiting_vetting().exists()) # Refusal choice is ok - refusal_reason_inserted = VetCommentaryForm.COMMENTARY_REFUSAL_DICT[\ + refusal_reason_inserted = VetCommentaryForm.COMMENTARY_REFUSAL_DICT[ VetCommentaryForm.REFUSAL_UNTRACEBLE] self.assertEqual(form.get_refusal_reason(), refusal_reason_inserted) diff --git a/commentaries/tests.py b/commentaries/tests.py deleted file mode 100644 index 7ce503c2dd97ba78597f6ff6e4393132753573f6..0000000000000000000000000000000000000000 --- a/commentaries/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/commentaries/views.py b/commentaries/views.py index aa653f178663c94fbdecb8bca2d708691b73bfe3..8c9288b1c8fb1c56e0f3d38d9d7db71c0f8dc430 100644 --- a/commentaries/views.py +++ b/commentaries/views.py @@ -3,14 +3,11 @@ import feedparser import re import requests -from django.db.models import Q from django.utils import timezone from django.shortcuts import get_object_or_404, render -from django.contrib.auth import login, logout from django.contrib.auth.decorators import login_required, permission_required from django.core.mail import EmailMessage from django.core.urlresolvers import reverse -from django.http import HttpResponse from django.shortcuts import redirect from django.template.loader import render_to_string @@ -21,9 +18,6 @@ from .forms import VetCommentaryForm, CommentarySearchForm from comments.models import Comment from comments.forms import CommentForm from scipost.models import Contributor -from scipost.models import title_dict -from scipost.forms import AuthenticationForm - ################ # Commentaries @@ -61,6 +55,7 @@ def request_commentary(request): context = {'form': form, 'doiform': doiform, 'identifierform': identifierform} return render(request, 'commentaries/request_commentary.html', context) + @permission_required('scipost.can_request_commentary_pages', raise_exception=True) def prefill_using_DOI(request): """ Probes CrossRef API with the DOI, to pre-fill the form. """ @@ -75,7 +70,8 @@ def prefill_using_DOI(request): errormessage = 'The DOI you entered is improperly formatted.' elif Commentary.objects.filter(pub_DOI=doiform.cleaned_data['doi']).exists(): errormessage = 'There already exists a Commentary Page on this publication, see' - existing_commentary = get_object_or_404(Commentary, pub_DOI=doiform.cleaned_data['doi']) + existing_commentary = get_object_or_404(Commentary, + pub_DOI=doiform.cleaned_data['doi']) if errormessage: form = RequestCommentaryForm() identifierform = IdentifierToQueryForm() @@ -104,7 +100,7 @@ def prefill_using_DOI(request): pages = '' try: - pages = doiqueryJSON['message']['article-number'] # for Phys Rev + pages = doiqueryJSON['message']['article-number'] # for Phys Rev except KeyError: pass try: @@ -117,7 +113,8 @@ def prefill_using_DOI(request): pub_date = (str(doiqueryJSON['message']['issued']['date-parts'][0][0]) + '-' + str(doiqueryJSON['message']['issued']['date-parts'][0][1])) try: - pub_date += '-' + str(doiqueryJSON['message']['issued']['date-parts'][0][2]) + pub_date += '-' + str( + doiqueryJSON['message']['issued']['date-parts'][0][2]) except (IndexError, KeyError): pass except (IndexError, KeyError): @@ -130,7 +127,7 @@ def prefill_using_DOI(request): 'pages': pages, 'pub_date': pub_date, 'pub_DOI': pub_DOI}) identifierform = IdentifierToQueryForm() - context = {'form': form, 'doiform': doiform, 'identifierform': identifierform,} + context = {'form': form, 'doiform': doiform, 'identifierform': identifierform, } context['title'] = pub_title return render(request, 'commentaries/request_commentary.html', context) except (IndexError, KeyError, ValueError): @@ -139,6 +136,7 @@ def prefill_using_DOI(request): pass return redirect(reverse('commentaries:request_commentary')) + @permission_required('scipost.can_request_commentary_pages', raise_exception=True) def prefill_using_identifier(request): """Probes arXiv with the identifier, to pre-fill the form""" @@ -182,7 +180,7 @@ def prefill_using_identifier(request): pass try: arxiv_doi = arxivquery['entries'][0]['arxiv_doi'] - errormessage = ('This paper has been published under DOI ' + arxiv_DOI + errormessage = ('This paper has been published under DOI ' + arxiv_doi + '. Please comment on the published version.') except (IndexError, KeyError): pass @@ -212,8 +210,10 @@ def prefill_using_identifier(request): context = {'form': form, 'doiform': doiform, 'identifierform': identifierform} context['title'] = pub_title return render(request, 'commentaries/request_commentary.html', context) - except (IndexError, KeyError, ValueError): # something went wrong with processing the arXiv data - errormessage = 'An error occurred while processing the arXiv data. Are you sure this identifier exists?' + except (IndexError, KeyError, ValueError): + # something went wrong with processing the arXiv data + errormessage = ('An error occurred while processing the arXiv data.' + ' Are you sure this identifier exists?') form = RequestCommentaryForm() doiform = DOIToQueryForm() context = {'form': form, 'doiform': doiform, 'identifierform': identifierform, @@ -229,11 +229,12 @@ def prefill_using_identifier(request): def vet_commentary_requests(request): """Show the first commentary thats awaiting vetting""" contributor = Contributor.objects.get(user=request.user) - commentary_to_vet = Commentary.objects.awaiting_vetting().first() # only handle one at a time + commentary_to_vet = Commentary.objects.awaiting_vetting().first() # only handle one at a time form = VetCommentaryForm() - context = {'contributor': contributor, 'commentary_to_vet': commentary_to_vet, 'form': form } + context = {'contributor': contributor, 'commentary_to_vet': commentary_to_vet, 'form': form} return render(request, 'commentaries/vet_commentary_requests.html', context) + @permission_required('scipost.can_vet_commentary_requests', raise_exception=True) def vet_commentary_request_ack(request, commentary_id): if request.method == 'POST': @@ -287,6 +288,7 @@ def vet_commentary_request_ack(request, commentary_id): 'followup_link_label': 'Commentary requests page'} return render(request, 'scipost/acknowledgement.html', context) + def commentaries(request): """List and search all commentaries""" form = CommentarySearchForm(request.POST or None) @@ -303,6 +305,7 @@ def commentaries(request): 'commentary_recent_list': commentary_recent_list} return render(request, 'commentaries/commentaries.html', context) + def browse(request, discipline, nrweeksback): """List all commentaries for discipline and period""" commentary_browse_list = Commentary.objects.vetted( @@ -314,6 +317,7 @@ def browse(request, discipline, nrweeksback): 'commentary_browse_list': commentary_browse_list} return render(request, 'commentaries/commentaries.html', context) + def commentary_detail(request, arxiv_or_DOI_string): commentary = get_object_or_404(Commentary, arxiv_or_DOI_string=arxiv_or_DOI_string) comments = commentary.comment_set.all() @@ -322,18 +326,18 @@ def commentary_detail(request, arxiv_or_DOI_string): if form.is_valid(): author = Contributor.objects.get(user=request.user) newcomment = Comment(commentary=commentary, author=author, - is_rem=form.cleaned_data['is_rem'], - is_que=form.cleaned_data['is_que'], - is_ans=form.cleaned_data['is_ans'], - is_obj=form.cleaned_data['is_obj'], - is_rep=form.cleaned_data['is_rep'], - is_val=form.cleaned_data['is_val'], - is_lit=form.cleaned_data['is_lit'], - is_sug=form.cleaned_data['is_sug'], - comment_text=form.cleaned_data['comment_text'], - remarks_for_editors=form.cleaned_data['remarks_for_editors'], - date_submitted=timezone.now(), - ) + is_rem=form.cleaned_data['is_rem'], + is_que=form.cleaned_data['is_que'], + is_ans=form.cleaned_data['is_ans'], + is_obj=form.cleaned_data['is_obj'], + is_rep=form.cleaned_data['is_rep'], + is_val=form.cleaned_data['is_val'], + is_lit=form.cleaned_data['is_lit'], + is_sug=form.cleaned_data['is_sug'], + comment_text=form.cleaned_data['comment_text'], + remarks_for_editors=form.cleaned_data['remarks_for_editors'], + date_submitted=timezone.now(), + ) newcomment.save() author.nr_comments = Comment.objects.filter(author=author).count() author.save() @@ -342,10 +346,12 @@ def commentary_detail(request, arxiv_or_DOI_string): 'followup_message': 'Back to the ', 'followup_link': reverse( 'commentaries:commentary', - kwargs={'arxiv_or_DOI_string': newcomment.commentary.arxiv_or_DOI_string} + kwargs={ + 'arxiv_or_DOI_string': newcomment.commentary.arxiv_or_DOI_string + } ), 'followup_link_label': ' Commentary page you came from' - } + } return render(request, 'scipost/acknowledgement.html', context) else: form = CommentForm() diff --git a/package.json b/package.json index 96e4911bf46ead8dac9415ad398525293fd81d64..8532c718ab3a888928c2e7c4f06ec6d85d5c8eab 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "bootstrap-loader": "^2.0.0-beta.19", "clean-webpack-plugin": "^0.1.15", "css-loader": "^0.26.1", - "extract-text-webpack-plugin": "^2.0.0-beta.5", + "extract-text-webpack-plugin": "^2.0.0-beta.2", "file-loader": "^0.8.4", "imports-loader": "^0.7.0", "jquery": "^2.2.0", @@ -35,7 +35,7 @@ "style-loader": "^0.13.1", "tether": "^1.4.0", "url-loader": "^0.5.7", - "webpack": "^2.2.0", + "webpack": "^2.1.0-beta.19", "webpack-bundle-tracker": "^0.2.0", "webpack-glob-entry": "^2.1.1" } diff --git a/scipost/constants.py b/scipost/constants.py index 7c7933e18e787769f830f999423730a6af836d82..7a64c84d499aa7c53bf5e78a121db533e881dd56 100644 --- a/scipost/constants.py +++ b/scipost/constants.py @@ -1,3 +1,7 @@ +DISCIPLINE_PHYSICS = 'physics' +DISCIPLINE_ASTROPHYSICS = 'astrophysics' +DISCIPLINE_MATH = 'mathematics' +DISCIPLINE_COMPUTERSCIENCE = 'computerscience' SCIPOST_DISCIPLINES = ( ('physics', 'Physics'), ('astrophysics', 'Astrophysics'),