def publish(self, user): """ Publishes a book on behalf of a (local) user. """ self.assert_publishable() changes = self.get_current_changes(publishable=True) book_xml = self.materialize(changes=changes) apiclient.api_call(user, "books/", {"book_xml": book_xml}) # record the publish br = BookPublishRecord.objects.create(book=self, user=user) for c in changes: ChunkPublishRecord.objects.create(book_record=br, change=c) post_publish.send(sender=br)
def put(cls, user, audiobook, path): tags = getattr(audiobook, "%s_tags" % cls.ext) data = { 'book': tags['url'], 'type': cls.ext, 'name': tags['name'], 'part_name': audiobook.part_name, 'part_index': audiobook.index, 'parts_count': audiobook.parts_count, 'source_sha1': audiobook.source_sha1, } api_call(user, UPLOAD_URL, data=data, files={ "file": open(path, 'rb'), })
def publish(self, user, fake=False, host=None): """ Publishes a book on behalf of a (local) user. """ self.assert_publishable() changes = self.get_current_changes(publishable=True) book_xml = self.materialize(changes=changes) if not fake: data = {"book_xml": book_xml} if host: data['gallery_url'] = host + self.gallery_url() apiclient.api_call(user, "books/", data) # record the publish br = BookPublishRecord.objects.create(book=self, user=user) for c in changes: ChunkPublishRecord.objects.create(book_record=br, change=c) post_publish.send(sender=br)
def publish(self, user): """Publishes the picture on behalf of a (local) user.""" from base64 import b64encode import apiclient from catalogue.signals import post_publish self.assert_publishable() change = self.publishable() picture_xml = change.materialize() picture_data = open(self.image.path).read() apiclient.api_call(user, "pictures/", { "picture_xml": picture_xml, "picture_image_data": b64encode(picture_data), }) # record the publish log = self.publish_log.create(user=user, change=change) post_publish.send(sender=log)
def publish(self, user, fake=False, host=None, days=0, beta=False): """ Publishes a book on behalf of a (local) user. """ self.assert_publishable() changes = self.get_current_changes(publishable=True) if not fake: book_xml = self.materialize(changes=changes) data = {"book_xml": book_xml, "days": days} if host: data['gallery_url'] = host + self.gallery_url() apiclient.api_call(user, "books/", data, beta=beta) if not beta: # record the publish br = BookPublishRecord.objects.create(book=self, user=user) for c in changes: ChunkPublishRecord.objects.create(book_record=br, change=c) if not self.public and days == 0: self.public = True self.save() if self.public and days > 0: self.public = False self.save() post_publish.send(sender=br)