Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Moving to Py3 #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eventframe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# The imports in this file are order-sensitive

from __future__ import absolute_import

from threading import Lock
from pytz import timezone
from flask import Flask
Expand Down
4 changes: 2 additions & 2 deletions eventframe/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ def absurl(self, fragment):

def load_theme_assets(env, theme):
css_list = theme.options.get('assets_css', [])
if isinstance(css_list, basestring):
if isinstance(css_list, str):
css_list = [css_list]
css = Bundle(*[Bundle('_themes/%s/%s' % (theme.identifier, item),
filters='cssmin', output='_themes/%s/%s.packed.css' % (theme.identifier, item)) for item in css_list]) # ,
# filters='cssrewrite', output='_themes/%s/eventframe.packed.css' % (theme.identifier))
env.register('css_%s' % theme.identifier, css)

js_list = theme.options.get('assets_js', [])
if isinstance(js_list, basestring):
if isinstance(js_list, str):
js_list = [js_list]
js = Bundle(*[Bundle('_themes/%s/%s' % (theme.identifier, item),
filters='uglipyjs', output='_themes/%s/%s.packed.js' % (theme.identifier, item)) for item in js_list])
Expand Down
46 changes: 23 additions & 23 deletions eventframe/forms/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def __init__(self, label='', validators=None, **kwargs):

def _value(self):
if self.data:
return u', '.join(self.data)
return ', '.join(self.data)
else:
return u''
return ''

def process_formdata(self, valuelist):
if valuelist:
Expand All @@ -74,7 +74,7 @@ def _remove_duplicates(seq):

class DictField(wtforms.fields.Field):
widget = wtforms.widgets.TextArea()
description = u'One per line, as {"key": "value"}'
description = 'One per line, as {"key": "value"}'

def __init__(self, *args, **kwargs):
if not 'description' in kwargs:
Expand All @@ -83,7 +83,7 @@ def __init__(self, *args, **kwargs):

def _value(self):
if isinstance(self.data, dict):
return '\r\n'.join([json.dumps({key: value}) for key, value in self.data.items()])
return '\r\n'.join([json.dumps({key: value}) for key, value in list(self.data.items())])
return ''

def process_formdata(self, valuelist):
Expand All @@ -97,14 +97,14 @@ def process_formdata(self, valuelist):


class WebsiteForm(Form):
title = wtforms.TextField(u"Title", validators=[wtforms.validators.Required()])
name = wtforms.TextField(u"URL name", validators=[wtforms.validators.Required(), valid_name])
url = wtforms.fields.html5.URLField(u"Website URL", validators=[wtforms.validators.Required()])
hostnames = HostnamesField(u"Hostnames", validators=[wtforms.validators.Required()],
description=u"Hostnames at which this website will be accessed, comma separated")
theme = wtforms.SelectField(u"Website theme", validators=[wtforms.validators.Required()])
typekit_code = wtforms.TextField(u"Typekit code")
googleanalytics_code = wtforms.TextField(u"Google Analytics code")
title = wtforms.TextField("Title", validators=[wtforms.validators.Required()])
name = wtforms.TextField("URL name", validators=[wtforms.validators.Required(), valid_name])
url = wtforms.fields.html5.URLField("Website URL", validators=[wtforms.validators.Required()])
hostnames = HostnamesField("Hostnames", validators=[wtforms.validators.Required()],
description="Hostnames at which this website will be accessed, comma separated")
theme = wtforms.SelectField("Website theme", validators=[wtforms.validators.Required()])
typekit_code = wtforms.TextField("Typekit code")
googleanalytics_code = wtforms.TextField("Google Analytics code")

def validate_name(self, field):
# TODO: Ensure name is unique
Expand All @@ -116,28 +116,28 @@ def validate_hostnames(self, field):


class FolderForm(Form):
name = wtforms.TextField(u"URL name", validators=[wtforms.validators.Optional(), valid_name],
description=u"Folder name as it appears in the URL (without slashes)")
title = wtforms.TextField(u"Title",
description=u"Folder title, used in the per-folder blog feed")
theme = wtforms.SelectField(u"Theme")
name = wtforms.TextField("URL name", validators=[wtforms.validators.Optional(), valid_name],
description="Folder name as it appears in the URL (without slashes)")
title = wtforms.TextField("Title",
description="Folder title, used in the per-folder blog feed")
theme = wtforms.SelectField("Theme")

def validate_name(self, field):
# TODO
pass


class ImportForm(Form):
import_file = wtforms.FileField(u"Upload file", validators=[wtforms.validators.Required()])
import_updated = wtforms.BooleanField(u"Only import newer nodes", default=True,
description=u"Nodes that are newer locally will not be imported")
import_file = wtforms.FileField("Upload file", validators=[wtforms.validators.Required()])
import_updated = wtforms.BooleanField("Only import newer nodes", default=True,
description="Nodes that are newer locally will not be imported")


