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 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 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) 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) 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('%s' % (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() #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 for post in Post.objects.all(): if post.author == "Scott Gilbertson": post.user = user post.save() '''