Merge lp:~widelands-dev/widelands-website/cleanup_threadedcomments into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 504
Proposed branch: lp:~widelands-dev/widelands-website/cleanup_threadedcomments
Merge into: lp:widelands-website
Diff against target: 894 lines (+72/-519)
12 files modified
pip_requirements.txt (+0/-1)
templates/news/inlines/post_detail.html (+1/-1)
templates/news/post_detail.html (+1/-1)
threadedcomments/admin.py (+2/-18)
threadedcomments/forms.py (+1/-21)
threadedcomments/management/commands/migratecomments.py (+0/-56)
threadedcomments/migrations/0002_auto_20181003_1238.py (+33/-0)
threadedcomments/models.py (+0/-157)
threadedcomments/moderation.py (+3/-4)
threadedcomments/templatetags/threadedcommentstags.py (+16/-162)
threadedcomments/urls.py (+0/-22)
threadedcomments/views.py (+15/-76)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/cleanup_threadedcomments
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+356200@code.launchpad.net

Commit message

Removed model FreeThreadedComments and its dependencies
Remove IP-Adress field from Threadedcomments
Scroll directly to the comments when clicking on 'x comments' in the mainpage

Description of the change

This is a big cleanup for threadedcomments, with regard to bug 1762164

Since we do not allow commenting for not logged in users, i have removed the related model and all it's dependencies. The model does not contain any data, see https://wl.widelands.org/admin/threadedcomments/freethreadedcomment/

Removed the IPAddressField from the other model.

Removed django_comments, because it is not needed.

Clicking on 'x Comments' in the mainpage will directly scroll to the comments section in the related page.

To post a comment you must log in.
508. By kaputtnik

removed more unused functions

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM, just 1 tiny nit - we have an extra indent that we could lose

review: Approve
509. By kaputtnik

unindented a row

Revision history for this message
kaputtnik (franku) wrote :

Will merge this at the next weekend

510. By kaputtnik

merged with trunk

Revision history for this message
kaputtnik (franku) wrote :

