Esempio n. 1
0
def search():
    form = SearchForm()
    genres = list_genres()
    province_counties = list_provinces()
    return render_template("search.html",
                           form=form,
                           genrelist=genres,
                           province_counties=province_counties,
                           display_breadcrumbs=True)
Esempio n. 2
0
class CreateBandForm2(FlaskForm):
    description = StringField(
        "Description",
        render_kw={"placeholder": "Ska Reggae Band from Belfast"},
        validators=[DataRequired()])
    strapline = StringField("Band Motto / Strapline")
    genres = MultiCheckboxField("Genres",
                                choices=[(genre.lower(), genre.title())
                                         for genre in list_genres()],
                                default="rock")
    genres_other = StringField(
        "Genres Other",
        render_kw={"style": "text-transform: lowercase;"},
        validators=[check_genres_length])
    created_by = HiddenField()
    submit = SubmitField("Next")
Esempio n. 3
0
class CreateUpdateBandForm(FlaskForm):
    solo = RadioField("Band or Individual",
                      choices=[(1, "Solo Artist"), (0, "Band")],
                      coerce=int,
                      render_kw={},
                      default="False")
    band_name = StringField(
        "Band Name",
        render_kw={"placeholder": "Org Name / Band / Venue"},
        validators=[DataRequired()])
    description = StringField(
        "Description",
        render_kw={"placeholder": "Ska Reggae Band from Belfast"},
        validators=[DataRequired()])
    strapline = StringField("Band Motto / Strapline")
    profile = TextAreaField("Profile",
                            render_kw={
                                "placeholder":
                                "Brief Bio/History, band origins and direction"
                            },
                            validators=[DataRequired()])
    genres = MultiCheckboxField("Genres",
                                choices=[(genre.lower(), genre.title())
                                         for genre in list_genres()],
                                default="rock")
    genres_other = StringField(
        "Genres Other",
        render_kw={"style": "text-transform: lowercase;"},
        validators=[check_genres_length])
    hometown = FormField(HomeTownForm)
    members = FieldList(FormField(BandMemberFormlet), min_entries=1)
    created_by = HiddenField()
    contact_details = FormField(ContactFormlet)
    enquiries_url = StringField(
        "Online Enquiries Link",
        render_kw={"placeholder": "Org Name / Band / Venue"},
        validators=[Optional(), URL()])
    media_assets = FormField(MediaAssetsFormlet)
    submit = SubmitField("Save")
