Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving to Py3 #550

Merged
merged 18 commits into from
Feb 10, 2020
8 changes: 4 additions & 4 deletions get-twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
init_for('dev')
auth = tweepy.OAuthHandler(app.config['TWITTER_CONSUMER_KEY'], app.config['TWITTER_CONSUMER_SECRET'])
auth_url = auth.get_authorization_url()
print 'Please authorize: ' + auth_url
verifier = raw_input('PIN: ').strip()
print('Please authorize: ' + auth_url)
verifier = input('PIN: ').strip()
auth.get_access_token(verifier)
print "TWITTER_ACCESS_KEY = '%s'" % auth.access_token.key
print "TWITTER_ACCESS_SECRET = '%s'" % auth.access_token.secret
print("TWITTER_ACCESS_KEY = '%s'" % auth.access_token.key)
print("TWITTER_ACCESS_SECRET = '%s'" % auth.access_token.secret)
2 changes: 1 addition & 1 deletion hasjob/extapi/location.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from urlparse import urljoin
from urllib.parse import urljoin
from simplejson import JSONDecodeError
import requests
from baseframe import cache
Expand Down
10 changes: 5 additions & 5 deletions hasjob/forms/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ class ConfirmForm(forms.Form):

class WithdrawForm(forms.Form):
really_withdraw = forms.BooleanField(__("Yes, I really want to withdraw the job post"),
validators=[forms.validators.DataRequired(__(u"You must confirm withdrawal"))])
validators=[forms.validators.DataRequired(__("You must confirm withdrawal"))])


class ReportForm(forms.Form):
report_code = forms.RadioField(__("Code"), coerce=int, validators=[forms.validators.InputRequired(__(u"Pick one"))])
report_code = forms.RadioField(__("Code"), coerce=int, validators=[forms.validators.InputRequired(__("Pick one"))])


class RejectForm(forms.Form):
reason = forms.StringField(__("Reason"), validators=[forms.validators.DataRequired(__(u"Give a reason"))])
reason = forms.StringField(__("Reason"), validators=[forms.validators.DataRequired(__("Give a reason"))])


class ModerateForm(forms.Form):
reason = forms.TextAreaField(__("Reason"),
validators=[forms.validators.DataRequired(__(u"Give a reason")), forms.validators.Length(max=250)])
validators=[forms.validators.DataRequired(__("Give a reason")), forms.validators.Length(max=250)])


class PinnedForm(forms.Form):
Expand All @@ -43,5 +43,5 @@ class NewLocationForm(forms.Form):

class EditLocationForm(forms.Form):
title = forms.StringField(__("Page title"),
validators=[forms.validators.DataRequired(__(u"This location needs a name"))])
validators=[forms.validators.DataRequired(__("This location needs a name"))])
description = forms.TinyMce4Field(__("Description"), content_css=content_css)
84 changes: 42 additions & 42 deletions hasjob/forms/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,47 @@
def jobtype_label(jobtype):
annotations = []
if jobtype.nopay_allowed:
annotations.append(_(u'zero pay allowed'))
annotations.append(_('zero pay allowed'))
if jobtype.webmail_allowed:
annotations.append(_(u'webmail address allowed'))
annotations.append(_('webmail address allowed'))
if annotations:
return Markup(u'%s <small><em>(%s)</em></small>') % (jobtype.title, u', '.join(annotations))
return Markup('%s <small><em>(%s)</em></small>') % (jobtype.title, ', '.join(annotations))
else:
return jobtype.title


