def status(self): if self.is_anonymous: if is_from_swat(user=self.user, ip=self.ip_address): return "Unregistered, Swarthmore" else: return "Unregistered, Non-Swarthmore" else: if self.user.staff_status(): return "Editor" if self.user.editor_status() else "Staff" elif is_from_swat(user=self.user, ip=self.ip_address): return "Registered, Swarthmore" else: return "Registered, Non-Swarthmore"
def starting_score(self): from_swat = is_from_swat(user=self.user, ip=self.ip_address) directly = self.user and self.user.user.has_perm('comments.can_post_directly') if not self.is_anonymous and directly: return 6 if from_swat else 5 else: return 4 if from_swat else 3
def new(self, check_spam=True, pre_approved=False, **data): """ Makes a new comment, dealing with spam checking and pre-approval as necessary. If spam, raise a CommentIsSpam error, with the unsaved comment in its .comment attribute. This comment is all ready to go; it just needs to be saved, should it be decided that it's not actually spam. Comments from Swarthmore IPs or registered users are not spam-checked. Comments from Swat IPs and non-anonymous users who haven't lost the can_post_directly permission are pre-approved (as per `pre_approved`). """ comment = PublicComment(**data) anon = comment.is_anonymous user = comment.user.user if comment.user else None needs_moderation = user and not user.has_perm('comments.can_post_directly') from_swat = is_from_swat(user=comment.user, ip=comment.ip_address) if needs_moderation or (anon and not from_swat): comment.is_approved = pre_approved else: comment.is_approved = True try: prev = PublicComment.objects.filter(subject_id=comment.subject_id, subject_type=comment.subject_type) comment.number = prev.order_by('-number')[0].number + 1 except IndexError: comment.number = 1 comment.score = comment.starting_score() if check_spam and not from_swat and not user: if comment.check_for_spam(): raise CommentIsSpam(comment) comment.save() return comment
def specific_article(request, story, num=None, form=None, print_view=False): "Displays an article without searching the db for it." logged_in = request.user.is_authenticated() if form is None: initial = { 'text': 'Have your say.' } if logged_in: initial['name'] = request.user.get_full_name() staff = logged_in and get_user_profile(request).staff_status() form = make_comment_form(logged_in=logged_in, initial=initial, staff=staff) if story.is_swat_only(): if not is_from_swat(user=get_user_profile(request), ip=get_ip(request)): return show_swat_only(request, story) try: photospread = story.photospread except PhotoSpread.DoesNotExist: return show_article(request, story, form, print_view) else: return show_photospread_page(request, photospread, num, form)
def specific_article(request, story, num=None, form=None, print_view=False): "Displays an article without searching the db for it." logged_in = request.user.is_authenticated() if form is None: initial = {'text': 'Have your say.'} if logged_in: initial['name'] = request.user.get_full_name() staff = logged_in and get_user_profile(request).staff_status() form = make_comment_form(logged_in=logged_in, initial=initial, staff=staff) if story.is_swat_only(): if not is_from_swat(user=get_user_profile(request), ip=get_ip(request)): return show_swat_only(request, story) try: photospread = story.photospread except PhotoSpread.DoesNotExist: return show_article(request, story, form, print_view) else: return show_photospread_page(request, photospread, num, form)