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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
from django.db import models
from django.urls import reverse
from django.utils.html import format_html, format_html_join
from django.utils import timezone
import settings
from products.models import ProductLink
class PostType(models.IntegerChoices):
REVIEW = 0, ('review')
GUIDE = 1, ('guide')
HOWTO = 2, ('how-to')
class TemplateType(models.IntegerChoices):
STORY = 0, ('story')
GALLERY = 1, ('gallery')
class PostStatus(models.IntegerChoices):
ASSIGNED = 0, ('Assigned')
TURNEDIN = 1, ('turned in')
PUBLISHED = 2, ('published')
class Post(models.Model):
# an entry in a feed
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL)
title = models.CharField(max_length=512, blank=True, null=True)
body = models.TextField(blank=True, null=True)
url = models.CharField(max_length=512, blank=True, null=True)
edit_url = models.CharField(max_length=512, blank=True, null=True)
date_last_pub = models.DateField()
guid = models.CharField(max_length=512, blank=True, null=True, db_index=True)
author = models.CharField(max_length=255, blank=True, null=True)
post_type = models.IntegerField(choices=PostType.choices, default=PostType.GUIDE)
template_type = models.IntegerField(choices=TemplateType.choices, default=TemplateType.STORY)
update_frequency = models.BigIntegerField(help_text="In days")
products = models.ManyToManyField(ProductLink, blank=True, null=True)
needs_update = models.BooleanField(default=False)
is_live = models.BooleanField(default=True)
post_status = models.IntegerField(choices=PostStatus.choices, default=PostStatus.PUBLISHED)
class Meta:
ordering = ('date_last_pub',)
def __str__(self):
return self.title
def time_since_update(self):
td = timezone.localdate() - self.date_last_pub
return int(td.days)
#def get_needs_update(self):
# if self.time_since_update() > self.update_frequency:
# return True
# else:
# return False
def days_overdue(self):
if self.needs_update == True:
return self.time_since_update() - self.update_frequency
else:
return 0
def admin_url(self):
return format_html('<a target="_blank" href="%s">%s</a>' % (self.url, self.url))
admin_link.short_description = 'Link'
def save(self, *args, **kwargs):
td = timezone.localdate() - self.date_last_pub
if td.days > self.update_frequency and self.post_status != 1:
self.needs_update = True
else:
self.needs_update = False
super(Post, self).save()
#URL,This Article,Type,Lead,Previous Leads,Other Testers,Notes/Docs,Last Pub Date,Update Next,Months Since Update,Update Frequency (Months),Updates per year,Prev. Updates,"18 Mo Traffic Trend
'''
row[0] #url
row[1] #title
row[2] #post_type
row[3] #author
row[7] #date_last_pub
row[10] #update_frequency
with open(path) as f:
reader = csv.reader(f)
count = 0
for row in reader:
if count > 1:
if row[2] == "Deals":
# don't care about deals posts
continue
elif row[2] == "Buying Guide":
gtype = PostType.GUIDE
else:
gtype = PostType.HOWTO
if row[10] == "Retired":
continue
else:
print(int(row[10]))
print(gtype)
d = datetime.strptime(row[7], '%m/%d/%Y')
post, created = Post.objects.get_or_create(
title = str(row[1]).strip(),
url = str(row[0]).strip(),
date_last_pub = d,
author = str(row[3]).strip(),
post_type = gtype,
update_frequency = int(row[10]*30),
)
user = User.objects.get(username="luxagraf")
user
<User: luxagraf>
for post in Post.objects.all():
if post.author == "Scott Gilbertson":
post.user = user
post.save()
'''
|