~widelands-dev/widelands-website/trunk

« back to all changes in this revision

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

  • Committer: franku
  • Author(s): GunChleoc
  • Date: 2016-12-13 18:30:38 UTC
  • mfrom: (438.1.6 pyformat_util)
  • Revision ID: somal@arcor.de-20161213183038-5cgmvfh2fkgmoc1s
adding a script to run pyformat over the code base

Show diffs side-by-side

added added

removed removed

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