<s> from wpc . models import Subscriber , Streamer , YoutubeChannel , YoutubeStream <EOL> from wpc . flask_utils import get_or_create <EOL> from utils import youtube_video_id <EOL> from flask_wtf import Form <EOL> from wtforms import StringField , SubmitField , validators , TextAreaField <EOL> from wtforms . validators import ValidationError <EOL> from flask . ext . login import current_user <EOL> from urlparse import urlparse <EOL> import re <EOL> def validate_email_unique ( form , field ) : <EOL> email = field . data <EOL> if Subscriber . query . filter_by ( email = email ) . first ( ) is not None : <EOL> raise ValidationError ( '<STR_LIT>' ) <EOL> class SubscribeForm ( Form ) : <EOL> email = StringField ( "<STR_LIT>" , [ validators . DataRequired ( ) , validators . Email ( ) , validate_email_unique ] ) <EOL> submit_button = SubmitField ( '<STR_LIT>' ) <EOL> class GLMSubscribeForm ( Form ) : <EOL> email = StringField ( "<STR_LIT>" , [ validators . DataRequired ( ) , validators . Email ( ) ] ) <EOL> submit_button = SubmitField ( '<STR_LIT>' ) <EOL> class DashboardEmailForm ( Form ) : <EOL> email = StringField ( "<STR_LIT>" , [ validators . DataRequired ( ) , validators . Email ( ) ] ) <EOL> submit_button = SubmitField ( '<STR_LIT>' ) <EOL> def prepopulate ( self , streamer ) : <EOL> if streamer . as_subscriber : <EOL> self . email . data = streamer . as_subscriber . email <EOL> class DashboardAddVideoForm ( Form ) : <EOL> link = StringField ( "<STR_LIT>" , [ validators . DataRequired ( ) ] ) <EOL> submit_button = SubmitField ( '<STR_LIT>' ) <EOL> def validate_link ( form , field ) : <EOL> ytid = youtube_video_id ( field . data ) <EOL> if not ytid : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> existing_stream = YoutubeStream . query . filter_by ( ytid = ytid ) . first ( ) <EOL> if existing_stream and existing_stream . streamer : <EOL> raise ValidationError ( "<STR_LIT>" . format ( existing_stream . streamer . reddit_username ) ) <EOL> class IdeaForm ( Form ) : <EOL> description = TextAreaField ( "<STR_LIT>" , [ validators . DataRequired ( ) ] ) <EOL> submit_button = SubmitField ( '<STR_LIT>' ) <EOL> class EditStreamTitleForm ( Form ) : <EOL> title = StringField ( "<STR_LIT>" , [ validators . Length ( max = <NUM_LIT:200> ) ] ) <EOL> submit_button = SubmitField ( '<STR_LIT>' ) <EOL> class RtmpRedirectForm ( Form ) : <EOL> rtmp_redirect_1 = StringField ( "<STR_LIT>" ) <EOL> rtmp_redirect_2 = StringField ( "<STR_LIT>" ) <EOL> rtmp_redirect_3 = StringField ( "<STR_LIT>" ) <EOL> submit_button = SubmitField ( '<STR_LIT>' ) <EOL> def prepopulate ( self , streamer ) : <EOL> for rid in xrange ( <NUM_LIT:1> , <NUM_LIT:4> ) : <EOL> attrname = '<STR_LIT>' . format ( rid ) <EOL> getattr ( self , attrname ) . data = getattr ( streamer , attrname ) <EOL> class EditStreamerInfoForm ( Form ) : <EOL> youtube_channel = StringField ( "<STR_LIT>" , [ validators . Length ( max = <NUM_LIT:100> ) ] ) <EOL> twitch_channel = StringField ( "<STR_LIT>" , [ validators . Length ( max = <NUM_LIT:100> ) ] ) <EOL> info = TextAreaField ( "<STR_LIT>" , [ validators . Length ( max = <NUM_LIT> ) ] ) <EOL> submit_button = SubmitField ( '<STR_LIT>' ) <EOL> def twitch_channel_extract ( self ) : <EOL> """<STR_LIT>""" <EOL> string = self . twitch_channel . data . strip ( ) <EOL> position = string . find ( '<STR_LIT>' ) <EOL> if position != - <NUM_LIT:1> : <EOL> path = urlparse ( string [ position : ] ) . path . split ( '<STR_LIT:/>' ) <EOL> if len ( path ) < <NUM_LIT:2> : <EOL> return None <EOL> string = path [ <NUM_LIT:1> ] <EOL> return string if len ( string ) <= <NUM_LIT> and re . match ( r'<STR_LIT>' , string ) else None <EOL> def youtube_channel_extract ( self ) : <EOL> """<STR_LIT>""" <EOL> string = self . youtube_channel . data . strip ( ) <EOL> position = string . find ( '<STR_LIT>' ) <EOL> if position != - <NUM_LIT:1> : <EOL> path = urlparse ( string [ position : ] ) . path . split ( '<STR_LIT:/>' ) <EOL> if len ( path ) < <NUM_LIT:3> or path [ <NUM_LIT:1> ] != "<STR_LIT>" : <EOL> return None <EOL> else : <EOL> string = path [ <NUM_LIT:2> ] <EOL> return string if len ( string ) == <NUM_LIT> and re . match ( r'<STR_LIT>' , string ) or string == '<STR_LIT>' else None <EOL> def validate_youtube_channel ( form , field ) : <EOL> yc = form . youtube_channel_extract ( ) <EOL> if yc is None : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> streamer = get_or_create ( YoutubeChannel , channel_id = yc ) . streamer <EOL> if streamer and streamer . checked and streamer != current_user : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def validate_twith_channel ( form , field ) : <EOL> tc = form . twitch_channel_extract ( ) <EOL> if tc is None : <EOL> raise ValidationError ( '<STR_LIT>' ) <EOL> streamer = Streamer . query . filter_by ( twitch_channel = tc ) . first ( ) <EOL> if streamer and streamer . checked and streamer != current_user : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> class SearchForm ( Form ) : <EOL> query = StringField ( "<STR_LIT>" ) <EOL> search_button = SubmitField ( '<STR_LIT>' ) </s>
