-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupgrade_rating_activity.py
77 lines (66 loc) · 3.73 KB
/
upgrade_rating_activity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'film20.settings'
import datetime
from film20.core.models import Rating
from film20.useractivity.models import UserActivity
from django.contrib.auth.models import User
import datetime
class RatingActivityUpgrade:
def actor_rating_upgrade(self):
users = User.objects.all()
for user in users:
ratings = Rating.objects.filter(user=user, type=3, last_rated__gte=datetime.datetime.now()-datetime.timedelta(hours=24)).exclude(rating__isnull = True)
if len(ratings) != 0:
rated_objects_html = ""
for rating in ratings:
rated_object_html = "<a href=\"/osoba/" + rating.parent.permalink +"\">" + unicode(rating.actor) + " (" + str(rating.rating) + ")</a>,"
rated_objects_html = rated_objects_html + rated_object_html
activity = UserActivity(user = user,
activity_type = UserActivity.TYPE_RATING,
rate_type=UserActivity.TYPE_ACTOR,
rated_objects_count=len(ratings),
rated_objects_html=rated_objects_html)
activity.save()
for rating in ratings:
activity.rated_objects.add(rating)
def director_rating_upgrade(self):
users = User.objects.all()
for user in users:
ratings = Rating.objects.filter(user=user, type=2, last_rated__gte=datetime.datetime.now()-datetime.timedelta(hours=24)).exclude(rating__isnull = True)
if len(ratings) != 0:
rated_objects_html = ""
for rating in ratings:
rated_object_html = "<a href=\"/osoba/" + rating.parent.permalink +"\">" + unicode(rating.director) + " (" + str(rating.rating) + ")</a>,"
rated_objects_html = rated_objects_html + rated_object_html
activity = UserActivity(user = user,
activity_type = UserActivity.TYPE_RATING,
rate_type=UserActivity.TYPE_DIRECTOR,
rated_objects_count=len(ratings),
rated_objects_html=rated_objects_html)
activity.save()
for rating in ratings:
activity.rated_objects.add(rating)
def film_rating_upgrade(self):
users = User.objects.all()
for user in users:
ratings = Rating.objects.filter(user=user, type=1, last_rated__gte=datetime.datetime.now()-datetime.timedelta(hours=24)).exclude(rating__isnull = True)
if len(ratings) != 0:
rated_objects_html = ""
for rating in ratings:
rated_object_html = "<a href=\"/film/" + rating.parent.permalink +"\">" + unicode(rating.film) + " (" + str(rating.rating) + ")</a>,"
rated_objects_html = rated_objects_html + rated_object_html
activity = UserActivity(user = user,
activity_type = UserActivity.TYPE_RATING,
rate_type=UserActivity.TYPE_FILM,
rated_objects_count=len(ratings),
rated_objects_html=rated_objects_html)
activity.save()
for rating in ratings:
activity.rated_objects.add(rating)
def main():
activity = RatingActivityUpgrade()
activity.film_rating_upgrade()
activity.director_rating_upgrade()
activity.actor_rating_upgrade()
if __name__ == "__main__":
main()