diff --git a/comments/managers.py b/comments/managers.py index c66d7f93225adf6d9e3d1883e32a118bd69f5505..dc094232df4abcdc60b907f36d6fc894af72cf17 100644 --- a/comments/managers.py +++ b/comments/managers.py @@ -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) diff --git a/comments/models.py b/comments/models.py index fda1b74ae3fab6b4abb779b9b6bf09748c36fb82..23ceb52188aef09e7d162499b8e09e2a88786b4f 100644 --- a/comments/models.py +++ b/comments/models.py @@ -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): diff --git a/comments/templates/comments/_comment_card_content.html b/comments/templates/comments/_comment_card_content.html index fb7dff65a51631ad07bb1211b5751b85ffdb217a..6fa4f459bd55ef6e161accab805c8689b5e973b3 100644 --- a/comments/templates/comments/_comment_card_content.html +++ b/comments/templates/comments/_comment_card_content.html @@ -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> diff --git a/comments/templates/comments/_comment_card_extended_for_author.html b/comments/templates/comments/_comment_card_extended_for_author.html index 51c26e39304d86a3b916dce310b43132f9792d83..5fa9fa5f645c02426aa4aecdc37530cb93c9b441 100644 --- a/comments/templates/comments/_comment_card_extended_for_author.html +++ b/comments/templates/comments/_comment_card_extended_for_author.html @@ -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 diff --git a/comments/templates/comments/_comment_tex_template.html b/comments/templates/comments/_comment_tex_template.html index cb39aa0d3c78f50d5fe9f2d75f618abadc9ce8a5..05d5e1479ade5d44ab1b41c9d15647940f1773d3 100644 --- a/comments/templates/comments/_comment_tex_template.html +++ b/comments/templates/comments/_comment_tex_template.html @@ -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 %} diff --git a/comments/templates/partials/comments/comments_list.html b/comments/templates/partials/comments/comments_list.html index ea3e9ac08e398d5ad273a886e34f42cd4e4f6f0d..6f35351e2a6b0e59a50c0c394113cc4040648c71 100644 --- a/comments/templates/partials/comments/comments_list.html +++ b/comments/templates/partials/comments/comments_list.html @@ -1,7 +1,7 @@ {% 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> diff --git a/comments/utils.py b/comments/utils.py index 3f04f17ed887b1b4e54aef374fdc5f26164527c4..8737a8e0d20b60b23fc0f2d9e5efe4bb5a4f313c 100644 --- a/comments/utils.py +++ b/comments/utils.py @@ -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 diff --git a/scipost/feeds.py b/scipost/feeds.py index 8417bbdc3c5dce05ba8aab4441d1bcbfc97d5912..e5426b9bf44f00ca6709654d9637da739cc56dea 100644 --- a/scipost/feeds.py +++ b/scipost/feeds.py @@ -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: diff --git a/scipost/views.py b/scipost/views.py index 2c231572ebcb594b1212840c8a00a1f44c334923..915df08f3fa3e0bfdc34fbef5b55fdda1e969eb5 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -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, diff --git a/templates/search/indexes/comments/comment_text.txt b/templates/search/indexes/comments/comment_text.txt index e187fa7fe26f1fc628c3190ea008c6eeec87dc31..896dec580c8f2d3fb36fbbbf840076ce88922a09 100644 --- a/templates/search/indexes/comments/comment_text.txt +++ b/templates/search/indexes/comments/comment_text.txt @@ -1,3 +1,3 @@ {{object.comment_text}} {{object.date_submitted}} -{{object.author}} +{% if not object.anonymous %}{{ object.author }}{% endif %}