Advertisement
Guest User

Untitled

a guest
Jul 6th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. class Feed(PolymorphicModel):
  2. active = models.BooleanField(default=True)
  3. feed_code = models.CharField(max_length=60)
  4. feed_delay = models.SmallIntegerField(default=0, validators=[MinValueValidator(-4)])
  5. feed_description = models.CharField(max_length=255, blank=True)
  6. feed_name = models.CharField(max_length=60)
  7. feed_type = models.ForeignKey(FeedType)
  8. partner = models.ForeignKey(Partner)
  9.  
  10. # Schedule Settings
  11. schedule_type = models.CharField(max_length=1, choices=SCHEDULE_TYPE_CHOICES)
  12. # this is stored as minute of the day (so 6:30am is 390)
  13. time_of_day = models.IntegerField("Time", blank=True, null=True, choices=TIME_OF_DAY_CHOICES)
  14.  
  15. class Meta:
  16. verbose_name_plural = 'Feeds'
  17. abstract = True
  18.  
  19. def __unicode__(self):
  20. return u'%s' % self.feed_name
  21.  
  22. def date_is_within_embargo(self, content_date):
  23. """
  24. Pass in a date (possibly an Issue publication date, and get a Boolean
  25. back indicating whether or not this feed is allowed to have the content.
  26.  
  27. If the Content's date + feed_delay < today, return True
  28. """
  29. today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
  30.  
  31. # Compute the most recent possible date, based on this feed's delay
  32. latest_valid_date = content_date + timedelta(days=int(self.feed_delay))
  33.  
  34. # Return whether the requested date is before the latest valid date
  35. if latest_valid_date < today:
  36. return True
  37.  
  38. return False
  39.  
  40. def deliver(self):
  41. raise NotImplementedError('This must be implemented')
  42.  
  43.  
  44. class KirkusHostedFTPFeed(Feed):
  45. username = models.CharField(max_length=24, unique=True)
  46. password = models.CharField(max_length=64)
  47.  
  48. def deliver(self):
  49. pass
  50.  
  51.  
  52. class EmailFeed(Feed):
  53. email_list = models.TextField(blank=True)
  54.  
  55. def deliver(self):
  56. pass
  57.  
  58.  
  59. class ExternalFTPFeed(Feed):
  60. remote_server_name = models.CharField(max_length=100, blank=True)
  61. remote_username = models.CharField(max_length=30, blank=True)
  62. remote_password = models.CharField(max_length=30, blank=True)
  63. remote_path = models.CharField(max_length=200, blank=True)
  64.  
  65. def deliver(self):
  66. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement