Beispiel #1
0
class YoutubeIdField(wtforms.Field):
    widget = URLInput()

    def __init__(self, label=None, validators=None, **kwargs):
        wtforms.Field.__init__(self, label, validators, **kwargs)

    def _value(self):
        if self.data is not None:
            return u"https://www.youtube.com/watch?v=%s" % unicode(self.data)
        else:
            return ''

    def process_formdata(self, valuelist):
        self.data = None
        if valuelist:
            parsed = urlparse.urlparse(valuelist[0])
            if "youtube.com" not in parsed.netloc:
                raise ValueError(self.gettext("Not a valid Youtube URL"))
            video_args = urlparse.parse_qs(parsed.query).get("v")
            if len(video_args) != 1:
                raise ValueError(self.gettext("Not a valid Youtube URL"))
            youtube_id = video_args[0]
            if not YOUTUBE_ID_VALIDATOR.match(youtube_id):
                raise ValueError(self.gettext("Not a valid Youtube URL"))
            self.data = youtube_id
Beispiel #2
0
class HostingServiceForm(HostingServiceFormFirstStep):
    """ Final step when adding a new hosting-service, doubling as the form used for editing hosting-services. """

    # validate_url sanitizes url before validate_api_url makes a call to it
    api_url = StringField(
        "Api Url",
        [InputRequired(), URL()],
        widget=URLInput(),
        description="should be the same as the landing page in most cases"
    )
    custom_config = TextAreaField(
        "Custom config",
        [validate_custom_config],
        description="Custom config json. If you dont know what to put in, just leave it empty.",
    )
    important_notes_md = ""

    def populate_api_url(self):
        self.api_url.data = self.landingpage_url.data

    def to_hosting_service(self):
        """
        create hosting service (the db model, not the interface) from form data
        """
        h = HostingService()

        h.api_url = self.api_url.data
        h.landingpage_url = self.landingpage_url.data
        h.type = self.type.data
        if hasattr(self, "api_key"):
            h.api_key = self.api_key.data
        else:
            h.api_key = None
        h.custom_config = self.custom_config.data
        return h

    @classmethod
    def from_hosting_service_type(cls, hoster_type: str):
        """
        make a form for a sepecfic hoster type
        """
        hosting_service_forms_mapping = dict(
            github=GithubHostingServiceForm,
            gitlab=GitlabHostingServiceForm,
            gitea=GiteaHostingServiceForm,
        )

        Form = hosting_service_forms_mapping.get(hoster_type, False)
        if not Form:
            raise NoHostingServiceFormException(
                "No form found to edit {hosting_service.type}"
            )
        return Form()

    @property
    def important_notes_html(self):
        return markdown.markdown(self.important_notes_md)
Beispiel #3
0
class ArtistForm(FlaskForm):
    name = StringField('name', validators=[DataRequired()])
    city = StringField('city', validators=[DataRequired()])
    state = SelectField('state',
                        validators=[DataRequired()],
                        choices=state_choices)
    phone = StringField('phone', validators=[validate_phone_number])
    genres = SelectMultipleField('genres',
                                 validators=[DataRequired()],
                                 choices=genre_choices)
    facebook_link = StringField('facebook_link', validators=[URL()])
    facebook_link = StringField('facebook_link',
                                validators=[URL()],
                                widget=URLInput())
    website = StringField('website', validators=[URL()], widget=URLInput())
    image_link = StringField('image_link',
                             validators=[URL()],
                             widget=URLInput())
    seeking_venues = BooleanField('seeking_venues')
    seeking_description = TextAreaField('seeking_description')
class HostingServiceFormFirstStep(FlaskForm):
    """ Only get type and landingpage from the user, the rest we automatically resolve to pre-fill in step 2. """

    type = SelectField(
        u"Type",
        [InputRequired()],
        choices=[
            ("gitea", "gitea"),
            ("gitlab", "Gitlab"),
            ("github", "GitHub"),
        ],
    )
    landingpage_url = StringField(
        "Landingpage Url",
        [InputRequired(), URL()],
        widget=URLInput(),
    )