class ConfirmForm(Form):
pass # Only needed for CSRF confirmation


class FileFolderForm(Form):
name = wtforms.TextField(u"URL name", validators=[wtforms.validators.Required(), valid_name])
title = wtforms.TextField(u"Title", validators=[wtforms.validators.Required()])
properties = DictField(u"Properties")
name = wtforms.TextField("URL name", validators=[wtforms.validators.Required(), valid_name])
title = wtforms.TextField("Title", validators=[wtforms.validators.Required()])
properties = DictField("Properties")
32 changes: 16 additions & 16 deletions eventframe/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm.collections import attribute_mapped_collection
from urlparse import urljoin
from urllib.parse import urljoin
from flask import url_for
from coaster.auth import current_auth
from coaster.utils import buid, parse_isoformat
Expand All @@ -21,26 +21,26 @@ def default_user_id():
class Website(BaseNameMixin, db.Model):
__tablename__ = 'website'
#: URL to the website
url = db.Column(db.Unicode(80), nullable=False, default=u'')
url = db.Column(db.Unicode(80), nullable=False, default='')
#: Theme that this website uses as the default (folders can override)
theme = db.Column(db.Unicode(80), nullable=False, default=u'default')
theme = db.Column(db.Unicode(80), nullable=False, default='default')
#: Typekit code, if used
typekit_code = db.Column(db.Unicode(20), nullable=False, default=u'')
typekit_code = db.Column(db.Unicode(20), nullable=False, default='')
#: Google Analytics code, if used
googleanalytics_code = db.Column(db.Unicode(20), nullable=False, default=u'')
googleanalytics_code = db.Column(db.Unicode(20), nullable=False, default='')

_hostnames = db.relationship("Hostname", cascade='all, delete-orphan', backref='website')
hostnames = association_proxy('_hostnames', 'name',
creator=lambda name: Hostname.get(name=name))

def __init__(self, **kwargs):
super(Website, self).__init__(**kwargs)
root = Folder(name=u'', title=u'', website=self)
root = Folder(name='', title='', website=self)
self.folders.append(root)
# root.pages[0].template = u'index.html'

def __repr__(self):
return u'<Website %s "%s">' % (self.name, self.title)
return '<Website %s "%s">' % (self.name, self.title)

def folder_ids(self):
return [i[0] for i in db.session.query(Folder.id).filter_by(website=self).all()]
Expand All @@ -62,7 +62,7 @@ class Hostname(BaseMixin, db.Model):
website_id = db.Column(db.Integer, db.ForeignKey('website.id'), nullable=False)

def __repr__(self):
return u'<Hostname %s>' % self.name
return '<Hostname %s>' % self.name

@classmethod
def get(cls, name, website=None):
Expand All @@ -75,7 +75,7 @@ class LoginCode(BaseMixin, db.Model):
#: Tracking code to enable users to login to an event website
code = db.Column(db.Unicode(22), nullable=False, unique=True)
#: Access scope requested
scope = db.Column(db.Unicode(250), nullable=False, default=u'')
scope = db.Column(db.Unicode(250), nullable=False, default='')
#: User who logged in
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True, default=None)
user = db.relationship(User)
Expand All @@ -95,7 +95,7 @@ class Folder(BaseScopedNameMixin, db.Model):
#: Website this folder is under
website_id = db.Column(db.Integer, db.ForeignKey('website.id'), nullable=False)

_theme = db.Column("theme", db.Unicode(80), nullable=False, default=u'')
_theme = db.Column("theme", db.Unicode(80), nullable=False, default='')

website = db.relationship(Website,
backref=db.backref('folders', order_by='Folder.name', cascade='all, delete-orphan'))
Expand All @@ -120,7 +120,7 @@ def __init__(self, **kwargs):
# self.pages.append(index)

def __repr__(self):
return u'<Folder %s at %s>' % (self.name or '(root)', self.website.name)
return '<Folder %s at %s>' % (self.name or '(root)', self.website.name)

