class CampaignForm(forms.Form): title = forms.StringField( __("Title"), description=__("A reference name for looking up this campaign again"), validators=[ forms.validators.DataRequired(__("A title is required")), forms.validators.StripWhitespace() ]) start_at = forms.DateTimeField(__("Start at"), timezone=lambda: g.user.timezone if g.user else None) end_at = forms.DateTimeField(__("End at"), timezone=lambda: g.user.timezone if g.user else None) public = forms.BooleanField(__("This campaign is live")) position = forms.RadioField(__("Display position"), choices=CAMPAIGN_POSITION.items(), coerce=int) priority = forms.IntegerField( __("Priority"), default=0, description=__( "A larger number is higher priority when multiple campaigns are running on the " "same dates. 0 implies lowest priority")) boards = QuerySelectMultipleField( __("Boards"), widget=ListWidget(), option_widget=CheckboxInput(), query_factory=lambda: Board.query.order_by('title'), get_label='title', validators=[forms.validators.Optional()], description=__(u"Select the boards this campaign is active on")) geonameids = forms.GeonameSelectMultiField( "Locations", description=__( "This campaign will be targetted at users and jobs with matching locations" )) user_required = forms.RadioField(__("User is required"), coerce=getbool, choices=[(None, __("N/A")), (True, __("Yes")), (False, __("No"))]) flags = forms.RadioMatrixField( "Flags", coerce=getbool, fields=Campaign.flag_choices, description=__( "All selected flags must match the logged in user for the campaign to be shown" ), choices=[('None', __("N/A")), ('True', __("True")), ('False', __("False"))]) content = forms.FormField(CampaignContentForm, __("Campaign content")) def validate_geonameids(self, field): field.data = [int(x) for x in field.data if x.isdigit()] def validate_end_at(self, field): if field.data <= self.start_at.data: raise forms.ValidationError( __(u"The campaign can’t end before it starts"))
class BoardTaggingForm(forms.Form): tag_domains = forms.TextListField( "Email Domains", description= "Jobs from any of these email domains will be automatically added to this board. " "One per line. Do NOT add the www prefix") geonameids = forms.GeonameSelectMultiField( "Locations", description= "Jobs in any of these locations will be automatically added to this board" ) def validate_tag_domains(self, field): relist = [] for item in field.data: item = item.strip() if u',' in item: relist.extend([x.strip() for x in item.split(',')]) elif u' ' in item: relist.extend([x.strip() for x in item.split(' ')]) else: relist.append(item) domains = set() for item in relist: if item: # FIXME: This will break domains where the subdomain handles email r = tldextract.extract(item.lower()) d = u'.'.join([r.domain, r.suffix]) if d not in webmail_domains: domains.add(d) field.data = list(domains) def validate_geonameids(self, field): field.data = [int(x) for x in field.data if x.isdigit()]
class FiltersetForm(forms.Form): title = forms.StringField(__("Title"), description=__("A title shown to viewers"), validators=[forms.validators.DataRequired()], filters=[forms.filters.strip()]) description = forms.TinyMce4Field( __("Description"), content_css=content_css, description=__("Description shown to viewers and search engines"), validators=[forms.validators.DataRequired()]) types = QuerySelectMultipleField(__("Job types"), widget=ListWidget(), option_widget=CheckboxInput(), get_label='title', validators=[forms.validators.Optional()]) categories = QuerySelectMultipleField( __("Job categories"), widget=ListWidget(), option_widget=CheckboxInput(), get_label='title', validators=[forms.validators.Optional()]) geonameids = forms.GeonameSelectMultiField("Locations", filters=[format_geonameids]) remote_location = forms.BooleanField(__("Match remote jobs")) pay_cash_currency = forms.RadioField( __("Currency"), choices=get_currency_choices(), default='', validators=[forms.validators.Optional()]) pay_cash = forms.IntegerField(__("Pay"), description=__("Minimum pay"), validators=[forms.validators.Optional()]) keywords = forms.StringField(__("Keywords"), validators=[forms.validators.Optional()], filters=[forms.filters.strip()]) auto_domains = forms.AutocompleteMultipleField( __("Domains"), autocomplete_endpoint='/api/1/domain/autocomplete', results_key='domains') auto_tags = forms.AutocompleteMultipleField( __("Tags"), autocomplete_endpoint='/api/1/tag/autocomplete', results_key='tags') def set_queries(self): if not self.edit_parent: self.edit_parent = g.board self.types.query = JobType.query.join(board_jobtype_table).filter( board_jobtype_table.c.board_id == self.edit_parent.id).order_by( 'title') self.categories.query = JobCategory.query.join( board_jobcategory_table).filter( board_jobcategory_table.c.board_id == self.edit_parent.id).order_by('title')
class BoardTaggingForm(forms.Form): auto_domains = forms.TextListField(__("Email Domains"), description=__("Jobs from any of these email domains will be automatically added to this board. " "One per line. Do NOT add the www prefix")) auto_geonameids = forms.GeonameSelectMultiField(__("Locations"), description=__("Jobs in any of these locations will be automatically added to this board")) auto_keywords = forms.AutocompleteMultipleField(__("Tags"), autocomplete_endpoint='/api/1/tag/autocomplete', results_key='tags', description=__("Jobs tagged with these keywords will be automatically added to this board")) auto_types = QuerySelectMultipleField(__("Job types"), query_factory=lambda: JobType.query.filter_by(private=False).order_by(JobType.seq), get_label='title', description=__(u"Jobs of this type will be automatically added to this board")) auto_categories = QuerySelectMultipleField(__("Job categories"), query_factory=lambda: JobCategory.query.filter_by(private=False).order_by(JobCategory.seq), get_label='title', description=__(u"Jobs of this category will be automatically added to this board")) auto_all = forms.BooleanField(__("All of the above criteria must match"), description=__(u"Select this if, for example, you want to match all programming jobs in Bangalore " u"and not all programming jobs or Bangalore-based jobs.")) def validate_auto_domains(self, field): relist = [] for item in field.data: item = item.strip() if u',' in item: relist.extend([x.strip() for x in item.split(',')]) elif u' ' in item: relist.extend([x.strip() for x in item.split(' ')]) else: relist.append(item) domains = set() for item in relist: if item: # FIXME: This will break domains where the subdomain handles email r = tldextract.extract(item.lower()) d = u'.'.join([r.domain, r.suffix]) if not is_public_email_domain(d, default=False): domains.add(d) field.data = list(domains) def validate_auto_geonameids(self, field): field.data = [int(x) for x in field.data if x.isdigit()]
class CampaignForm(forms.Form): title = forms.StringField( __("Title"), description=__("A reference name for looking up this campaign again"), validators=[forms.validators.DataRequired(__("A title is required"))], filters=[forms.filters.strip()], ) start_at = forms.DateTimeField(__("Start at"), naive=False) end_at = forms.DateTimeField( __("End at"), validators=[ forms.validators.GreaterThan( 'start_at', __("The campaign can’t end before it starts") ) ], naive=False, ) public = forms.BooleanField(__("This campaign is live")) position = forms.RadioField( __("Display position"), choices=list(CAMPAIGN_POSITION.items()), coerce=int ) priority = forms.IntegerField( __("Priority"), default=0, description=__( "A larger number is higher priority when multiple campaigns are running on the " "same dates. 0 implies lowest priority" ), ) boards = QuerySelectMultipleField( __("Boards"), widget=ListWidget(), option_widget=CheckboxInput(), query_factory=lambda: Board.query.order_by(Board.featured.desc(), Board.title), get_label='title_and_name', validators=[forms.validators.Optional()], description=__("Select the boards this campaign is active on"), ) geonameids = forms.GeonameSelectMultiField( "Locations", description=__( "This campaign will be targetted at users and jobs with matching locations" ), ) user_required = forms.RadioField( __("User is required"), coerce=getbool, choices=[ (None, __("N/A – Don’t target by login status")), (True, __("Yes – Show to logged in users only")), (False, __("No – Show to anonymous users only")), ], ) flags = forms.RadioMatrixField( "Flags", coerce=getbool, fields=Campaign.flag_choices, description=__( "All selected flags must match the logged in user for the campaign to be shown" ), choices=[('None', __("N/A")), ('True', __("True")), ('False', __("False"))], ) content = forms.FormField(CampaignContentForm, __("Campaign content")) def validate_geonameids(self, field): field.data = [int(x) for x in field.data if x.isdigit()]