diff --git a/comments/models.py b/comments/models.py index 74a89b0071fa138a75668f0906a9bdeb9a24b800..d8ff43dfb400576a45462a9d9a68ceb85e1b2c28 100644 --- a/comments/models.py +++ b/comments/models.py @@ -63,27 +63,24 @@ class Comment(models.Model): remarks_for_editors = models.TextField(default='', blank=True, verbose_name='optional remarks for the Editors only') date_submitted = models.DateTimeField('date submitted') # Opinions - nr_FA = models.PositiveIntegerField(default=0) - nr_MA = models.PositiveIntegerField(default=0) - nr_DIS = models.PositiveIntegerField(default=0) - nr_OBJ = models.PositiveIntegerField(default=0) + nr_A = models.PositiveIntegerField(default=0) + nr_N = models.PositiveIntegerField(default=0) + nr_D = models.PositiveIntegerField(default=0) def __str__ (self): return self.comment_text def recalculate_nr_opinions(self): - self.nr_FA = Opinion.objects.filter(comment=self, opinion='FA').count() - self.nr_MA = Opinion.objects.filter(comment=self, opinion='MA').count() - self.nr_DIS = Opinion.objects.filter(comment=self, opinion='DIS').count() - self.nr_OBJ = Opinion.objects.filter(comment=self, opinion='OBJ').count() + self.nr_A = Opinion.objects.filter(comment=self, opinion='A').count() + self.nr_N = Opinion.objects.filter(comment=self, opinion='N').count() + self.nr_D = Opinion.objects.filter(comment=self, opinion='D').count() self.save() def opinions_as_ul(self): output = '<div class="opinionsDisplay"><ul>' - output += '<li>Fully agree: ' + str(self.nr_FA) + '</li>' - output += '<li>Mostly agree: ' + str(self.nr_MA) + '</li>' - output += '<li>Disagree: ' + str(self.nr_DIS) + '</li>' - output += '<li>Object: ' + str(self.nr_OBJ) + '</li>' + output += '<li>Agree: ' + str(self.nr_A) + '</li>' + output += '<li>Neutral: ' + str(self.nr_N) + '</li>' + output += '<li>Disagree: ' + str(self.nr_D) + '</li>' output += '</ul></div>' return output diff --git a/scipost/models.py b/scipost/models.py index 9b0a0dbe1daed821c384bffd55ec902b4f0d0bf9..1208e41e6e0be7205813af0ca4da36889e7e0542 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -112,15 +112,13 @@ class Assessment(models.Model): significance = models.PositiveSmallIntegerField(choices=ASSESSMENT_CHOICES, default=101) - ### Opinions OPINION_CHOICES = ( ('ABS', '-'), - ('FA', 'I fully agree'), - ('MA', 'I mostly agree'), - ('DIS', 'I disagree'), - ('OBJ', 'I object to this'), + ('A', 'agree'), + ('N', 'neutral'), + ('D', 'disagree'), ) opinion_choices_dict = dict(OPINION_CHOICES) diff --git a/scipost/views.py b/scipost/views.py index 50c2b77cc7209d9c3d1b913ce425aa5f698c9cc7..650304762ab08c3971c4109868506271b2355de6 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -39,7 +39,9 @@ def index(request): submission_search_form = SubmissionSearchForm(request.POST) commentary_search_form = CommentarySearchForm(request.POST) thesislink_search_form = ThesisLinkSearchForm(request.POST) - context = {'submission_search_form': submission_search_form, 'commentary_search_form': commentary_search_form, 'thesislink_search_form': thesislink_search_form} + context = {'submission_search_form': submission_search_form, + 'commentary_search_form': commentary_search_form, + 'thesislink_search_form': thesislink_search_form} return render(request, 'scipost/index.html', context) ############### @@ -67,11 +69,14 @@ def register(request): Utils.load({'form': form}) if form.is_valid(): if Utils.password_mismatch(): - return render(request, 'scipost/register.html', {'form': form, 'errormessage': 'Your passwords must match'}) + return render(request, 'scipost/register.html', + {'form': form, 'errormessage': 'Your passwords must match'}) if Utils.username_already_taken(): - return render(request, 'scipost/register.html', {'form': form, 'errormessage': 'This username is already in use'}) + return render(request, 'scipost/register.html', + {'form': form, 'errormessage': 'This username is already in use'}) if Utils.email_already_taken(): - return render(request, 'scipost/register.html', {'form': form, 'errormessage': 'This email address is already in use'}) + return render(request, 'scipost/register.html', + {'form': form, 'errormessage': 'This email address is already in use'}) Utils.create_and_save_contributor() Utils.send_registration_email() return HttpResponseRedirect('thanks_for_registering') @@ -117,8 +122,13 @@ def request_new_activation_link(request, oldkey): contributor.activation_key = hashlib.sha1(salt+usernamesalt).hexdigest() contributor.key_expires = datetime.datetime.strftime(datetime.datetime.now() + datetime.timedelta(days=2), "%Y-%m-%d %H:%M:%S") contributor.save() - email_text = 'Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + ', \n\nYour request for a new email activation link for registration to the SciPost publication portal has been received. You now need to visit this link within the next 48 hours: \n\n' + 'https://scipost.org/activation/' + contributor.activation_key + '\n\nYour registration will thereafter be vetted. Many thanks for your interest. \n\nThe SciPost Team.' - emailmessage = EmailMessage('SciPost registration: new email activation link', email_text, 'registration@scipost.org', [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) + email_text = ('Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + + ', \n\nYour request for a new email activation link for registration to the SciPost ' + + 'publication portal has been received. You now need to visit this link within the next 48 hours: \n\n' + + 'https://scipost.org/activation/' + contributor.activation_key + + '\n\nYour registration will thereafter be vetted. Many thanks for your interest. \n\nThe SciPost Team.') + emailmessage = EmailMessage('SciPost registration: new email activation link', email_text, 'registration@scipost.org', + [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) emailmessage.send(fail_silently=False) return render (request, 'scipost/request_new_activation_link_ack.html') @@ -143,15 +153,23 @@ def vet_registration_request_ack(request, contributor_id): if form.cleaned_data['promote_to_rank_1']: contributor.rank = 1 contributor.save() - email_text = 'Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + ', \n\nYour registration to the SciPost publication portal has been accepted. You can now login and contribute. \n\nThe SciPost Team.' - emailmessage = EmailMessage('SciPost registration accepted', email_text, 'registration@scipost.org', [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) + email_text = ('Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + + ', \n\nYour registration to the SciPost publication portal has been accepted. ' + + 'You can now login and contribute. \n\nThe SciPost Team.') + emailmessage = EmailMessage('SciPost registration accepted', email_text, 'registration@scipost.org', + [contributor.user.email, 'registration@scipost.org'], + reply_to=['registration@scipost.org']) emailmessage.send(fail_silently=False) else: ref_reason = int(form.cleaned_data['refusal_reason']) - email_text = 'Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + ', \n\nYour registration to the SciPost publication portal has been turned down, the reason being: ' + reg_ref_dict[ref_reason] + '. You can however still view all SciPost contents, just not submit papers, comments or votes. We nonetheless thank you for your interest. \n\nThe SciPost Team.' + email_text = ('Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + + ', \n\nYour registration to the SciPost publication portal has been turned down, the reason being: ' + + reg_ref_dict[ref_reason] + '. You can however still view all SciPost contents, just not submit papers, ' + + 'comments or votes. We nonetheless thank you for your interest. \n\nThe SciPost Team.') if form.cleaned_data['email_response_field']: email_text += '\n\nFurther explanations: ' + form.cleaned_data['email_response_field'] - emailmessage = EmailMessage('SciPost registration: unsuccessful', email_text, 'registration@scipost.org', [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) + emailmessage = EmailMessage('SciPost registration: unsuccessful', email_text, 'registration@scipost.org', + [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) emailmessage.send(fail_silently=False) contributor.rank = form.cleaned_data['refusal_reason'] contributor.save() @@ -198,7 +216,9 @@ def personal_page(request): intwodays = now + timezone.timedelta(days=2) # count the number of pending registration request nr_reg_to_vet = Contributor.objects.filter(user__is_active=True, rank=0).count() - nr_reg_awaiting_validation = Contributor.objects.filter(user__is_active=False, key_expires__gte=now, key_expires__lte=intwodays, rank=0).count() + nr_reg_awaiting_validation = Contributor.objects.filter( + user__is_active=False, key_expires__gte=now, key_expires__lte=intwodays, rank=0 + ).count() nr_submissions_to_process = Submission.objects.filter(vetted=False).count() nr_commentary_page_requests_to_vet = 0 nr_comments_to_vet = 0 @@ -213,7 +233,15 @@ def personal_page(request): nr_thesislink_requests_to_vet = ThesisLink.objects.filter(vetted=False).count() own_comments = Comment.objects.filter(author=contributor).order_by('-date_submitted') own_authorreplies = AuthorReply.objects.filter(author=contributor).order_by('-date_submitted') - context = {'contributor': contributor, 'nr_reg_to_vet': nr_reg_to_vet, 'nr_reg_awaiting_validation': nr_reg_awaiting_validation, 'nr_commentary_page_requests_to_vet': nr_commentary_page_requests_to_vet, 'nr_comments_to_vet': nr_comments_to_vet, 'nr_author_replies_to_vet': nr_author_replies_to_vet, 'nr_reports_to_vet': nr_reports_to_vet, 'nr_submissions_to_process': nr_submissions_to_process, 'nr_thesislink_requests_to_vet': nr_thesislink_requests_to_vet, 'own_comments': own_comments, 'own_authorreplies': own_authorreplies} + context = {'contributor': contributor, 'nr_reg_to_vet': nr_reg_to_vet, + 'nr_reg_awaiting_validation': nr_reg_awaiting_validation, + 'nr_commentary_page_requests_to_vet': nr_commentary_page_requests_to_vet, + 'nr_comments_to_vet': nr_comments_to_vet, + 'nr_author_replies_to_vet': nr_author_replies_to_vet, + 'nr_reports_to_vet': nr_reports_to_vet, + 'nr_submissions_to_process': nr_submissions_to_process, + 'nr_thesislink_requests_to_vet': nr_thesislink_requests_to_vet, + 'own_comments': own_comments, 'own_authorreplies': own_authorreplies} return render(request, 'scipost/personal_page.html', context) else: form = AuthenticationForm() @@ -226,9 +254,11 @@ def change_password(request): form = PasswordChangeForm(request.POST) if form.is_valid(): if not request.user.check_password(form.cleaned_data['password_prev']): - return render(request, 'scipost/change_password.html', {'form': form, 'errormessage': 'The currently existing password you entered is incorrect'}) + return render(request, 'scipost/change_password.html', + {'form': form, 'errormessage': 'The currently existing password you entered is incorrect'}) if form.cleaned_data['password_new'] != form.cleaned_data['password_verif']: - return render(request, 'scipost/change_password.html', {'form': form, 'errormessage': 'Your new password entries must match'}) + return render(request, 'scipost/change_password.html', + {'form': form, 'errormessage': 'Your new password entries must match'}) request.user.set_password(form.cleaned_data['password_new']) request.user.save() ack = True