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)
Beispiel #2
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 #3
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 #4
0
 def create_artist(self, artist):
     return Artist(
         pk=artist.id,
         name=artist.display_name,
         songkick_url=self.get_url(artist.songkick_uri),
     )