def url_for(self, action='view'):
"""
Expand All @@ -129,12 +129,12 @@ def url_for(self, action='view'):
if action == 'view':
return urljoin(self.website.url, self.name)
elif action == 'list':
if self.name == u'':
if self.name == '':
return url_for('website', website=self.website.name)
else:
return url_for('folder', website=self.website.name, folder=self.name)
elif action == 'edit':
if self.name != u'':
if self.name != '':
return url_for('folder_edit', website=self.website.name, folder=self.name)


Expand All @@ -159,7 +159,7 @@ def __init__(self, *args, **kwargs):
self.update(*args, **kwargs)

def update(self, *args, **kwargs):
for k, v in dict(*args, **kwargs).iteritems():
for k, v in dict(*args, **kwargs).items():
self[k] = v

def __delitem__(self, key):
Expand All @@ -178,7 +178,7 @@ def __setitem__(self, key, value):
if isinstance(value, Property):
dict.__setitem__(self, key, value.value)
else:
value = unicode(value) # Since Property.value = db.Unicode
value = str(value) # Since Property.value = db.Unicode
dict.__setitem__(self, key, value)
if key in self.node.node_properties:
self.node.node_properties[key].value = value
Expand Down Expand Up @@ -260,7 +260,7 @@ def url_for(self, action='view', _external=False):
Return a URL to this node.
"""
if action == 'view':
if self.folder.name == u'':
if self.folder.name == '':
return url_for('folder', folder=self.name, _external=_external)
else:
return url_for('node', folder=self.folder.name, node=self.name, _external=_external)
Expand Down
16 changes: 8 additions & 8 deletions eventframe/nodes/content/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@


