~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to threadedcomments/management/commands/migratecomments.py

  • Committer: franku
  • Date: 2016-07-02 12:38:06 UTC
  • mfrom: (404.2.56 widelands)
  • Revision ID: somal@arcor.de-20160702123806-q69u3d48s1prrxds
merged the django1_8 branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.core.management.base import BaseCommand
 
2
from django.contrib.comments.models import Comment, FreeComment
 
3
from threadedcomments.models import ThreadedComment, FreeThreadedComment
 
4
 
 
5
class Command(BaseCommand):
 
6
    help = "Migrates Django's built-in django.contrib.comments data to threadedcomments data"
 
7
    
 
8
    output_transaction = True
 
9
    
 
10
    def handle(self, *args, **options):
 
11
        """
 
12
        Converts all legacy ``Comment`` and ``FreeComment`` objects into 
 
13
        ``ThreadedComment`` and ``FreeThreadedComment`` objects, respectively.
 
14
        """
 
15
        self.handle_free_comments()
 
16
        self.handle_comments()
 
17
    
 
18
    def handle_free_comments(self):
 
19
        """
 
20
        Converts all legacy ``FreeComment`` objects into ``FreeThreadedComment``
 
21
        objects.
 
22
        """
 
23
        comments = FreeComment.objects.all()
 
24
        for c in comments:
 
25
            new = FreeThreadedComment(
 
26
                content_type = c.content_type,
 
27
                object_id = c.object_id,
 
28
                comment = c.comment,
 
29
                name = c.person_name,
 
30
                website = '',
 
31
                email = '',
 
32
                date_submitted = c.submit_date,
 
33
                date_modified = c.submit_date,
 
34
                date_approved = c.submit_date,
 
35
                is_public = c.is_public,
 
36
                ip_address = c.ip_address,
 
37
                is_approved = c.approved
 
38
            )
 
39
            new.save()
 
40
    
 
41
    def handle_comments(self):
 
42
        """
 
43
        Converts all legacy ``Comment`` objects into ``ThreadedComment`` objects.
 
44
        """
 
45
        comments = Comment.objects.all()
 
46
        for c in comments:
 
47
            new = ThreadedComment(
 
48
                content_type = c.content_type,
 
49
                object_id = c.object_id,
 
50
                comment = c.comment,
 
51
                user = c.user,
 
52
                date_submitted = c.submit_date,
 
53
                date_modified = c.submit_date,
 
54
                date_approved = c.submit_date,
 
55
                is_public = c.is_public,
 
56
                ip_address = c.ip_address,
 
57
                is_approved = not c.is_removed
 
58
            )
 
59
            new.save()
 
 
b'\\ No newline at end of file'