+
+
+class Site(models.Model):
+ name = models.CharField(max_length=255)
+ site_type = models.CharField(max_length=32, choices=[
+ ('legimi', 'Legimi'),
+ ('woblink', 'Woblink'),
+ ])
+ username = models.CharField(max_length=255)
+ password = models.CharField(max_length=255)
+ publisher_handle = models.CharField(max_length=255, blank=True)
+ description_add = models.TextField(blank=True)
+
+ def __str__(self):
+ return self.name
+
+ def get_texts(self):
+ return [t.text for t in self.mediainserttext_set.all()]
+
+ def get_price(self, words, pages):
+ price_obj = self.pricelevel_set.exclude(
+ min_pages__gt=pages
+ ).exclude(
+ min_words__gt=words
+ ).order_by('-price').first()
+ if price_obj is None:
+ return None
+ return price_obj.price
+
+ def get_publisher(self):
+ if self.site_type == 'legimi':
+ pub_class = Legimi
+ elif self.site_type == 'woblink':
+ pub_class = Woblink
+ return pub_class(self.username, self.password, self.publisher_handle)
+
+ def publish(self, site_book_publish, changes):
+ self.get_publisher().send_book(
+ site_book_publish,
+ changes=changes,
+ )
+
+ def can_publish(self, book):
+ return self.get_publisher().can_publish(self, book)
+
+ def get_last(self, book):
+ return SiteBookPublish.objects.filter(
+ site_book__site=self, site_book__book=book
+ ).order_by('-created_at').first()
+
+ def get_external_id_for_book(self, book):
+ site_book = self.sitebook_set.filter(book=book).first()
+ return (site_book and site_book.external_id) or ''
+
+class PriceLevel(models.Model):
+ site = models.ForeignKey(Site, models.CASCADE)
+ min_pages = models.IntegerField(null=True, blank=True)
+ min_words = models.IntegerField(null=True, blank=True)
+ price = models.IntegerField()
+
+ class Meta:
+ ordering = ('price',)
+
+
+class MediaInsertText(models.Model):
+ site = models.ForeignKey(Site, models.CASCADE)
+ ordering = models.IntegerField()
+ text = models.TextField()
+
+ class Meta:
+ ordering = ('ordering',)