Beispiel #1
0
 def form_valid(self, form):
     firstname = form.cleaned_data['firstname']
     lastname = form.cleaned_data['lastname']
     email = form.cleaned_data['email']
     p = Artist(firstname=firstname, lastname=lastname, email=email)
     p.save()
     return super().form_valid(form)
    def artist(self):
        artist = Artist()
        artist.name = "irrelevant name " + str(self.number_of_artists)

        artist.thumbnail = str(self.number_of_artists)
        artist.image = str(self.number_of_artists)
        artist.largeImage = str(self.number_of_artists)
        self.number_of_artists += 1
        return artist
Beispiel #3
0
 def add_artist(self, artist_name):
     '''
     add artist to users liked artist
     '''
     artist = Artist.retrieve_or_create_artist(artist_name)
     self.liked_artists.add(artist)
     logging.info('added artist %s from user %s', 
                  artist_name,
                  self.user.username)
     return artist
Beispiel #4
0
def profile(request):
    if request.method == 'POST':
        form = CreateArtistForm(request.POST)
        if form.is_valid():
            new_artist = Artist(
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                profession=form.cleaned_data['profession'],
                description=form.cleaned_data['description'],
                thank_you_message=form.cleaned_data['thank_you_message']
            )
            new_artist.save()
            return HttpResponseRedirect('/share/{id}'.format(id=new_artist.id))
    else:
        form = CreateArtistForm()

    return render(request, 'profile.html', {
        'form': form,
    })
Beispiel #5
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    # TODO: insert form data as a new Venue record in the db, instead
    # TODO: modify data to be the data object returned from db insertion
    form = ArtistForm()
    name = form.name.data
    created = False

    if form.validate_on_submit():
        try:
            attrs = {
                attr: getattr(form, attr).data
                for attr in ARTIST_SIMPLE_ATTRS
            }

            genres = ",".join(x for x in form.genres.data)

            new_artist = Artist(**attrs,
                                genres=genres,
                                available_times=[
                                    AvailableTime(**data)
                                    for data in form.available_times.data
                                ])

            db.session.add(new_artist)
            db.session.commit()
            # on successful db insert, flash success
            created = True
            flash("Artist " + name + " was successfully listed!")

        except:
            print(sys.exc_info())
        finally:
            db.session.close()

        if created:
            return redirect(url_for("index"))

    # TODO: on unsuccessful db insert, flash an error instead.
    flash("An error occurred. Artist " + name + " could not be listed.")
    return render_template("forms/new_artist.html", form=form)
Beispiel #6
0
    def restore_object(self, attrs, instance=None):
        """
        Create or update a new snippet instance, given a dictionary
        of deserialized field values.

        Note that if we don't define this method, then deserializing
        data will simply return a dictionary of items.
        """
        if instance:
            # Update existing instance
            instance.artist_name = attrs.get('name', instance.name)
            instance.artist_label = attrs.get('artist_label',
                                              instance.artist_label)
            instance.bio = attrs.get('bio', instance.bio)
            instance.currently_touring = attrs.get('currently_touring',
                                                   instance.currently_touring)
            instance.country_of_origin = attrs.get('country_of_origin',
                                                   instance.country_of_origin)
            instance.genre = attrs.get('genre', instance.genre)
            return instance

        # Create new instance
        return Artist(**attrs)
Beispiel #7
0
 def create_artist(self, artist):
     return Artist(
         pk=artist.id,
         name=artist.display_name,
         songkick_url=self.get_url(artist.songkick_uri),
     )