class BoardOptionsForm(forms.Form):
restrict_listing = forms.BooleanField(__(u"Restrict direct posting on this board to owners and the following users"),
restrict_listing = forms.BooleanField(__("Restrict direct posting on this board to owners and the following users"),
default=True,
description=__(u"As the owner of this board, you can always cross-add jobs from other boards on Hasjob"))
posting_users = forms.UserSelectMultiField(__(u"Allowed users"),
description=__(u"These users will be allowed to post jobs on this board under the following terms"),
description=__("As the owner of this board, you can always cross-add jobs from other boards on Hasjob"))
posting_users = forms.UserSelectMultiField(__("Allowed users"),
description=__("These users will be allowed to post jobs on this board under the following terms"),
usermodel=User, lastuser=lastuser)
# Allow turning this off only in siteadmin-approved boards (deleted in the view for non-siteadmins)
require_pay = forms.BooleanField(__(u"Require pay data for posting on this board?"), default=True,
description=__(u"Hasjob requires employers to reveal what they intend to pay, "
u"but you can make it optional for jobs posted from this board. "
u"Pay data is used to match candidates to jobs. We recommend you collect it"))
newjob_headline = forms.StringField(__(u"Headline"),
description=__(u"Optional – The sample headline shown to employers when posting a job"),
require_pay = forms.BooleanField(__("Require pay data for posting on this board?"), default=True,
description=__("Hasjob requires employers to reveal what they intend to pay, "
"but you can make it optional for jobs posted from this board. "
"Pay data is used to match candidates to jobs. We recommend you collect it"))
newjob_headline = forms.StringField(__("Headline"),
description=__("Optional – The sample headline shown to employers when posting a job"),
validators=[
forms.validators.Length(min=0, max=100, message=__("%%(max)d characters maximum"))],
filters=[forms.filters.strip(), forms.filters.none_if_empty()])
newjob_blurb = forms.TinyMce4Field(__(u"Posting instructions"),
description=__(u"Optional – What should we tell employers when they post a job on your board? "
u"Leave blank to use the default text"),
newjob_blurb = forms.TinyMce4Field(__("Posting instructions"),
description=__("Optional – What should we tell employers when they post a job on your board? "
"Leave blank to use the default text"),
content_css=content_css,
validators=[forms.validators.AllUrlsValid()])
types = QuerySelectMultipleField(__("Job types"),
widget=ListWidget(), option_widget=CheckboxInput(),
query_factory=lambda: JobType.query.filter_by(private=False).order_by(JobType.seq), get_label=jobtype_label,
validators=[forms.validators.DataRequired(__(u"You need to select at least one job type"))],
description=__(u"Jobs listed directly on this board can use one of the types enabled here"))
validators=[forms.validators.DataRequired(__("You need to select at least one job type"))],
description=__("Jobs listed directly on this board can use one of the types enabled here"))
categories = QuerySelectMultipleField(__("Job categories"),
widget=ListWidget(), option_widget=CheckboxInput(),
query_factory=lambda: JobCategory.query.filter_by(private=False).order_by(JobCategory.seq), get_label='title',
validators=[forms.validators.DataRequired(__(u"You need to select at least one category"))],
description=__(u"Jobs listed directly on this board can use one of the categories enabled here"))
validators=[forms.validators.DataRequired(__("You need to select at least one category"))],
description=__("Jobs listed directly on this board can use one of the categories enabled here"))


class BoardTaggingForm(forms.Form):
Expand All @@ -72,21 +72,21 @@ class BoardTaggingForm(forms.Form):
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"))
description=__("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"))
description=__("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."))
description=__("Select this if, for example, you want to match all programming jobs in Bangalore "
"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:
if ',' in item:
relist.extend([x.strip() for x in item.split(',')])
elif u' ' in item:
elif ' ' in item:
relist.extend([x.strip() for x in item.split(' ')])
else:
relist.append(item)
Expand All @@ -96,7 +96,7 @@ def validate_auto_domains(self, field):
if item:
# FIXME: This will break domains where the subdomain handles email
r = tldextract.extract(item.lower())
d = u'.'.join([r.domain, r.suffix])
d = '.'.join([r.domain, r.suffix])
if not is_public_email_domain(d, default=False):
domains.add(d)
field.data = list(domains)
Expand All @@ -120,29 +120,29 @@ class BoardForm(forms.Form):
forms.validators.Optional(),
forms.validators.Length(min=0, max=80, message=__("%%(max)d characters maximum"))],
filters=[forms.filters.strip(), forms.filters.none_if_empty()])
name = forms.AnnotatedTextField(__("URL Name"), prefix='https://', suffix=u'.hasjob.co',
description=__(u"Optional — Will be autogenerated if blank"),
name = forms.AnnotatedTextField(__("URL Name"), prefix='https://', suffix='.hasjob.co',
description=__("Optional — Will be autogenerated if blank"),
validators=[
forms.validators.ValidName(),
forms.validators.Length(min=0, max=63, message=__("%%(max)d characters maximum")),
AvailableName(__(u"This name has been taken by another board"), model=Board)])
description = forms.TinyMce4Field(__(u"Description"),
description=__(u"The description appears at the top of the board, above all jobs. "
u"Use it to introduce your board and keep it brief"),
AvailableName(__("This name has been taken by another board"), model=Board)])
description = forms.TinyMce4Field(__("Description"),
description=__("The description appears at the top of the board, above all jobs. "
"Use it to introduce your board and keep it brief"),
content_css=content_css,
validators=[forms.validators.DataRequired(__("A description of the job board is required")),
forms.validators.AllUrlsValid()])
userid = forms.SelectField(__(u"Owner"), validators=[forms.validators.DataRequired(__("Select an owner"))],
description=__(u"Select the user, organization or team who owns this board. "
userid = forms.SelectField(__("Owner"), validators=[forms.validators.DataRequired(__("Select an owner"))],
description=__("Select the user, organization or team who owns this board. "
"Owners can add jobs to the board and edit these settings"))
require_login = forms.BooleanField(__(u"Prompt users to login"), default=True,
description=__(u"If checked, users must login to see all jobs available. "
u"Logging in provides users better filtering for jobs that may be of interest to them, "
u"and allows employers to understand how well their post is performing"))
options = forms.FormField(BoardOptionsForm, __(u"Direct posting options"))
autotag = forms.FormField(BoardTaggingForm, __(u"Automatic posting options"))
require_login = forms.BooleanField(__("Prompt users to login"), default=True,
description=__("If checked, users must login to see all jobs available. "
"Logging in provides users better filtering for jobs that may be of interest to them, "
"and allows employers to understand how well their post is performing"))
options = forms.FormField(BoardOptionsForm, __("Direct posting options"))
autotag = forms.FormField(BoardTaggingForm, __("Automatic posting options"))

def validate_name(self, field):
if field.data:
if field.data in Board.reserved_names:
raise forms.ValidationError(_(u"This name is reserved. Please use another name"))
raise forms.ValidationError(_("This name is reserved. Please use another name"))
32 changes: 16 additions & 16 deletions hasjob/forms/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CampaignContentForm(forms.Form):
validators=[forms.validators.Optional(), forms.validators.AllUrlsValid()])
banner_image = forms.URLField(__("Banner image URL"), validators=[forms.validators.Optional()], # TODO: Use ImgeeField
description=__("An image to illustrate your campaign"))
banner_location = forms.RadioField(__("Banner location"), choices=BANNER_LOCATION.items(), coerce=int,
banner_location = forms.RadioField(__("Banner location"), choices=list(BANNER_LOCATION.items()), coerce=int,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, list() is necessary as we are replacing a frame object with a list.

description=__("Where should this banner appear relative to text?"))


Expand All @@ -34,28 +34,28 @@ class CampaignForm(forms.Form):
filters=[forms.filters.strip()])
start_at = forms.DateTimeField(__("Start at"), naive=False)
end_at = forms.DateTimeField(__("End at"),
validators=[forms.validators.GreaterThan('start_at', __(u"The campaign can’t end before it starts"))],
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=CAMPAIGN_POSITION.items(), coerce=int)
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=__(u"Select the boards this campaign is active on"))
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, __(u"N/A – Don’t target by login status")),
(True, __(u"Yes – Show to logged in users only")),
(False, __(u"No – Show to anonymous users only"))])
(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', __(u"N/A")), ('True', __(u"True")), ('False', __(u"False"))])
choices=[('None', __("N/A")), ('True', __("True")), ('False', __("False"))])
content = forms.FormField(CampaignContentForm, __("Campaign content"))

def validate_geonameids(self, field):
Expand All @@ -69,24 +69,24 @@ class CampaignActionForm(forms.Form):
icon = forms.StringField(__("Icon"), validators=[forms.validators.Optional()], filters=[forms.filters.none_if_empty()],
description=__("Optional Font-Awesome icon name"))
public = forms.BooleanField(__("This action is live"))
type = forms.RadioField(__("Type"), choices=CAMPAIGN_ACTION.items(), validators=[forms.validators.DataRequired(__("This is required"))])
type = forms.RadioField(__("Type"), choices=list(CAMPAIGN_ACTION.items()), validators=[forms.validators.DataRequired(__("This is required"))])
group = forms.StringField(__("RSVP group"), validators=[forms.validators.Optional()],
filters=[forms.filters.none_if_empty()],
description=__("If you have multiple RSVP actions, add an optional group name"))
category = forms.RadioField(__("Category"), validators=[forms.validators.DataRequired(__("This is required"))],
widget=forms.InlineListWidget(class_='button-bar', class_prefix='btn btn-'), choices=[
(u'default', __(u"Default")),
(u'primary', __(u"Primary")),
(u'success', __(u"Success")),
(u'info', __(u"Info")),
(u'warning', __(u"Warning")),
(u'danger', __(u"Danger")),
('default', __("Default")),
('primary', __("Primary")),
('success', __("Success")),
('info', __("Info")),
('warning', __("Warning")),
('danger', __("Danger")),
])
message = forms.TinyMce4Field(__("Message"),
description=__("Message shown after the user has performed an action (for forms and RSVP type)"),
content_css=content_css,
validators=[forms.validators.Optional(), forms.validators.AllUrlsValid()])
link = forms.URLField(__("Link"), description=__(u"URL to redirect to, if type is “follow link”"),
link = forms.URLField(__("Link"), description=__("URL to redirect to, if type is “follow link”"),
validators=[
optional_url,
forms.validators.Length(min=0, max=250, message=__("%%(max)d characters maximum")),
Expand Down
4 changes: 2 additions & 2 deletions hasjob/forms/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class DomainForm(forms.Form):
title = forms.StringField(__(u"Common name"),
title = forms.StringField(__("Common name"),
validators=[forms.validators.DataRequired(),
forms.validators.Length(min=1, max=250, message=__("%(max)d characters maximum"))],
filters=[forms.filters.strip()],
Expand All @@ -18,7 +18,7 @@ class DomainForm(forms.Form):
validators=[forms.validators.Optional(),
forms.validators.Length(min=1, max=250, message=__("%%(max)d characters maximum"))],
filters=[forms.filters.none_if_empty()],
description=__(u"Optional — The full legal name of your organization"))
description=__("Optional — The full legal name of your organization"))
# logo_url = forms.URLField(__("Logo URL"), # TODO: Use ImgeeField
# validators=[forms.validators.Optional(),
# forms.validators.Length(min=0, max=250, message=__("%%(max)d characters maximum"))],
Expand Down
2 changes: 1 addition & 1 deletion hasjob/forms/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def format_geonameids(geonameids):

def get_currency_choices():
choices = [('', __('None'))]
choices.extend(CURRENCY.items())
choices.extend(list(CURRENCY.items()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will work without the list().

return choices


Expand Down
2 changes: 1 addition & 1 deletion hasjob/forms/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def optional_url(form, field):
try:
return validator(form, field)
except forms.ValidationError as e:
raise forms.StopValidation(unicode(e))
raise forms.StopValidation(str(e))
Loading