class ContentForm(Form):
previous_id = wtforms.HiddenField(u"Previous revision")
title = wtforms.TextField(u"Title", validators=[wtforms.validators.Required()])
name = wtforms.TextField(u"URL name", validators=[wtforms.validators.Optional(), valid_name])
author = wtforms.TextField(u"Author (optional)", validators=[wtforms.validators.Length(max=40)],
previous_id = wtforms.HiddenField("Previous revision")
title = wtforms.TextField("Title", validators=[wtforms.validators.Required()])
name = wtforms.TextField("URL name", validators=[wtforms.validators.Optional(), valid_name])
author = wtforms.TextField("Author (optional)", validators=[wtforms.validators.Length(max=40)],
description="Name of the author. Will default to your name if blank")
description = wtforms.TextAreaField(u"Summary", description=u"Summary of this page")
content = RichTextField(u"Page content", linkify=False,
description = wtforms.TextAreaField("Summary", description="Summary of this page")
content = RichTextField("Page content", linkify=False,
tinymce_options=tinymce_options,
sanitize_tags=richtext_sanitize_tags,
sanitize_attributes=richtext_sanitize_attributes)
template = wtforms.TextField("Template", validators=[wtforms.validators.Required()], default='page.html.jinja2',
description=u"Template with which this page will be rendered.")
properties = DictField(u"Properties")
description="Template with which this page will be rendered.")
properties = DictField("Properties")

def validate_previous_id(self, field):
if not field.data:
Expand Down
8 changes: 4 additions & 4 deletions eventframe/nodes/content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class ContentRevision(BaseMixin, db.Model):
#: Title of the current revision
title = db.Column(db.Unicode(250), nullable=False)
#: Abstract that is shown in summaries. Plain text.
description = db.Column(db.UnicodeText, nullable=False, default=u'')
description = db.Column(db.UnicodeText, nullable=False, default='')
#: Page content. Rich text.
_content = db.Column('content', db.UnicodeText, nullable=False, default=u'')
_content = db.Column('content', db.UnicodeText, nullable=False, default='')
#: Template with which this page will be rendered
template = db.Column(db.Unicode(80), nullable=False, default=u'')
template = db.Column(db.Unicode(80), nullable=False, default='')

def __init__(self, **kwargs):
super(ContentRevision, self).__init__(**kwargs)
Expand Down Expand Up @@ -166,7 +166,7 @@ def content(self):
return self.revisions.draft.content

def __repr__(self):
return u'<%s %s/%s "%s" at %s>' % (self.__tablename__.title(), self.folder.name, self.name or '(index)',
return '<%s %s/%s "%s" at %s>' % (self.__tablename__.title(), self.folder.name, self.name or '(index)',
self.title, self.folder.website.name)

def as_json(self):
Expand Down
10 changes: 5 additions & 5 deletions eventframe/nodes/content/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class ContentHandler(AutoFormHandler):
def edit_tabs(self):
if self.node:
return [
{'title': u"Edit", 'url': self.node.url_for('edit'), 'active': self.action == 'edit'},
{'title': u"Publish", 'url': self.node.url_for('publish'), 'active': self.action == 'publish'},
{'title': u"Unpublish", 'url': self.node.url_for('unpublish'), 'active': self.action == 'unpublish'},
{'title': "Edit", 'url': self.node.url_for('edit'), 'active': self.action == 'edit'},
{'title': "Publish", 'url': self.node.url_for('publish'), 'active': self.action == 'publish'},
{'title': "Unpublish", 'url': self.node.url_for('unpublish'), 'active': self.action == 'unpublish'},
]
else:
return []
Expand Down Expand Up @@ -64,10 +64,10 @@ def process_form(self):
self.node.title = revision.title
if not self.node.id and not self.node.name:
# Is there already an index node in this folder?
index = db.session.query(Node.id).filter_by(folder=self.folder, name=u'').first()
index = db.session.query(Node.id).filter_by(folder=self.folder, name='').first()
if index is not None:
self.node.make_name()
db.session.commit()
# FIXME: Say created when created
flash(u"Edited node '%s'." % self.node.title, 'success')
flash("Edited node '%s'." % self.node.title, 'success')
return render_redirect(url_for('folder', website=self.website.name, folder=self.folder.name), code=303)
12 changes: 6 additions & 6 deletions eventframe/nodes/data/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@


class DataForm(Form):
name = wtforms.TextField(u"URL name", validators=[wtforms.validators.Required(), valid_name])
title = wtforms.TextField(u"Title", validators=[wtforms.validators.Required()])
data = wtforms.TextAreaField(u"Data", validators=[wtforms.validators.Required()],
description=u"Enter JSON data")
properties = DictField(u"Properties")
name = wtforms.TextField("URL name", validators=[wtforms.validators.Required(), valid_name])
title = wtforms.TextField("Title", validators=[wtforms.validators.Required()])
data = wtforms.TextAreaField("Data", validators=[wtforms.validators.Required()],
description="Enter JSON data")
properties = DictField("Properties")

def validate_data(self, field):
# Check for exceptions when loading data
parsed = simplejson.loads(field.data, use_decimal=True)
if not isinstance(parsed, dict):
raise wtforms.ValidationError(u'This is not a valid JSON object. Use {"key": value, ...}')
raise wtforms.ValidationError('This is not a valid JSON object. Use {"key": value, ...}')
2 changes: 1 addition & 1 deletion eventframe/nodes/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __len__(self):
return len(self.data)

def __iter__(self):
return self.data.iterkeys()
return iter(self.data.keys())

def __contains__(self, item):
return item in self.data
Expand Down
4 changes: 2 additions & 2 deletions eventframe/nodes/data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def process_form(self):
if self.node is None:
self.node = Data(folder=self.folder, name=self.form.name.data, title=self.form.title.data)
db.session.add(self.node)
flash(u"Created new data node '%s'" % self.node.title, 'success')
flash("Created new data node '%s'" % self.node.title, 'success')
else:
self.node.name = self.form.name.data
self.node.title = self.form.title.data
flash(u"Edited data node '%s'" % self.node.title, 'success')
flash("Edited data node '%s'" % self.node.title, 'success')
self.node.data = json.loads(self.form.data.data, use_decimal=True)
db.session.commit()
return render_redirect(url_for('folder', website=self.website.name, folder=self.folder.name), code=303)
Expand Down
24 changes: 12 additions & 12 deletions eventframe/nodes/event/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@


class EventForm(ContentForm):
start_datetime = DateTimeField(u"Start date/time", validators=[wtforms.validators.Required()])
end_datetime = DateTimeField(u"End date/time", validators=[wtforms.validators.Required()])
timezone = wtforms.SelectField(u"Timezone", choices=timezone_list, validators=[wtforms.validators.Required()])
location_name = wtforms.TextField(u"Location name", validators=[wtforms.validators.Required()])
location_address = wtforms.TextField(u"Address", validators=[wtforms.validators.Required()])
map = QuerySelectField(u"Map", get_label='title', allow_blank=True)
mapmarker = wtforms.TextField(u"Map marker")
capacity = wtforms.IntegerField(u"Capacity", validators=[wtforms.validators.Required()])
allow_waitlisting = wtforms.BooleanField(u"Allow wait-listing if over capacity", default=False)
allow_maybe = wtforms.BooleanField(u"Allow “Maybe” responses", default=True)
participant_list = QuerySelectField(u"Participant list", get_label='title', allow_blank=True)
properties = DictField(u"Properties")
start_datetime = DateTimeField("Start date/time", validators=[wtforms.validators.Required()])
end_datetime = DateTimeField("End date/time", validators=[wtforms.validators.Required()])
timezone = wtforms.SelectField("Timezone", choices=timezone_list, validators=[wtforms.validators.Required()])
location_name = wtforms.TextField("Location name", validators=[wtforms.validators.Required()])
location_address = wtforms.TextField("Address", validators=[wtforms.validators.Required()])
map = QuerySelectField("Map", get_label='title', allow_blank=True)
mapmarker = wtforms.TextField("Map marker")
capacity = wtforms.IntegerField("Capacity", validators=[wtforms.validators.Required()])
allow_waitlisting = wtforms.BooleanField("Allow wait-listing if over capacity", default=False)
allow_maybe = wtforms.BooleanField("Allow “Maybe” responses", default=True)
participant_list = QuerySelectField("Participant list", get_label='title', allow_blank=True)
properties = DictField("Properties")
Loading