コード例 #1
0
    def create_edition_from_data(self, work, edition_data):
        """if we already have the work, we're ready"""
        mapped_data = dict_from_mappings(edition_data, self.book_mappings)
        mapped_data["work"] = work.remote_id
        edition_activity = activitypub.Edition(**mapped_data)
        edition = edition_activity.to_model(model=models.Edition)
        edition.connector = self.connector
        edition.save()

        for author in self.get_authors_from_data(edition_data):
            edition.authors.add(author)
        if not edition.authors.exists() and work.authors.exists():
            edition.authors.set(work.authors.all())

        return edition
コード例 #2
0
    def create_edition_from_data(self, work, edition_data, instance=None):
        """if we already have the work, we're ready"""
        mapped_data = dict_from_mappings(edition_data, self.book_mappings)
        mapped_data["work"] = work.remote_id
        edition_activity = activitypub.Edition(**mapped_data)
        edition = edition_activity.to_model(model=models.Edition,
                                            overwrite=False,
                                            instance=instance)

        # if we're updating an existing instance, we don't need to load authors
        if instance:
            return edition

        if not edition.connector:
            edition.connector = self.connector
            edition.save(broadcast=False, update_fields=["connector"])

        for author in self.get_authors_from_data(edition_data):
            edition.authors.add(author)
        # use the authors from the work if none are found for the edition
        if not edition.authors.exists() and work.authors.exists():
            edition.authors.set(work.authors.all())

        return edition
コード例 #3
0
ファイル: incoming.py プロジェクト: tastytea/bookwyrm
def handle_update_edition(activity):
    ''' a remote instance changed a book (Document) '''
    activitypub.Edition(**activity['object']).to_model(models.Edition)