SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit d5c5c84d authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Fully integrate anonymized Comments

parent f0e54173
No related branches found
No related tags found
No related merge requests found
......@@ -19,3 +19,6 @@ class CommentQuerySet(models.QuerySet):
def author_replies(self):
return self.filter(is_author_reply=True)
def publicly_visible(self):
return self.filter(anonymous=False, status__gte=1)
......@@ -27,8 +27,10 @@ US_NOTICE = 'Warning: This field is out of service and will be removed in the fu
class Comment(TimeStampedModel):
""" A Comment is an unsollicited note, submitted by a Contributor,
on a particular publication or in reply to an earlier Comment. """
""" A Comment is an unsollicited note, submitted by a Contributor.
A Comment is pointed to a particular publication or in reply to an earlier Comment. It
may be l"""
status = models.SmallIntegerField(default=STATUS_PENDING, choices=COMMENT_STATUS)
vetted_by = models.ForeignKey('scipost.Contributor', blank=True, null=True,
......@@ -151,16 +153,16 @@ class Comment(TimeStampedModel):
assign_perm('comments.can_vet_comments', to_object.editor_in_charge.user, self)
def get_author(self):
'''Get author, if and only if comment is not anonymous!!!'''
"""Return Contributor instance of object if not anonymous."""
if not self.anonymous:
return self.author
return None
def get_author_str(self):
'''Get author string, if and only if comment is not anonymous!!!'''
"""Return author string if not anonymous."""
author = self.get_author()
if author:
return author.user.first_name + ' ' + author.user.last_name
return '{} {}'.format(author.get_title_display(), author.user.last_name)
return 'Anonymous'
def update_opinions(self, contributor_id, opinion):
......
......@@ -2,10 +2,11 @@
{% block card_block_header %}{% endblock %}
<p class="card-text">
{% if comment.anonymous %}
Anonymous:
Anonymous:
{% else %}
<a href="{{comment.author.get_absolute_url}}">{{comment.author.user.first_name}} {{comment.author.user.last_name}}</a>:
<a href="{{ comment.author.get_absolute_url }}">{{ comment.get_author_str }}</a>:
{% endif %}
<a href="{{comment.get_absolute_url}}">
"{{comment.comment_text|slice:'30'}}{% if comment.comment_text|length > 30 %}...{% endif %}"
</a>
......
......@@ -5,7 +5,11 @@
</div>
<p>"{{comment.comment_text|linebreaksbr}}"</p>
<p class="card-text">by <a href="{{comment.author.get_absolute_url}}">{{comment.author.user.first_name}} {{comment.author.user.last_name}}</a> in {{comment.content_type|capfirst}} on <a href="{{comment.content_object.get_absolute_url}}" class="pubtitleli">{{comment.title}}</a> {% if comment.content_object.author_list %} <span class="text-muted">by {{comment.content_object.author_list}}</span>{% endif %}</p>
{% if comment.anonymous %}
<p class="card-text">by Anonymous in {{comment.content_type|capfirst}} on <a href="{{comment.content_object.get_absolute_url}}" class="pubtitleli">{{comment.title}}</a> {% if comment.content_object.author_list %} <span class="text-muted">by {{comment.content_object.author_list}}</span>{% endif %}</p>
{% else %}
<p class="card-text">by <a href="{{comment.author.get_absolute_url}}">{{comment.author.user.first_name}} {{comment.author.user.last_name}}</a> in {{comment.content_type|capfirst}} on <a href="{{comment.content_object.get_absolute_url}}" class="pubtitleli">{{comment.title}}</a> {% if comment.content_object.author_list %} <span class="text-muted">by {{comment.content_object.author_list}}</span>{% endif %}</p>
{% endif %}
{% comment %}
Using 'by xxx' on non-submission comments here would be ambigious. Does the `by xxx` apply to the
......
......@@ -4,8 +4,8 @@ Received {{comment.date_submitted|date:'d-m-Y'}}\ \\
{% endspaceless %}
{% for subcomment in comment.nested_comments.vetted %}
\addcontentsline{toc}{subsection}{\protect\numberline{}{% if subcomment.is_author_reply %}Author Reply{% else %}Comment{% endif %} {{forloop.counter}} by {{subcomment.author.user.first_name}} {{subcomment.author.user.last_name}} }
\addcontentsline{toc}{subsection}{\protect\numberline{}{% if subcomment.is_author_reply %}Author Reply{% else %}Comment{% endif %} {{forloop.counter}} by {% if subcomment.anonymous %}Anonymous{% else %}{{subcomment.author.user.first_name}} {{subcomment.author.user.last_name}}{% endif %} }
\subsection*{ {% if subcomment.is_author_reply %}Author Reply{% else %}Comment{% endif %} {{forloop.parentloop.counter}}.{{forloop.counter}} by {{subcomment.author.user.first_name}} {{subcomment.author.user.last_name}} }
\subsection*{ {% if subcomment.is_author_reply %}Author Reply{% else %}Comment{% endif %} {{forloop.parentloop.counter}}.{{forloop.counter}} by {% if subcomment.anonymous %}Anonymous{% else %}{{subcomment.author.user.first_name}} {{subcomment.author.user.last_name}}{% endif %} }
{% include 'comments/_comment_tex_template.html' with comment=subcomment %}
{% endfor %}
{% if comments %}
<ul class="{{ css_class|default:'' }}">
{% for comment in comments %}
<li><a href="{{ comment.get_absolute_url }}"{% if target_blank %} target="_blank"{% endif %}>{% if comment.is_author_reply %}Author Reply{% else %}Comment{% endif %} by {{ comment.author.get_title_display }} {{ comment.author.user.last_name }} on {{ comment.date_submitted|date:'DATE_FORMAT' }}</a></li>
<li><a href="{{ comment.get_absolute_url }}"{% if target_blank %} target="_blank"{% endif %}>{% if comment.is_author_reply %}Author Reply{% else %}Comment{% endif %} by {{ comment.get_author_str }} on {{ comment.date_submitted|date:'DATE_FORMAT' }}</a></li>
{% include 'partials/comments/comments_list.html' with comments=comment.nested_comments.vetted css_class='m-0 pl-4' %}
{% endfor %}
</ul>
......
......@@ -8,7 +8,7 @@ from common.utils import BaseMailUtil
def validate_file_extention(value, allowed_extentions):
'''Check if a filefield (value) has allowed extentions.'''
"""Check if a filefield (value) has allowed extentions."""
ext = os.path.splitext(value.name)[1] # [0] returns path+filename
return ext.lower() in allowed_extentions
......@@ -19,8 +19,7 @@ class CommentUtils(BaseMailUtil):
@classmethod
def email_comment_vet_accepted_to_author(cls):
"""
Send mail after Comment is vetted: `Accept`
"""Send mail after Comment is vetted: `Accept`.
Requires loading:
comment -- Comment
......@@ -43,8 +42,7 @@ class CommentUtils(BaseMailUtil):
@classmethod
def email_comment_vet_rejected_to_author(cls, email_response=''):
"""
Send mail after Comment is vetted: `Reject`
"""Send mail after Comment is vetted: `Reject`.
Requires loading:
comment -- Comment
......
......@@ -11,11 +11,13 @@ from django.core.urlresolvers import reverse
from django.db.models import Q
from comments.models import Comment
from commentaries.models import Commentary
from journals.models import Publication
from news.models import NewsItem
from scipost.models import subject_areas_dict
from submissions.constants import SUBMISSION_STATUS_PUBLICLY_INVISIBLE
from submissions.models import Submission
from theses.models import ThesisLink
class LatestCommentsFeedRSS(Feed):
......@@ -24,7 +26,7 @@ class LatestCommentsFeedRSS(Feed):
link = "/comments/"
def items(self):
return Comment.objects.filter(status__gte=0).order_by('-date_submitted')[:10]
return Comment.objects.vetted().order_by('-date_submitted')[:10]
def item_title(self, item):
return item.comment_text[:50]
......@@ -33,14 +35,14 @@ class LatestCommentsFeedRSS(Feed):
return item.comment_text[:50]
def item_link(self, item):
if item.commentary:
if isinstance(item.content_object, Commentary):
return reverse('commentaries:commentary',
kwargs={'arxiv_or_DOI_string': item.commentary.arxiv_or_DOI_string})
elif item.submission:
kwargs={'arxiv_or_DOI_string': item.content_object.arxiv_or_DOI_string})
elif isinstance(item.content_object, Submission):
return reverse('submissions:submission',
kwargs={'arxiv_identifier_w_vn_nr':
item.submission.arxiv_identifier_w_vn_nr})
elif item.thesislink:
item.content_object.arxiv_identifier_w_vn_nr})
elif isinstance(item.content_object, ThesisLink):
return reverse('theses:thesis',
kwargs={'thesislink_id': item.thesislink.id})
else:
......
......@@ -868,10 +868,10 @@ def contributor_info(request, contributor_id):
contributor_submissions = Submission.objects.public_unlisted().filter(authors=contributor)
contributor_commentaries = Commentary.objects.filter(authors=contributor)
contributor_theses = ThesisLink.objects.vetted().filter(author_as_cont=contributor)
contributor_comments = (Comment.objects.vetted()
contributor_comments = (Comment.objects.vetted().publicly_visible()
.filter(author=contributor, is_author_reply=False)
.order_by('-date_submitted'))
contributor_authorreplies = (Comment.objects.vetted()
contributor_authorreplies = (Comment.objects.vetted().publicly_visible()
.filter(author=contributor, is_author_reply=True)
.order_by('-date_submitted'))
context = {'contributor': contributor,
......
{{object.comment_text}}
{{object.date_submitted}}
{{object.author}}
{% if not object.anonymous %}{{ object.author }}{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment