summaryrefslogtreecommitdiff
path: root/app/posts/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/posts/models.py')
-rw-r--r--app/posts/models.py141
1 files changed, 141 insertions, 0 deletions
diff --git a/app/posts/models.py b/app/posts/models.py
new file mode 100644
index 0000000..a19a50f
--- /dev/null
+++ b/app/posts/models.py
@@ -0,0 +1,141 @@
+from django.db import models
+from django.utils.html import format_html, format_html_join
+from django.utils import timezone
+
+from products.models import ProductLink
+
+"""
+class Feed(models.Model):
+ name = models.CharField(max_length=255)
+ feed_url = models.CharField(max_length=512)
+ slug = models.CharField(max_length=50)
+ last_polled = models.DateTimeField(blank=True, null=True)
+ due_poll = models.DateTimeField(default=datetime.datetime(1900, 1, 1)) # default to distant past to put new sources to front of queue
+ etag = models.CharField(max_length=255, blank=True, null=True)
+ last_modified = models.CharField(max_length=255, blank=True, null=True) # just pass this back and forward between server and me , no need to parse
+ last_result = models.CharField(max_length=255,blank=True,null=True)
+ interval = models.PositiveIntegerField(default=400)
+ last_success = models.DateTimeField(blank=True, null=True)
+ last_change = models.DateTimeField(blank=True, null=True)
+ live = models.BooleanField(default=True)
+ status_code = models.PositiveIntegerField(default=0)
+ last_302_url = models.CharField(max_length=512, null=True, blank=True)
+ last_302_start = models.DateTimeField(null=True, blank=True)
+
+ def __str__(self):
+ return self.name
+"""
+
+
+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 Post(models.Model):
+ # an entry in a feed
+ 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)
+ 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)
+
+ 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 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 ''
+
+ 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:
+ self.needs_update = True
+ else:
+ self.needs_update = False
+ super(Post, self).save()
+
+
+class Note(models.Model):
+ title = models.CharField(max_length=400)
+ url = models.CharField(max_length=400)
+ body_markdown = models.TextField(blank=True, null=True)
+ date_created = models.DateTimeField(default=timezone.now)
+ post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True)
+
+ class Meta:
+ ordering = ('date_created',)
+
+ def __str__(self):
+ return self.title
+
+
+#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),
+ )
+
+'''