class NewPostForm(Form): title = StringField(_l('Title'), validators=[DataRequired()]) content = TextAreaField(_l('Content'), validators=[DataRequired()]) covered_period = DateField(_l('Date'), validators=[DataRequired()], default=lambda: dtdate.today()) week = BooleanField(_l('Covers whole week')) categories = SelectMultipleField(_('Categories'), widget=ListWidget(), option_widget=CheckboxInput(), choices=ClassChoices( Category.query.order_by('name'), 'name')) def get_slug(self): return slugify(self.title.data) def fill_post_object(self, post): post.title = self.title.data post.content = self.content.data post.covered_period = self.covered_period.data post.covers_week = self.week.data post.categories.extend( Category.query.filter(Category.name.in_(self.categories.data))) return post
class RecoverSetForm(Form): password = PasswordField(_l('password'), [ validators.Required(), validators.EqualTo('password2', message=_l("Passwords must match")), check_password_length ]) password2 = PasswordField(_l('password repeat'))
class NewCategoryForm(Form): name = StringField(_l('Name'), validators=[DataRequired()]) public = BooleanField(_l('Public')) users = SelectMultipleField(_l('Allowed readers'), coerce=int, widget=ListWidget(), option_widget=CheckboxInput(), choices=ClassChoices( User.query.order_by('login'), 'login'))
class RegistrationForm(mixin_class, Form): email = EmailField(label=_l(u"Your email address"), validators=[required(), email()]) coming_on_oct_3 = BooleanField( label=_l(u"Will you come on Oct. 3th? (Thursday)")) coming_on_oct_4 = BooleanField( label=_l(u"Will you come on Oct. 4th? (Friday)")) coming_on_oct_5 = BooleanField( label=_l(u"Will you come on Oct. 5th? (Saturday)"))
class WFSEditForm(Form): def is_submitted(self): return request and request.method in ("PUT", "POST") and request.form.get('edit_form') layer = SelectField(_l('wfs_layer')) external_editor = HiddenField() edit_form = HiddenField()
def validate(self): if not Form.validate(self): return False user = User.objects(name=self.name.data).first() if user is None: self.name.errors.append(_l(u'Username or password mismatch.')) return False return True
class ClassRoom(Slugged, Publishable, db.EmbeddedDocument): WEEKDAYS = ( ("sun", _l("Sunday")), ("mon", _l("Monday")), ("tue", _l("Tuesday")), ("wed", _l("Wednesday")), ("thu", _l("Thursday")), ("fri", _l("Friday")), ("sat", _l("Saturday")), ) title = db.StringField(required=True, max_length=100) description = db.StringField() weekdays = db.ListField(db.StringField(choices=WEEKDAYS), default=[]) start_date = db.DateTimeField() end_date = db.DateTimeField() status = db.StringField() def get_description(self): return "<br>".join([ self.title, self.description, ",".join(self.weekdays), self.start_date.strftime("%Y-%m-%d") if self.start_date else '' ]) def get_weekdays_display(self, **kwargs): data = dict(self.WEEKDAYS) data.update(kwargs) return [data.get(k) for k in self.weekdays] def clean(self): self.validate_slug() def __unicode__(self): return self.title
def display_form(): form = make_registration_form_class()() print form['track_1'] page = dict(title=_l(u"Register as a participant")) tracks = Track.query.all() print g.lang return render_template("registration/form.html", page=page, tracks=tracks, form=form, lang="en")
def display_form(): form = make_registration_form_class()() print form['track_1'] page = dict(title=_l(u"Register as a participant")) tracks = Track.query.all() return render_template("registration/form.html", page=page, tracks=tracks, form=form)
class ConfirmationForm(mixin_class, Form): email = EmailField(label=_l(u"Your email address"), validators=[required(), email()]) coming_on_oct_3 = BooleanField( label=_l(u"Will you come on Oct. 3th? (Thursday)")) coming_on_oct_4 = BooleanField( label=_l(u"Will you come on Oct. 4th? (Friday)")) coming_on_oct_5 = BooleanField( label=_l(u"Will you come on Oct. 5th? (Saturday)")) first_name = TextField(label=_l("First name")) last_name = TextField(label=_l("Last name")) organization = TextField(label=_l("Organization")) url = TextField(label=_l("URL")) url = TextAreaField(label=_l("Biography"))
class SDCApplicationForm(Form): theme = SelectField(label=_l(u"Merci de choisir une catégorie"), choices=THEMES_AS_CHOICE, validators=[required()]) leader = StringField(label=_l(u"Votre nom"), validators=[required()]) prenom = StringField(label=_l(u"Votre prénom"), validators=[required()]) email = EmailField(label=_l(u"Your email address"), validators=[required(), email()]) telephone = StringField(label=_l(u"Votre téléphone"), validators=[required()]) organization = StringField(label=_l(u"Etablissement / entreprise"), validators=[required()]) intervenants = TextAreaField( label=_l(u"Autres intervenants (autant de possible)")) summary = TextAreaField(label=_l(u"Résumé du projet"), validators=[required()])
class NewUserForm(EditAddressForm): type = SelectField(_l('type'), coerce=int) email = TextField( _l('email'), [validators.Required(), username_unique, validators.Email()]) password = PasswordField(_l('password'), [ validators.Required(), validators.EqualTo('password2', message=_l("Passwords must match")), check_password_length ]) password2 = PasswordField(_l('password repeat')) terms_of_use = BooleanField(_l('terms of use'), [validators.Required()])
def apply(self, permission, acl, resource=_l('resource')): """apply acl, abort if not allowed""" logger.debug('check %r with acl %r', permission, acl) if isinstance(acl, Container) and len(acl) < 0: return thruth = self.get_thruth(permission, current_user, acl) if thruth == 'ALLOW': logger.debug('ALLOW for space') return elif thruth == 'DENY': logger.debug('DENY for space') abort(403, _('You are not allowed to "%(permission)s" this\ %(resource)s', permission=PERMISSIONS.get(permission, _('unknown')), resource=resource)) else: logger.debug('no match for space, ignore') return
def __init__(self, *panels, **kwargs): self.app = None self.panels = [] self.breadcrumb_items = {} self.setup_blueprint() self.nav_root = NavGroup( 'admin', 'root', title=_l(u'Admin'), endpoint=None, condition=lambda context: (not current_user.is_anonymous() and security.has_role(current_user, AdminRole)) ) for panel in panels: self.register_panel(panel) app = kwargs.pop('app', None) if app is not None: self.init_app(app)
def check_password_length(form, field): if len(field.data) < 5: raise ValidationError(_l('Password must at least 6 characters'))
def username_exists(form, field): if not User.by_email(field.data): raise ValidationError(_l('email does not exist.'))
def username_unique(form, field): if User.by_email(field.data): raise ValidationError(_l('email already exists.'))
class WFSSearchForm(Form): wfs_serach_layer = QuerySelectField(_l('select coverage'), [validators.Required()], query_factory=query_all_wfs, get_label=lambda a: ('%s (%s)' % (a.name, a.search_property)), get_pk=lambda a: a.name)
class CopyFileForm(Form): filename = TextField(_l('filename'), [validators.Required()]) boxes = QuerySelectField(_l('select target user'), [validators.Required()], query_factory=query_all_user_boxes, get_label='email')
import logging from collections import Container from functools import wraps from flask import abort from flask.ext.login import current_user from flask.ext.babel import gettext as _, lazy_gettext as _l from gasoline.services.base import Service __all__ = ['ACLService'] logger = logging.getLogger('gasoline') PERMISSIONS = { 'read': _l('read'), 'write': _l('write'), 'delete': _l('delete'), 'write.comments': _l('write comments'), 'write.attachments': _l('write attachments'), } class ACLService(Service): name = 'acl' def init_app(self, app): """intialise ACL service with flask configuration""" super(ACLService, self).init_app(app) def apply(self, permission, acl, resource=_l('resource')):
""" args, kwargs = super(ObjectView, self).prepare_args(args, kwargs) self.form = self.Form(**self.get_form_kwargs()) return args, kwargs def get_form_kwargs(self): return dict(obj=self.obj) def index_url(self): return url_for('.index') def redirect_to_index(self): return redirect(self.index_url()) CANCEL_BUTTON = ButtonAction('form', 'cancel', title=_l(u'Cancel')) EDIT_BUTTON = ButtonAction('form', 'edit', btn_class='primary', title=_l(u'Save')) class ObjectEdit(ObjectView): """ Edit objects """ template = 'default/object_edit.html' #: :class:ButtonAction instance to show on form _buttons = () #: submitted form data data = None
def validate_view_level_end(form, field): if form.data['view_level_start'] > field.data: raise validators.ValidationError(_l('level needs to be bigger or equal to start level'))
class LoginForm(Form): login = StringField(_l('Login'), validators=[DataRequired()]) password = PasswordField(_l('Password')) next = HiddenField()
class RemoveUserForm(Form): password = PasswordField(_l('password'), [validators.Required()])
class EditPasswordForm(RecoverSetForm): old_password = PasswordField(_l('old password'), [validators.Required()])
class EditAddressForm(Form): title = SelectField( _l('title'), [validators.Required()], choices=[ ] # at the moment choices are set on view, because we load they from config ) lastname = TextField(_l('lastname'), [validators.Required()]) firstname = TextField(_l('firstname'), [validators.Required()]) address = TextField(_l('address'), [validators.Required()]) address_extend = TextField(_l('address_extend')) company_name = TextField(_l('company_name')) zipcode = TextField(_l('zipcode'), [validators.Required()]) city = TextField(_l('city'), [validators.Required()]) federal_state = TextField(_l('federal_state')) federal_state = SelectField( _l('federal_state'), [validators.Required()], choices=[ ] # at the moment choices are set on view, because we load they from config ) phone = TextField(_l('phone')) fax = TextField(_l('fax')) # only used for customers number has 10-16 characters company_number = TextField(_l('company_number'), # [validators.Length(min=10, max=16)] ) # only used for service_provider commercial_register_number = TextField(_l('commercial_register_number'))
class LoginForm(Form): email = TextField(_l('email'), [validators.Required(), validators.Email()]) password = PasswordField(_l('password'), [validators.Required()])
class DefaultConfig(object): """ Default configuration """ TESTING = False DEBUG = True # config for pagination USER_PER_PAGE = 20 WTF_I18N_ENABLED = True SESSION_COOKIE_NAME = 'gbi_server_session' # allow access to admin URLs without authentication # (e.g. for testing with curl) ADMIN_PARTY = False # change this in your production settings !!! SECRET_KEY = "verysecret" # keys for localhost. Change as appropriate. SQLALCHEMY_DATABASE_URI = 'postgresql://*****:*****@127.0.0.1:5432/igreen' SQLALCHEMY_ECHO = False # from warning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. # TODO check if tracking is required SQLALCHEMY_TRACK_MODIFICATIONS = True ACCEPT_LANGUAGES = ['de'] ASSETS_DEBUG = True ASSETS_BUNDLES_CONF = p.join(p.dirname(__file__), 'asset_bundles.yaml') LOG_DIR = p.abspath(p.join(p.dirname(__file__), '../../var/log')) DEBUG_LOG = 'debug.log' ERROR_LOG = 'error.log' CACHE_TYPE = "simple" CACHE_DEFAULT_TIMEOUT = 300 BCRYPT_LOG_ROUNDS = 10 MAIL_SERVER = "localhost" MAIL_USERNAME = '******' MAIL_PASSWORD = '******' MAIL_DEBUG = DEBUG MAIL_DEFAULT_SENDER = "GeoBox Server <*****@*****.**>" MAIL_FOOTER = ''' -- Internet: https://example.org E-Mail: [email protected] ''' TINYOWS_NAME = "TinyOWS Server" TINYOWS_TITLE = "TinyOWS Server - Demo Service" TINYOWS_BIN = "/usr/local/bin/tinyows" TINYOWS_SCHEMA_DIR = "/usr/local/share/tinyows/schema/" TINYOWS_LOG_FILE = "/tmp/tinyows.log" TINYOWS_LOG_LEVEL = "7" TINYOWS_NS_PREFIX = "tows" TINYOWS_NS_URI = "http://www.tinyows.org/" TINYOWS_TMP_CONFIG_DIR = "/tmp/tinyows" TEMP_PG_HOST = "127.0.0.1" TEMP_PG_DB = "wfs_tmp" TEMP_PG_USER = "******" TEMP_PG_PASSWORD = "******" TEMP_PG_PORT = "5432" # remove this one if we remove the editor completly USER_READONLY_LAYER = "florlp" USER_WORKON_LAYER = "baselayer" COUCH_DB_URL = "http://127.0.0.1:5984" # user name and password for db admin that is allowed to # create new user boxes COUCH_DB_ADMIN_USER = '******' COUCH_DB_ADMIN_PASSWORD = '******' PARCEL_SEARCH_DATABASE_URI = '' PARCEL_SEARCH_DATABASE_SRID = 25832 PARCEL_SEARCH_DATABASE_ECHO = False PARCEL_SEARCH_USE_DUMMY_DATA = False AUTHPROXY_CACHE_DIR = "/tmp/authproxy" MAPPROXY_SRS = ['EPSG:25832'] MAPPROXY_YAML_DIR = "/tmp/" GBI_CLIENT_DOWNLOAD_URL = "http://download.omniscale.de/geobox/dist/setup-geobox-0.2.7.exe" STATIC_PAGES_DIR = p.join(p.dirname(__file__), '..', 'pages') USERMANUAL_URL = 'usermanual-gbi-server.pdf' # enable/disable document boxes (CUSTOMER/CONSULTANT) FEATURE_DOC_BOXES = True # enable/disable area boxes FEATURE_AREA_BOXES = True # enable WFS editor FEATURE_EDITOR = True # allow CUSTOMER accounts FEATURE_CUSTOMER_USERS = True # allow CONSULTANT accounts FEATURE_CONSULTANT_USERS = True SALUTATIONS = [ ('mr', _l(u'mr')), ('mrs', _l(u'mrs')), ] FEDERAL_STATES = [ ('BW', _l(u'Baden-Wuerttemberg')), ('BY', _l(u'Bavaria')), ('BE', _l(u'Berlin')), ('BB', _l(u'Brandenburg')), ('HB', _l(u'Bremen')), ('HH', _l(u'Hamburg')), ('HE', _l(u'Hesse')), ('MV', _l(u'Mecklenburg Western Pomerania')), ('NI', _l(u'Lower Saxony')), ('NW', _l(u'Northrhine-Westphalia')), ('RP', _l(u'Rhineland Palatinate')), ('SL', _l(u'Saarland')), ('SN', _l(u'Saxony')), ('ST', _l(u'Saxony-Anhalt')), ('SH', _l(u'Schleswig Holstein')), ('TH', _l(u'Thuringia')), ] PORTAL_PREFIX = "DEFAULT" PORTAL_TITLE = "Unconfigured GeoBox-Server" LOG_CSV_HEADER = [ "time", "action", "format", "srs", "mapping", "source", "layer", "zoom_level_start", "zoom_level_end", "refreshed", "geometry_as_geojson" ] TILE_PROXY_URLS = [ ( re.compile( 'http://igreendemo.omniscale.net/wmts/(?P<layer>[^/]+)/GoogleMapsCompatible-(?P<z>[^/]+)-(?P<x>[^/]+)-(?P<y>[^/]+)/tile$' ), 'http://igreendemo.omniscale.net/wmts/%(layer)s/GoogleMapsCompatible-%(z)s-%(x)s-%(y)s/tile' # 'http://localhost:8099/%(layer)s/GoogleMapsCompatible-%(z)s-%(x)s-%(y)s/tile' ), ]
class NewUserForm(Form): login = StringField(_l('Login'), validators=[DataRequired()]) password = PasswordField(_l('Password'), validators=[DataRequired()])
class WMSForm(RasterSourceForm): version = SelectField(_l('wms_version'), choices=[('1.1.1', '1.1.1'), ('1.3.0', '1.3.0')], validators=[validators.Required()])
class CommentForm(Form): post = IntegerField(widget=HiddenInput()) comment = TextAreaField(_l('Leave a comment'), validators=[DataRequired()])
class UploadForm(Form): file = FileField(_l('file'), [validators.Required()]) overwrite = HiddenField('overwrite', default=False)
class WFSAddLayerForm(Form): def is_submitted(self): return request and request.method in ("PUT", "POST") and request.form.get('add_form') new_layer = TextField(_l('wfs_new_layer_name'), validators=[validators.Required(),]) add_form = HiddenField()
class RecoverRequestForm(Form): email = TextField( _l('email'), [validators.Required(), username_exists, validators.Email()])
def display_form(): form = SDCApplicationForm() page = dict(title=_l(u"Candidature pour la Student Demo Cup")) return render_template("sdc/form.html", page=page, form=form)
# -*- coding: utf-8 -*- """ Based on: Activity Stream Specs: http://activitystrea.ms/specs/json/1.0/ """ from datetime import datetime from gasoline.core.extensions import db from flask.ext.babel import gettext as _, lazy_gettext as _l ACTIONS = { 'create': { 'page': _l('create page'), 'event': _l('create event'), 'issue': _l('create issue'), 'task': _l('create task'), }, 'update': { 'page': _l('update page'), }, 'remove': { 'page': _l('remove page'), }, 'attach': { 'file': _l('attach file'), }, 'add': { 'comment': _l('comment'), },
class RasterSourceForm(Form): url = TextField(_l('rastersource_url'), [validators.Required()]) username = TextField(_l('rastersource_username')) password = PasswordField(_l('rastersource_password')) name = TextField(_l('rastersource_name'), [validators.Required(), validators.Regexp('[a-z0-9_-]+$')]) title = TextField(_l('rastersource_title'), [validators.Required()]) layer = TextField(_l('rastersource_layer'), [validators.Required()]) format = SelectField(_l('rastersource_format'), [validators.Required()], choices=[('png', 'png'), ('jpeg', 'jpeg')]) srs = TextField(_l('rastersource_srs'), [validators.Required()]) max_tiles = TextField(_l('rastersource_max_tiles'), [validators.Regexp('^\d*$')]) view_coverage = TextAreaField(_l('rastersource_view_coverage'), [validators.Required()]) #XXX kai: geojson validator? view_level_start = SelectField(_l('rastersource_view_level_start'), coerce=int, choices=[(x, x) for x in range(20)]) view_level_end = SelectField(_l('rastersource_view_level_end'), coerce=int, choices=[(x, x) for x in range(20)]) is_background_layer = BooleanField(_l('rastersource_background_layer')) is_transparent = BooleanField(_l('rastersource_transparent')) is_visible = BooleanField(_l('rastersource_visibility')) is_public = BooleanField(_l('rastersource_public')) is_accessible = BooleanField(_l('rastersource_accessible')) is_protected = BooleanField(_l('rastersource_protected')) def validate_view_level_end(form, field): if form.data['view_level_start'] > field.data: raise validators.ValidationError(_l('level needs to be bigger or equal to start level'))