merged and deployed now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pip_requirements.txt'
2--- pip_requirements.txt 2018-04-14 15:03:31 +0000
3+++ pip_requirements.txt 2018-10-12 19:57:27 +0000
4@@ -2,7 +2,6 @@
5
6 BeautifulSoup==3.2.0
7 Django==1.11.12
8-django-contrib-comments==1.8.0
9 django-haystack==2.8.1
10 # django-messages is very old on pypi
11 # Do not install newer versions because our notifications app is affected
12
13=== modified file 'templates/news/inlines/post_detail.html'
14--- templates/news/inlines/post_detail.html 2017-05-20 20:17:28 +0000
15+++ templates/news/inlines/post_detail.html 2018-10-12 19:57:27 +0000
16@@ -26,6 +26,6 @@
17
18 <hr />
19 {% get_comment_count for object as ccount %}
20- <span class="small posLeft"><a href="{{ object.get_absolute_url }}">{{ ccount }} comment{{ ccount|pluralize }}</a></span>
21+ <span class="small posLeft"><a href="{{ object.get_absolute_url }}#comment_anchor">{{ ccount }} comment{{ ccount|pluralize }}</a></span>
22 <span class="small posRight">Posted by {{object.author|user_link}} on {{ object.publish|custom_date:user }}</span>
23 </div>
24
25=== modified file 'templates/news/post_detail.html'
26--- templates/news/post_detail.html 2016-11-20 11:55:39 +0000
27+++ templates/news/post_detail.html 2018-10-12 19:57:27 +0000
28@@ -30,7 +30,7 @@
29 {% include "news/inlines/post_detail.html" %}
30
31 <div class="blogEntry">
32- <h3>Comments on this Post:</h3>
33+ <h3 id="comment_anchor">Comments on this Post:</h3>
34 {% include "threadedcomments/inlines/comments.html" %}
35 </div>
36 {% endblock %}
37
38=== modified file 'threadedcomments/admin.py'
39--- threadedcomments/admin.py 2016-12-13 18:28:51 +0000
40+++ threadedcomments/admin.py 2018-10-12 19:57:27 +0000
41@@ -1,6 +1,6 @@
42 from django.contrib import admin
43 from django.utils.translation import ugettext_lazy as _
44-from threadedcomments.models import ThreadedComment, FreeThreadedComment
45+from threadedcomments.models import ThreadedComment
46
47
48 class ThreadedCommentAdmin(admin.ModelAdmin):
49@@ -9,7 +9,7 @@
50 (_('Parent'), {'fields': ('parent',)}),
51 (_('Content'), {'fields': ('user', 'comment')}),
52 (_('Meta'), {'fields': ('is_public', 'date_submitted',
53- 'date_modified', 'date_approved', 'is_approved', 'ip_address')}),
54+ 'date_modified', 'date_approved', 'is_approved')}),
55 )
56 list_display = ('user', 'date_submitted', 'content_type',
57 'get_content_object', 'parent', '__unicode__')
58@@ -18,20 +18,4 @@
59 search_fields = ('comment', 'user__username')
60
61
62-class FreeThreadedCommentAdmin(admin.ModelAdmin):
63- fieldsets = (
64- (None, {'fields': ('content_type', 'object_id')}),
65- (_('Parent'), {'fields': ('parent',)}),
66- (_('Content'), {'fields': ('name', 'website', 'email', 'comment')}),
67- (_('Meta'), {'fields': ('date_submitted', 'date_modified',
68- 'date_approved', 'is_public', 'ip_address', 'is_approved')}),
69- )
70- list_display = ('name', 'date_submitted', 'content_type',
71- 'get_content_object', 'parent', '__unicode__')
72- list_filter = ('date_submitted',)
73- date_hierarchy = 'date_submitted'
74- search_fields = ('comment', 'name', 'email', 'website')
75-
76-
77 admin.site.register(ThreadedComment, ThreadedCommentAdmin)
78-admin.site.register(FreeThreadedComment, FreeThreadedCommentAdmin)
79
80=== modified file 'threadedcomments/forms.py'
81--- threadedcomments/forms.py 2016-12-13 18:28:51 +0000
82+++ threadedcomments/forms.py 2018-10-12 19:57:27 +0000
83@@ -1,6 +1,6 @@
84 from django import forms
85 from threadedcomments.models import DEFAULT_MAX_COMMENT_LENGTH
86-from threadedcomments.models import FreeThreadedComment, ThreadedComment
87+from threadedcomments.models import ThreadedComment
88 from django.utils.translation import ugettext_lazy as _
89
90
91@@ -21,23 +21,3 @@
92 class Meta:
93 model = ThreadedComment
94 fields = ('comment', 'markup')
95-
96-
97-class FreeThreadedCommentForm(forms.ModelForm):
98- """
99- Form which can be used to validate data for a new FreeThreadedComment.
100- It consists of just a few fields: ``comment``, ``name``, ``website``,
101- ``email``, and ``markup``.
102-
103- The fields ``comment``, and ``name`` are the only ones which are required.
104- """
105-
106- comment = forms.CharField(
107- label=_('comment'),
108- max_length=DEFAULT_MAX_COMMENT_LENGTH,
109- widget=forms.Textarea
110- )
111-
112- class Meta:
113- model = FreeThreadedComment
114- fields = ('comment', 'name', 'website', 'email', 'markup')
115
116=== removed directory 'threadedcomments/management'
117=== removed file 'threadedcomments/management/__init__.py'
118=== removed directory 'threadedcomments/management/commands'
119=== removed file 'threadedcomments/management/commands/__init__.py'
120=== removed file 'threadedcomments/management/commands/migratecomments.py'
121--- threadedcomments/management/commands/migratecomments.py 2016-12-13 18:28:51 +0000
122+++ threadedcomments/management/commands/migratecomments.py 1970-01-01 00:00:00 +0000
123@@ -1,56 +0,0 @@
124-from django.core.management.base import BaseCommand
125-from django.contrib.comments.models import Comment, FreeComment
126-from threadedcomments.models import ThreadedComment, FreeThreadedComment
127-
128-
129-class Command(BaseCommand):
130- help = "Migrates Django's built-in django.contrib.comments data to threadedcomments data"
131-
132- output_transaction = True
133-
134- def handle(self, *args, **options):
135- """Converts all legacy ``Comment`` and ``FreeComment`` objects into
136- ``ThreadedComment`` and ``FreeThreadedComment`` objects,
137- respectively."""
138- self.handle_free_comments()
139- self.handle_comments()
140-
141- def handle_free_comments(self):
142- """Converts all legacy ``FreeComment`` objects into
143- ``FreeThreadedComment`` objects."""
144- comments = FreeComment.objects.all()
145- for c in comments:
146- new = FreeThreadedComment(
147- content_type=c.content_type,
148- object_id=c.object_id,
149- comment=c.comment,
150- name=c.person_name,
151- website='',
152- email='',
153- date_submitted=c.submit_date,
154- date_modified=c.submit_date,
155- date_approved=c.submit_date,
156- is_public=c.is_public,
157- ip_address=c.ip_address,
158- is_approved=c.approved
159- )
160- new.save()
161-
162- def handle_comments(self):
163- """Converts all legacy ``Comment`` objects into ``ThreadedComment``
164- objects."""
165- comments = Comment.objects.all()
166- for c in comments:
167- new = ThreadedComment(
168- content_type=c.content_type,
169- object_id=c.object_id,
170- comment=c.comment,
171- user=c.user,
172- date_submitted=c.submit_date,
173- date_modified=c.submit_date,
174- date_approved=c.submit_date,
175- is_public=c.is_public,
176- ip_address=c.ip_address,
177- is_approved=not c.is_removed
178- )
179- new.save()
180
181=== added file 'threadedcomments/migrations/0002_auto_20181003_1238.py'
182--- threadedcomments/migrations/0002_auto_20181003_1238.py 1970-01-01 00:00:00 +0000
183+++ threadedcomments/migrations/0002_auto_20181003_1238.py 2018-10-12 19:57:27 +0000
184@@ -0,0 +1,33 @@
185+# -*- coding: utf-8 -*-
186+# Generated by Django 1.11.12 on 2018-10-03 12:38
187+from __future__ import unicode_literals
188+
189+from django.db import migrations
190+
191+
192+class Migration(migrations.Migration):
193+
194+ dependencies = [
195+ ('threadedcomments', '0001_initial'),
196+ ]
197+
198+ operations = [
199+ migrations.RemoveField(
200+ model_name='freethreadedcomment',
201+ name='content_type',
202+ ),
203+ migrations.RemoveField(
204+ model_name='freethreadedcomment',
205+ name='parent',
206+ ),
207+ migrations.DeleteModel(
208+ name='TestModel',
209+ ),
210+ migrations.RemoveField(
211+ model_name='threadedcomment',
212+ name='ip_address',
213+ ),
214+ migrations.DeleteModel(
215+ name='FreeThreadedComment',
216+ ),
217+ ]
218
219=== modified file 'threadedcomments/models.py'
220--- threadedcomments/models.py 2016-12-13 18:28:51 +0000
221+++ threadedcomments/models.py 2018-10-12 19:57:27 +0000
222@@ -1,6 +1,5 @@
223 from django.db import models
224 from django.contrib.contenttypes.models import ContentType
225-#from django.contrib.contenttypes import generic
226 from django.contrib.contenttypes.fields import GenericForeignKey
227 from django.contrib.auth.models import User
228 from datetime import datetime
229@@ -16,13 +15,11 @@
230 MARKDOWN = 1
231 TEXTILE = 2
232 REST = 3
233-#HTML = 4
234 PLAINTEXT = 5
235 MARKUP_CHOICES = (
236 (MARKDOWN, _('markdown')),
237 (TEXTILE, _('textile')),
238 (REST, _('restructuredtext')),
239- # (HTML, _("html")),
240 (PLAINTEXT, _('plaintext')),
241 )
242
243@@ -178,10 +175,6 @@
244 is_public = models.BooleanField(_('is public'), default=True)
245 is_approved = models.BooleanField(_('is approved'), default=False)
246
247- # Extra Field
248- ip_address = models.GenericIPAddressField(
249- _('IP address'), null=True, blank=True)
250-
251 objects = ThreadedCommentManager()
252 public = PublicThreadedCommentManager()
253
254@@ -203,158 +196,8 @@
255 and due to ``list_display`` limitations."""
256 return self.content_object
257
258- def get_base_data(self, show_dates=True):
259- """Outputs a Python dictionary representing the most useful bits of
260- information about this particular object instance.
261-
262- This is mostly useful for testing purposes, as the output from
263- the serializer changes from run to run. However, this may end
264- up being useful for JSON and/or XML data exchange going forward
265- and as the serializer system is changed.
266-
267- """
268- markup = 'plaintext'
269- for markup_choice in MARKUP_CHOICES:
270- if self.markup == markup_choice[0]:
271- markup = markup_choice[1]
272- break
273- to_return = {
274- 'content_object': self.content_object,
275- 'parent': self.parent,
276- 'user': self.user,
277- 'comment': self.comment,
278- 'is_public': self.is_public,
279- 'is_approved': self.is_approved,
280- 'ip_address': self.ip_address,
281- 'markup': force_unicode(markup),
282- }
283- if show_dates:
284- to_return['date_submitted'] = self.date_submitted
285- to_return['date_modified'] = self.date_modified
286- to_return['date_approved'] = self.date_approved
287- return to_return
288-
289 class Meta:
290 ordering = ('-date_submitted',)
291 verbose_name = _('Threaded Comment')
292 verbose_name_plural = _('Threaded Comments')
293 get_latest_by = 'date_submitted'
294-
295-
296-class FreeThreadedComment(models.Model):
297- """
298- A threaded comment which need not be associated with an instance of
299- ``django.contrib.auth.models.User``. Instead, it requires minimally a name,
300- and maximally a name, website, and e-mail address. It is given its hierarchy
301- by a nullable relationship back on itself named ``parent``.
302-
303- This ``FreeThreadedComment`` supports several kinds of markup languages,
304- including Textile, Markdown, and ReST.
305-
306- It also includes two Managers: ``objects``, which is the same as the normal
307- ``objects`` Manager with a few added utility functions (see above), and
308- ``public``, which has those same utility functions but limits the QuerySet to
309- only those values which are designated as public (``is_public=True``).
310- """
311- # Generic Foreign Key Fields
312- content_type = models.ForeignKey(ContentType)
313- object_id = models.PositiveIntegerField(_('object ID'))
314- content_object = GenericForeignKey()
315-
316- # Hierarchy Field
317- parent = models.ForeignKey(
318- 'self', null=True, blank=True, default=None, related_name='children')
319-
320- # User-Replacement Fields
321- name = models.CharField(_('name'), max_length=128)
322- website = models.URLField(_('site'), blank=True)
323- email = models.EmailField(_('e-mail address'), blank=True)
324-
325- # Date Fields
326- date_submitted = models.DateTimeField(
327- _('date/time submitted'), default=datetime.now)
328- date_modified = models.DateTimeField(
329- _('date/time modified'), default=datetime.now)
330- date_approved = models.DateTimeField(
331- _('date/time approved'), default=None, null=True, blank=True)
332-
333- # Meat n' Potatoes
334- comment = models.TextField(_('comment'))
335- markup = models.IntegerField(
336- choices=MARKUP_CHOICES, default=DEFAULT_MARKUP, null=True, blank=True)
337-
338- # Status Fields
339- is_public = models.BooleanField(_('is public'), default=True)
340- is_approved = models.BooleanField(_('is approved'), default=False)
341-
342- # Extra Field
343- ip_address = models.GenericIPAddressField(
344- _('IP address'), null=True, blank=True)
345-
346- objects = ThreadedCommentManager()
347- public = PublicThreadedCommentManager()
348-
349- def __unicode__(self):
350- if len(self.comment) > 50:
351- return self.comment[:50] + '...'
352- return self.comment[:50]
353-
354- def save(self, **kwargs):
355- if not self.markup:
356- self.markup = DEFAULT_MARKUP
357- self.date_modified = datetime.now()
358- if not self.date_approved and self.is_approved:
359- self.date_approved = datetime.now()
360- super(FreeThreadedComment, self).save()
361-
362- def get_content_object(self, **kwargs):
363- """Wrapper around the GenericForeignKey due to compatibility reasons
364- and due to ``list_display`` limitations."""
365- return self.content_object
366-
367- def get_base_data(self, show_dates=True):
368- """Outputs a Python dictionary representing the most useful bits of
369- information about this particular object instance.
370-
371- This is mostly useful for testing purposes, as the output from
372- the serializer changes from run to run. However, this may end
373- up being useful for JSON and/or XML data exchange going forward
374- and as the serializer system is changed.
375-
376- """
377- markup = 'plaintext'
378- for markup_choice in MARKUP_CHOICES:
379- if self.markup == markup_choice[0]:
380- markup = markup_choice[1]
381- break
382- to_return = {
383- 'content_object': self.content_object,
384- 'parent': self.parent,
385- 'name': self.name,
386- 'website': self.website,
387- 'email': self.email,
388- 'comment': self.comment,
389- 'is_public': self.is_public,
390- 'is_approved': self.is_approved,
391- 'ip_address': self.ip_address,
392- 'markup': force_unicode(markup),
393- }
394- if show_dates:
395- to_return['date_submitted'] = self.date_submitted
396- to_return['date_modified'] = self.date_modified
397- to_return['date_approved'] = self.date_approved
398- return to_return
399-
400- class Meta:
401- ordering = ('-date_submitted',)
402- verbose_name = _('Free Threaded Comment')
403- verbose_name_plural = _('Free Threaded Comments')
404- get_latest_by = 'date_submitted'
405-
406-
407-class TestModel(models.Model):
408- """This model is simply used by this application's test suite as a model to
409- which to attach comments."""
410- name = models.CharField(max_length=5)
411- is_public = models.BooleanField(default=True)
412- date = models.DateTimeField(default=datetime.now)
413
414=== modified file 'threadedcomments/moderation.py'
415--- threadedcomments/moderation.py 2016-12-13 18:28:51 +0000
416+++ threadedcomments/moderation.py 2018-10-12 19:57:27 +0000
417@@ -1,5 +1,5 @@
418 from django.db.models import signals
419-from threadedcomments.models import ThreadedComment, FreeThreadedComment, MARKUP_CHOICES
420+from threadedcomments.models import ThreadedComment, MARKUP_CHOICES
421 from threadedcomments.models import DEFAULT_MAX_COMMENT_LENGTH, DEFAULT_MAX_COMMENT_DEPTH
422 from comment_utils import moderation
423
424@@ -37,9 +37,8 @@
425 class Moderator(moderation.Moderator):
426
427 def connect(self):
428- for model in (ThreadedComment, FreeThreadedComment):
429- signals.pre_save.connect(self.pre_save_moderation, sender=model)
430- signals.post_save.connect(self.post_save_moderation, sender=model)
431+ signals.pre_save.connect(self.pre_save_moderation, sender=ThreadedComment)
432+ signals.post_save.connect(self.post_save_moderation, sender=ThreadedComment)
433
434 # THE FOLLOWING ARE HACKS UNTIL django-comment-utils GETS UPDATED SIGNALS
435 # ####
436
437=== modified file 'threadedcomments/templatetags/threadedcommentstags.py'
438--- threadedcomments/templatetags/threadedcommentstags.py 2018-04-08 14:40:17 +0000
439+++ threadedcomments/templatetags/threadedcommentstags.py 2018-10-12 19:57:27 +0000
440@@ -4,8 +4,8 @@
441 from django.urls import reverse
442 from django.utils.encoding import force_unicode
443 from django.utils.safestring import mark_safe
444-from threadedcomments.models import ThreadedComment, FreeThreadedComment
445-from threadedcomments.forms import ThreadedCommentForm, FreeThreadedCommentForm
446+from threadedcomments.models import ThreadedComment
447+from threadedcomments.forms import ThreadedCommentForm
448 from mainpage.templatetags.wl_markdown import do_wl_markdown
449
450 # Regular expressions for getting rid of newlines and witespace
451@@ -78,64 +78,8 @@
452 return ''
453
454
455-def get_free_comment_url(content_object, parent=None):
456- """Given an object and an optional parent, this tag gets the URL to POST to
457- for the creation of new ``FreeThreadedComment`` objects."""
458- kwargs = get_contenttype_kwargs(content_object)
459- if parent:
460- if not isinstance(parent, FreeThreadedComment):
461- raise template.TemplateSyntaxError, 'get_free_comment_url requires its parent object to be of type FreeThreadedComment'
462- kwargs.update({'parent_id': getattr(
463- parent, 'pk', getattr(parent, 'id'))})
464- return reverse('tc_free_comment_parent', kwargs=kwargs)
465- else:
466- return reverse('tc_free_comment', kwargs=kwargs)
467-
468-
469-def get_free_comment_url_ajax(content_object, parent=None, ajax_type='json'):
470- """Given an object and an optional parent, this tag gets the URL to POST to
471- for the creation of new ``FreeThreadedComment`` objects.
472-
473- It returns the latest created object in the AJAX form of the user's
474- choosing (json or xml).
475-
476- """
477- kwargs = get_contenttype_kwargs(content_object)
478- kwargs.update({'ajax': ajax_type})
479- if parent:
480- if not isinstance(parent, FreeThreadedComment):
481- raise template.TemplateSyntaxError, 'get_free_comment_url_ajax requires its parent object to be of type FreeThreadedComment'
482- kwargs.update({'parent_id': getattr(
483- parent, 'pk', getattr(parent, 'id'))})
484- return reverse('tc_free_comment_parent_ajax', kwargs=kwargs)
485- else:
486- return reverse('tc_free_comment_ajax', kwargs=kwargs)
487-
488-
489-def get_free_comment_url_json(content_object, parent=None):
490- """
491- Wraps ``get_free_comment_url_ajax`` with ``ajax_type='json'``
492- """
493- try:
494- return get_free_comment_url_ajax(content_object, parent, ajax_type='json')
495- except template.TemplateSyntaxError:
496- raise template.TemplateSyntaxError, 'get_free_comment_url_json requires its parent object to be of type FreeThreadedComment'
497- return ''
498-
499-
500-def get_free_comment_url_xml(content_object, parent=None):
501- """
502- Wraps ``get_free_comment_url_ajax`` with ``ajax_type='xml'``
503- """
504- try:
505- return get_free_comment_url_ajax(content_object, parent, ajax_type='xml')
506- except template.TemplateSyntaxError:
507- raise template.TemplateSyntaxError, 'get_free_comment_url_xml requires its parent object to be of type FreeThreadedComment'
508- return ''
509-
510-
511 def auto_transform_markup(comment):
512- """Given a comment (``ThreadedComment`` or ``FreeThreadedComment``), this
513+ """Given a comment, this
514 tag simply returns the comment after wl_markdown runs over it.
515
516 """
517@@ -190,24 +134,6 @@
518 raise template.TemplateSyntaxError(error_string)
519
520
521-def do_get_free_threaded_comment_tree(parser, token):
522- """Gets a tree (list of objects ordered by traversing tree in preorder, and
523- with an additional ``depth`` integer attribute annotated onto each
524- ``FreeThreadedComment.``"""
525- error_string = '%r tag must be of format {%% get_free_threaded_comment_tree for OBJECT [TREE_ROOT] as CONTEXT_VARIABLE %%}' % token.contents.split()[
526- 0]
527- try:
528- split = token.split_contents()
529- except ValueError:
530- raise template.TemplateSyntaxError(error_string)
531- if len(split) == 5:
532- return FreeCommentTreeNode(split[2], split[4], split[3])
533- elif len(split) == 6:
534- return FreeCommentTreeNode(split[2], split[5], split[3])
535- else:
536- raise template.TemplateSyntaxError(error_string)
537-
538-
539 class CommentTreeNode(template.Node):
540
541 def __init__(self, content_object, context_name, tree_root):
542@@ -233,31 +159,6 @@
543 return ''
544
545
546-class FreeCommentTreeNode(template.Node):
547-
548- def __init__(self, content_object, context_name, tree_root):
549- self.content_object = template.Variable(content_object)
550- self.tree_root = template.Variable(tree_root)
551- self.tree_root_str = tree_root
552- self.context_name = context_name
553-
554- def render(self, context):
555- content_object = self.content_object.resolve(context)
556- try:
557- tree_root = self.tree_root.resolve(context)
558- except template.VariableDoesNotExist:
559- if self.tree_root_str == 'as':
560- tree_root = None
561- else:
562- try:
563- tree_root = int(self.tree_root_str)
564- except ValueError:
565- tree_root = self.tree_root_str
566- context[self.context_name] = FreeThreadedComment.public.get_tree(
567- content_object, root=tree_root)
568- return ''
569-
570-
571 def do_get_comment_count(parser, token):
572 """Gets a count of how many ThreadedComment objects are attached to the
573 given object."""
574@@ -285,33 +186,6 @@
575 return ''
576
577
578-def do_get_free_comment_count(parser, token):
579- """Gets a count of how many FreeThreadedComment objects are attached to the
580- given object."""
581- error_message = '%r tag must be of format {%% %r for OBJECT as CONTEXT_VARIABLE %%}' % (
582- token.contents.split()[0], token.contents.split()[0])
583- try:
584- split = token.split_contents()
585- except ValueError:
586- raise template.TemplateSyntaxError, error_message
587- if split[1] != 'for' or split[3] != 'as':
588- raise template.TemplateSyntaxError, error_message
589- return FreeThreadedCommentCountNode(split[2], split[4])
590-
591-
592-class FreeThreadedCommentCountNode(template.Node):
593-
594- def __init__(self, content_object, context_name):
595- self.content_object = template.Variable(content_object)
596- self.context_name = context_name
597-
598- def render(self, context):
599- content_object = self.content_object.resolve(context)
600- context[self.context_name] = FreeThreadedComment.public.all_for_object(
601- content_object).count()
602- return ''
603-
604-
605 def oneline(value):
606 """Takes some HTML and gets rid of newlines and spaces between tags,
607 rendering the result all on one line."""
608@@ -322,7 +196,7 @@
609
610
611 def do_get_threaded_comment_form(parser, token):
612- """Gets a FreeThreadedCommentForm and inserts it into the context."""
613+ """Gets a ThreadedCommentForm and inserts it into the context."""
614 error_message = '%r tag must be of format {%% %r as CONTEXT_VARIABLE %%}' % (
615 token.contents.split()[0], token.contents.split()[0])
616 try:
617@@ -333,24 +207,18 @@
618 raise template.TemplateSyntaxError, error_message
619 if len(split) != 3:
620 raise template.TemplateSyntaxError, error_message
621- if 'free' in split[0]:
622- is_free = True
623- else:
624- is_free = False
625- return ThreadedCommentFormNode(split[2], free=is_free)
626+
627+ return ThreadedCommentFormNode(split[2])
628
629
630 class ThreadedCommentFormNode(template.Node):
631
632- def __init__(self, context_name, free=False):
633+ def __init__(self, context_name):
634 self.context_name = context_name
635- self.free = free
636+
637
638 def render(self, context):
639- if self.free:
640- form = FreeThreadedCommentForm()
641- else:
642- form = ThreadedCommentForm()
643+ form = ThreadedCommentForm()
644 context[self.context_name] = form
645 return ''
646
647@@ -367,26 +235,18 @@
648 raise template.TemplateSyntaxError, error_message
649 if split[2] != 'as':
650 raise template.TemplateSyntaxError, error_message
651- if 'free' in split[0]:
652- is_free = True
653- else:
654- is_free = False
655- return LatestCommentsNode(split[1], split[3], free=is_free)
656+
657+ return LatestCommentsNode(split[1], split[3])
658
659
660 class LatestCommentsNode(template.Node):
661
662- def __init__(self, num, context_name, free=False):
663+ def __init__(self, num, context_name):
664 self.num = num
665 self.context_name = context_name
666- self.free = free
667
668 def render(self, context):
669- if self.free:
670- comments = FreeThreadedComment.objects.order_by(
671- '-date_submitted')[:self.num]
672- else:
673- comments = ThreadedComment.objects.order_by(
674+ comments = ThreadedComment.objects.order_by(
675 '-date_submitted')[:self.num]
676 context[self.context_name] = comments
677 return ''
678@@ -402,6 +262,7 @@
679 raise template.TemplateSyntaxError, error_message
680 if len(split) != 5:
681 raise template.TemplateSyntaxError, error_message
682+
683 return UserCommentsNode(split[2], split[4])
684
685
686@@ -427,6 +288,7 @@
687 raise template.TemplateSyntaxError, error_message
688 if len(split) != 5:
689 raise template.TemplateSyntaxError, error_message
690+
691 return UserCommentCountNode(split[2], split[4])
692
693
694@@ -445,21 +307,13 @@
695 register.simple_tag(get_comment_url)
696 register.simple_tag(get_comment_url_json)
697 register.simple_tag(get_comment_url_xml)
698-register.simple_tag(get_free_comment_url)
699-register.simple_tag(get_free_comment_url_json)
700-register.simple_tag(get_free_comment_url_xml)
701
702 register.filter('oneline', oneline)
703
704 register.tag('auto_transform_markup', do_auto_transform_markup)
705+register.tag('get_comment_count', do_get_comment_count)
706 register.tag('get_threaded_comment_tree', do_get_threaded_comment_tree)
707-register.tag('get_free_threaded_comment_tree',
708- do_get_free_threaded_comment_tree)
709-register.tag('get_comment_count', do_get_comment_count)
710-register.tag('get_free_comment_count', do_get_free_comment_count)
711-register.tag('get_free_threaded_comment_form', do_get_threaded_comment_form)
712 register.tag('get_threaded_comment_form', do_get_threaded_comment_form)
713 register.tag('get_latest_comments', do_get_latest_comments)
714-register.tag('get_latest_free_comments', do_get_latest_comments)
715 register.tag('get_user_comments', do_get_user_comments)
716 register.tag('get_user_comment_count', do_get_user_comment_count)
717
718=== modified file 'threadedcomments/urls.py'
719--- threadedcomments/urls.py 2016-12-13 18:28:51 +0000
720+++ threadedcomments/urls.py 2018-10-12 19:57:27 +0000
721@@ -1,8 +1,6 @@
722 from django.conf.urls import url
723-from threadedcomments.models import FreeThreadedComment
724 from threadedcomments import views
725
726-free = {'model': FreeThreadedComment}
727
728 urlpatterns = [
729 ### Comments ###
730@@ -10,8 +8,6 @@
731 views.comment, name='tc_comment'),
732 url(r'^comment/(?P<content_type>\d+)/(?P<object_id>\d+)/(?P<parent_id>\d+)/$',
733 views.comment, name='tc_comment_parent'),
734- url(r'^comment/(?P<object_id>\d+)/delete/$',
735- views.comment_delete, name='tc_comment_delete'),
736 url(r'^comment/(?P<edit_id>\d+)/edit/$',
737 views.comment, name='tc_comment_edit'),
738
739@@ -22,22 +18,4 @@
740 views.comment, name='tc_comment_parent_ajax'),
741 url(r'^comment/(?P<edit_id>\d+)/edit/(?P<ajax>json|xml)/$',
742 views.comment, name='tc_comment_edit_ajax'),
743-
744- ### Free Comments ###
745- url(r'^freecomment/(?P<content_type>\d+)/(?P<object_id>\d+)/$',
746- views.free_comment, name='tc_free_comment'),
747- url(r'^freecomment/(?P<content_type>\d+)/(?P<object_id>\d+)/(?P<parent_id>\d+)/$',
748- views.free_comment, name='tc_free_comment_parent'),
749- url(r'^freecomment/(?P<object_id>\d+)/delete/$',
750- views.comment_delete, free, name='tc_free_comment_delete'),
751- url(r'^freecomment/(?P<edit_id>\d+)/edit/$',
752- views.free_comment, name='tc_free_comment_edit'),
753-
754- ### Free Comments (AJAX) ###
755- url(r'^freecomment/(?P<content_type>\d+)/(?P<object_id>\d+)/(?P<ajax>json|xml)/$',
756- views.free_comment, name='tc_free_comment_ajax'),
757- url(r'^freecomment/(?P<content_type>\d+)/(?P<object_id>\d+)/(?P<parent_id>\d+)/(?P<ajax>json|xml)/$',
758- views.free_comment, name='tc_free_comment_parent_ajax'),
759- url(r'^freecomment/(?P<edit_id>\d+)/edit/(?P<ajax>json|xml)/$',
760- views.free_comment, name='tc_free_comment_edit_ajax'),
761 ]
762
763=== modified file 'threadedcomments/views.py'
764--- threadedcomments/views.py 2018-04-05 07:30:42 +0000
765+++ threadedcomments/views.py 2018-10-12 19:57:27 +0000
766@@ -5,8 +5,8 @@
767 from django.template import RequestContext, Context, Template
768 from django.utils.http import urlquote
769 from django.conf import settings
770-from threadedcomments.forms import FreeThreadedCommentForm, ThreadedCommentForm
771-from threadedcomments.models import ThreadedComment, FreeThreadedComment, DEFAULT_MAX_COMMENT_LENGTH
772+from threadedcomments.forms import ThreadedCommentForm
773+from threadedcomments.models import ThreadedComment, DEFAULT_MAX_COMMENT_LENGTH
774 from threadedcomments.utils import JSONResponse, XMLResponse
775 from wl_utils import get_real_ip
776
777@@ -59,10 +59,10 @@
778 )
779
780
781-def free_comment(request, content_type=None, object_id=None, edit_id=None, parent_id=None, add_messages=False, ajax=False, model=FreeThreadedComment, form_class=FreeThreadedCommentForm, context_processors=[], extra_context={}):
782- """Receives POST data and either creates a new ``ThreadedComment`` or
783- ``FreeThreadedComment``, or edits an old one based upon the specified
784- parameters.
785+@login_required
786+def comment(request, content_type=None, object_id=None, edit_id=None, parent_id=None, add_messages=False, ajax=False, context_processors=[], extra_context={}):
787+ """Receives POST data and creates a new ``ThreadedComment``, or
788+ edits an old one based upon the specified parameters.
789
790 If there is a 'preview' key in the POST request, a preview will be forced and the
791 comment will not be saved until a 'preview' key is no longer in the POST request.
792@@ -74,6 +74,8 @@
793 where the comment may be edited until it does not contain errors.
794
795 """
796+ form_class = ThreadedCommentForm
797+ model = ThreadedComment
798 if not edit_id and not (content_type and object_id):
799 raise Http404 # Must specify either content_type and object_id or edit_id
800 if 'preview' in request.POST:
801@@ -87,25 +89,19 @@
802 if form.is_valid():
803 new_comment = form.save(commit=False)
804 if not edit_id:
805- new_comment.ip_address = get_real_ip(request)
806 new_comment.content_type = get_object_or_404(
807 ContentType, id=int(content_type))
808 new_comment.object_id = int(object_id)
809- if model == ThreadedComment:
810- new_comment.user = request.user
811+
812+ new_comment.user = request.user
813+
814 if parent_id:
815 new_comment.parent = get_object_or_404(model, id=int(parent_id))
816 new_comment.save()
817- if model == ThreadedComment:
818- if add_messages:
819- request.user.message_set.create(
820- message='Your message has been posted successfully.')
821- else:
822- request.session['successful_data'] = {
823- 'name': form.cleaned_data['name'],
824- 'website': form.cleaned_data['website'],
825- 'email': form.cleaned_data['email'],
826- }
827+ if add_messages:
828+ request.user.message_set.create(
829+ message='Your message has been posted successfully.')
830+
831 if ajax == 'json':
832 return JSONResponse([new_comment, ])
833 elif ajax == 'xml':
834@@ -129,60 +125,3 @@
835 return XMLResponse(response_str, is_iterable=False)
836 else:
837 return _preview(request, context_processors, extra_context, form_class=form_class)
838-
839-
840-def comment(*args, **kwargs):
841- """Thin wrapper around free_comment which adds login_required status and
842- also assigns the ``model`` to be ``ThreadedComment``."""
843- kwargs['model'] = ThreadedComment
844- kwargs['form_class'] = ThreadedCommentForm
845- return free_comment(*args, **kwargs)
846-# Require login to be required, as request.user must exist and be valid.
847-comment = login_required(comment)
848-
849-
850-def can_delete_comment(comment, user):
851- """Default callback function to determine wether the given user has the
852- ability to delete the given comment."""
853- if user.is_staff or user.is_superuser:
854- return True
855- if hasattr(comment, 'user') and comment.user == user:
856- return True
857- return False
858-
859-# Todo: Next one is not used so far and may need adjustments to the render()
860-def comment_delete(request, object_id, model=ThreadedComment, extra_context={}, context_processors=[], permission_callback=can_delete_comment):
861- """Deletes the specified comment, which can be either a
862- ``FreeThreadedComment`` or a ``ThreadedComment``.
863-
864- If it is a POST request, then the comment will be deleted outright,
865- however, if it is a GET request, a confirmation page will be shown.
866-
867- """
868- tc = get_object_or_404(model, id=int(object_id))
869- if not permission_callback(tc, request.user):
870- login_url = settings.LOGIN_URL
871- current_url = urlquote(request.get_full_path())
872- return HttpResponseRedirect('%s?next=%s' % (login_url, current_url))
873- if request.method == 'POST':
874- tc.delete()
875- return HttpResponseRedirect(_get_next(request))
876- else:
877- if model == ThreadedComment:
878- is_free_threaded_comment = False
879- is_threaded_comment = True
880- else:
881- is_free_threaded_comment = True
882- is_threaded_comment = False
883-
884- extra_context.update(
885- {'comment': tc,
886- 'is_free_threaded_comment': is_free_threaded_comment,
887- 'is_threaded_comment': is_threaded_comment,
888- 'next': _get_next(request),
889- }
890- )
891- return render(request,
892- 'threadedcomments/confirm_delete.html',
893- extra_context,
894- )

Subscribers

People subscribed via source and target branches