예제 #1
0
    def mutate(self, info, artwork_data=None):
        metrics = ArtworkMetrics()
        artwork = Artwork(
            title=artwork_data.title,
            artist=artwork_data.artist,
            description=artwork_data.description,
            pictures=artwork_data.pictures if artwork_data.pictures else [],
            found_by=decodeId(artwork_data.found_by),
            location={
                "type": "Point",
                "coordinates":
                [artwork_data.location[0], artwork_data.location[1]]
            },
            metrics=metrics,
            num_ratings=artwork_data.num_ratings,
            rating=artwork_data.rating,
            comments=[],
            tags=artwork_data.tags)
        artwork.save()
        # Add artwork to user portfolio
        user = UpdateUserMutation.getUser(artwork_data.found_by)
        user.personal_portfolio.artworks.append(artwork)
        user.metrics.works_found += 1
        user.save()
        UpdateUserMutation.updateMetrics(user)

        return CreateArtworkMutation(artwork=artwork)
예제 #2
0
def add_artwork(artist, name, price, availability):
    try:
        artist_id = _get_artist_id(artist)
        new_artwork = Artwork(artist=artist_id,
                              name=name,
                              price=price,
                              available=availability)
        new_artwork.save()
        return f'The artwork \'{name}\' by {artist} was added successfully.'
    except IntegrityError:
        return 'I\'m sorry. There was an issue adding this art.'