def update_band_profile(bname, letter, band_view):
    # flask-login uses a proxy that doesn't play nice with mongoengine
    # so current_user must be cast as user
    user = User.objects(id=current_user.id).first()
    band = Band.objects(band_name=bname).first()
    if band.created_by.id != current_user.id:
        abort(403)
    form = CreateUpdateBandForm()
    if form.validate_on_submit():
        if form.media_assets.featured_image.data:
            picture_file = save_picture(form.media_assets.featured_image.data,
                                        band=True)
            band.media_assets.featured_image = picture_file
        if form.media_assets.featured_video.data:
            band.media_assets.featured_video = get_video_service_and_id(
                form.media_assets.featured_video.data)
        contact = Contact()
        contact.contact_name = form.contact_details.contact_name.data
        contact.contact_title = form.contact_details.contact_title.data
        contact.contact_generic_title = form.contact_details.contact_generic_title.data
        phone = phonenumbers.parse(
            form.contact_details.contact_numbers.phone.data,
            form.contact_details.contact_numbers.region.data)
        new_phone = Phone(mobile=bool(
            form.contact_details.contact_numbers.mobile.data),
                          number=phonenumbers.format_number(
                              phone, phonenumbers.PhoneNumberFormat.E164))
        contact.contact_numbers = new_phone
        new_email = Email(
            email_title=form.contact_details.contact_emails.email_title.data,
            email_address=form.contact_details.contact_emails.email_address.
            data)
        contact.contact_emails = new_email
        weblinks = Links()
        weblinks.enquiries = form.enquiries_url.data
        band.solo = bool(form.solo.data)
        band.band_name = form.band_name.data
        band.catalogue_name = de_article(form.band_name.data)
        band.date_updated = datetime.utcnow
        band.description = form.description.data
        band.genres.clear()
        returned_genrelist = [
            genre.strip().replace(' ', '-').lower()
            for gl in request.form.getlist('genres') for genre in gl.split(',')
        ]
        returned_genrelist.extend(genre.strip().replace(' ', '-').lower()
                                  for genre in form.genres_other.data.split(
                                      ',')) if form.genres_other.data else None
        band.genres = list(filter(None, set(returned_genrelist)))
        band.hometown = {
            "town": form.hometown.origin_town.data,
            "county": form.hometown.origin_county.data
        }
        band.profile = form.profile.data
        band.strapline = form.strapline.data
        band.contact_details = contact
        band.links = weblinks
        band.band_members.clear()
        band.band_members = [
            BandMember(**member) for member in form.members.data
        ]
        band.save()
        flash("Band details updated!", "success")
        return redirect(url_for('manage.manage_bands_home', toggle='recent'))
    elif request.method == "GET":
        form.solo.data = band.solo
        form.band_name.data = band.band_name
        form.description.data = band.description
        form.strapline.data = band.strapline
        form.profile.data = band.profile
        form.contact_details.contact_name.data = band.contact_details.contact_name
        form.contact_details.contact_title.data = band.contact_details.contact_title
        form.contact_details.contact_generic_title.data = band.contact_details.contact_generic_title
        form.contact_details.contact_generic_title.data = band.contact_details.contact_generic_title
        form.contact_details.contact_numbers.mobile.data = band.contact_details.contact_numbers.mobile
        form.contact_details.contact_numbers.region.data = "None"
        form.contact_details.contact_numbers.phone.data = band.contact_details.contact_numbers.number
        form.contact_details.contact_emails.email_title.data = band.contact_details.contact_emails.email_title
        form.contact_details.contact_emails.email_address.data = band.contact_details.contact_emails.email_address
        form.media_assets.featured_video.data = (
            ("https://www.youtube.com/watch?v="
             if band.media_assets.featured_video["service"] == "youtube" else
             "https://www.vimeo.com/") +
            band.media_assets.featured_video["vid"]
        ) if band.media_assets.featured_video else None
        form.genres.data = ",".join(map(str, band.genres))
    selected_county = band.hometown["county"] if band.hometown[
        "county"] is not None else "Antrim"
    selected_town = band.hometown["town"] if band.hometown[
        "town"] is not None else "none"
    genres = list_genres()
    form_legend = "Edit Band Profile"
    return render_template("manage_band_update_form.html",
                           form=form,
                           genrelist=genres,
                           form_legend="Edit Band Profile",
                           formpage=True,
                           selected_county=selected_county,
                           selected_town=selected_town,
                           band=band,
                           display_breadcrumbs=True)
def add_band(stage):
    genres = list_genres()
    if stage == 1:
        form = CreateBandForm1()
        if request.method == "POST" and form.validate_on_submit():
            if form.band_name.validate(form):
                catalogue_name = de_article(form.band_name.data) if int(
                    form.solo.data) == 0 else de_singularise(
                        form.band_name.data)
            session["band"] = {
                "band_name": form.band_name.data,
                "catalogue_name": catalogue_name,
                "hometown": {
                    "town": form.hometown.origin_town.data,
                    "county": form.hometown.origin_county.data
                },
                "solo": form.solo.data
            }
            form = CreateBandForm2()
            stage = 2
            return render_template("manage_new_stage2_band_details.html",
                                   form=form,
                                   formpage=True,
                                   display_breadcrumbs=True,
                                   stage=stage,
                                   genrelist=genres,
                                   bname=session["band"]["band_name"])
        else:
            form = CreateBandForm1()
            return render_template('manage_new_stage1_band_check.html',
                                   form=form,
                                   formpage=True,
                                   display_breadcrumbs=True,
                                   stage=1,
                                   title="Band/Artist Name")

    if stage == 2:
        form = CreateBandForm2()
        if request.method == "POST" and form.validate_on_submit():
            returned_genrelist = [
                genre.strip().replace(' ', '-').lower()
                for gl in request.form.getlist('genres')
                for genre in gl.split(',')
            ]
            returned_genrelist.extend(
                genre.strip().replace(' ', '-').lower()
                for genre in form.genres_other.data.split(
                    ',')) if form.genres_other.data else None
            session["band"]["strapline"] = form.strapline.data
            session["band"]["description"] = form.description.data
            session["band"]["genres"] = list(
                filter(None, set(returned_genrelist)))
            session.modified = True
            form = CreateBandForm3()
            stage = 3
            return render_template("manage_new_stage3_band_profile.html",
                                   form=form,
                                   formpage=True,
                                   display_breadcrumbs=True,
                                   stage=stage,
                                   bname=session["band"]["band_name"])
        else:
            stage = 2
            return render_template("manage_new_stage2_band_details.html",
                                   form=form,
                                   formpage=True,
                                   display_breadcrumbs=True,
                                   stage=stage,
                                   genrelist=genres,
                                   bname=session["band"]["band_name"])

    if stage == 3:
        form = CreateBandForm3()
        if request.method == "POST" and form.validate_on_submit():
            if form.featured_image.data:
                picture_file = save_picture(form.featured_image.data,
                                            band=True)
                featured_image = picture_file if picture_file else 'defaultband.jpg'
            else:
                featured_image = "defaultband.jpg"
            session["band"]["featured_image"] = featured_image
            session["band"]["profile"] = form.profile.data
            session["band"]["members"] = [{
                **member
            } for member in form.members.data]
            session.modified = True
            form = CreateBandForm4()
            stage = 4
            return render_template("manage_new_stage4_band_contact.html",
                                   form=form,
                                   formpage=True,
                                   display_breadcrumbs=True,
                                   stage=stage,
                                   bname=session["band"]["band_name"])
        else:
            stage = 3
            return render_template("manage_new_stage3_band_profile.html",
                                   form=form,
                                   formpage=True,
                                   display_breadcrumbs=True,
                                   stage=stage,
                                   bname=session["band"]["band_name"])

    if stage == 4:
        form = CreateBandForm4()
        if request.method == "POST" and form.validate_on_submit():
            user = User.objects(id=current_user.id).first()
            contact = Contact()
            contact.contact_name = form.contact_details.contact_name.data
            if len(form.contact_details.contact_title.data.rstrip()) == 0:
                contact.contact_title = "Enquiries"
            else:
                contact.contact_title = form.contact_details.contact_title.data
            if len(form.contact_details.contact_generic_title.data.rstrip()
                   ) == 0:
                contact.contact_generic_title = "Enquiries"
            else:
                contact.contact_generic_title = form.contact_details.contact_generic_title.data
            _phone = phonenumbers.parse(
                form.contact_details.contact_numbers.phone.data,
                form.contact_details.contact_numbers.region.data)
            contact.contact_numbers = Phone(
                mobile=bool(form.contact_details.contact_numbers.mobile.data),
                number=phonenumbers.format_number(
                    _phone, phonenumbers.PhoneNumberFormat.E164))
            contact.contact_emails = Email(email_title=form.contact_details.
                                           contact_emails.email_title.data,
                                           email_address=form.contact_details.
                                           contact_emails.email_address.data)
            weblinks = Links(enquiries=form.enquiries_url.data)
            assets = Assets(featured_image=session["band"]["featured_image"])
            if form.featured_video.data:
                assets["featured_video"] = get_video_service_and_id(
                    form.featured_video.data)

            band = Band(band_name=session["band"]["band_name"],
                        catalogue_name=session["band"]["catalogue_name"],
                        genres=session["band"]["genres"],
                        hometown=session["band"]["hometown"],
                        description=session["band"]["description"],
                        strapline=session["band"]["strapline"],
                        profile=session["band"]["profile"],
                        band_members=[
                            BandMember(**member)
                            for member in session["band"]["members"]
                        ],
                        media_assets=assets,
                        contact_details=contact,
                        links=weblinks,
                        created_by=user,
                        solo=bool(session["band"]["solo"]))
            band.save()
            band_id = band.id
            # user.update(push__posts=post) if associating band to user
            band = Band.objects(id=band_id).first()
            return redirect(
                url_for('manage.preview_band',
                        band_view='alpha',
                        letter=band.catalogue_name[0],
                        bname=band.band_name))
        else:
            stage = 4
            return render_template("manage_new_stage4_band_contact.html",
                                   form=form,
                                   stage=stage,
                                   bname=session["band"]["band_name"],
                                   display_breadcrumbs=True)