From: philipp Date: Thu, 27 Jul 2017 22:01:24 +0000 (+0000) Subject: Delete unused files. X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wradmin.git/commitdiff_plain/ce9338754783a42cc48df560055b39e801384fd3 Delete unused files. git-svn-id: http://www.winterrodeln.org/svn/wradmin/trunk@2677 7aebc617-e5e2-0310-91dc-80fb5f6d2477 --- diff --git a/wradmin/config/routing.py b/wradmin/config/routing.py deleted file mode 100644 index 583a50b..0000000 --- a/wradmin/config/routing.py +++ /dev/null @@ -1,54 +0,0 @@ -"""Routes configuration - -The more specific and detailed routes should be defined first so they -may take precedent over the more generic routes. For more information -refer to the routes manual at http://routes.groovie.org/docs/ - - -Proposal for Winterrodeln URL schema: - -bahnen.winterrodeln.org/kemater_alm => www.winterrodeln.org/wiki/Kemater_Alm -huetten.winterrodeln.org/kemater_alm => www.winterrodeln.org/wiki/Kemater_Alm_(Gasthaus) - -www.winterrodeln.org/wiki ... handled by apache/mediawiki -www.winterrodeln.org/feeds/berichte/alle -www.winterrodeln.org/feeds/berichte/region/tirol -www.winterrodeln.org/feeds/berichte/bahn/kemater_alm -www.winterrodeln.org/wradmin/ -www.winterrodeln.org/wrapp/ -www.winterrodeln.org/app/bericht/list -www.winterrodeln.org/app/bericht/new -www.winterrodeln.org/app/bericht/5360 -www.winterrodeln.org/app/bericht/5360/edit -www.winterrodeln.org/app/bahn/list -www.winterrodeln.org/app/bahn/new -www.winterrodeln.org/app/bahn/3480 -www.winterrodeln.org/app/bahn/3480/edit -www.winterrodeln.org/app/user -www.winterrodeln.org/mobile/ -www.winterrodeln.org/xml/ -www.winterrodeln.org/feed/ - - -""" -from routes import Mapper - -def make_map(config): - """Create, configure and return the routes Mapper""" - map = Mapper(directory=config['pylons.paths']['controllers'], - always_scan=config['debug']) - map.minimization = False - map.explicit = False - - # The ErrorController route (handles 404/500 error pages); it should - # likely stay at the top, ensuring it can always be resolved - map.connect('/error/{action}', controller='error') - map.connect('/error/{action}/{id}', controller='error') - - # CUSTOM ROUTES HERE - - map.connect('/', controller='rodelbahn', action='index') - map.connect('/{controller}/{action}') - map.connect('/{controller}/{action}/{id}') - - return map diff --git a/wradmin/lib/helpers.py b/wradmin/lib/helpers.py deleted file mode 100644 index 3e0247c..0000000 --- a/wradmin/lib/helpers.py +++ /dev/null @@ -1,48 +0,0 @@ -"""Helper functions - -Consists of functions to typically be used within templates, but also -available to Controllers. This module is available to templates as 'h'. -""" -# Import helpers as desired, or define your own, ie: -#from webhelpers.html.tags import checkbox, password - -from pylons import url -import wrpylib.wrvalidators -from webhelpers.html.tags import file, form, end_form, submit - -def wiki(page_title=None): - "Creates a link to the specified page in the www.winterrodeln.org wiki" - if page_title is None: page_title = 'Hauptseite' - return 'http://www.winterrodeln.org/wiki/' + page_title - - -def forum(forum=None): - "Creates a link to the specified forum. If no id is given, a general link is created." - if forum is None: return 'http://winterrodeln-forum.org/' - return 'http://winterrodeln-forum.org/viewforum.php?f=%d' % forum - - -def google_maps(latitude, longitude): - "Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007" - return "http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude) - - -def bool(value): - "Takes a bool value and creates a German representation" - return wrpylib.wrvalidators.GermanBoolNone().from_python(value) - - -def tristate_tuple(yes, no): - "Takes a German representation of a tristate value" - return wrpylib.wrvalidators.GermanTristateTuple().from_python((yes, no)) - - -def tristate_float(value): - "Takes a German representation of a tristate value" - return wrpylib.wrvalidators.GermanTristateFloat().from_python(value) - - -def public_transport(value): - if isinstance(value, int): value = int(value) - return wrpylib.wrvalidators.GermanPublicTransport().from_python(value) - diff --git a/wradmin/model/validators.py b/wradmin/model/validators.py deleted file mode 100644 index dd92176..0000000 --- a/wradmin/model/validators.py +++ /dev/null @@ -1,705 +0,0 @@ -#!/usr/bin/python3.4 -"""This file contains "validators" that convert between string and python (database) representation -of properties used in the "Rodelbahnbox" and "Gasthausbox". -The "to_python" method has to get a unicode argument. -You can run tests with ->>> nosetests --with-pylons=test.ini - -TODO: Replace by wrpylib.wrvalidators -""" -import formencode -import formencode.national -import datetime -import re -import xml.dom.minidom as minidom -from xml.parsers.expat import ExpatError - - -class NoneValidator(formencode.FancyValidator): - """Takes a validator and makes it possible that empty strings are mapped to None.""" - def __init__(self, validator, python_none=None): - self.validator = validator - self.python_none = python_none - - def to_python(self, value): - self.assert_string(value, None) - if value == '': return self.python_none - return self.validator.to_python(value) - - def from_python(self, value): - if value == self.python_none: return '' - return self.validator.from_python(value) - - -class NeinValidator(formencode.FancyValidator): - """Take an arbitrary validator and adds the possibility that the - string can be u'Nein'. - Example together with an UnsignedNone validator: - >>> v = NeinValidator(UnsignedNone()) - >>> v.to_python(u'') - None - >>> v.to_python(u'34') - 34 - >>> v.to_python(u'Nein') - u'Nein' - """ - def __init__(self, validator, python_no='Nein'): - self.validator = validator - self.python_no = python_no - - def to_python(self, value): - self.assert_string(value, None) - if value == 'Nein': return self.python_no - return self.validator.to_python(value) - - def from_python(self, value): - if value == self.python_no: return 'Nein' - return self.validator.from_python(value) - - -class Unicode(formencode.FancyValidator): - """Converts an unicode string to an unicode string: - u'any string' <=> u'any string'""" - def to_python(self, value): - self.assert_string(value, None) - return str(value) - - def from_python(self, value): - return str(value) - - -class UnicodeNone(NoneValidator): - """Converts an unicode string to an unicode string: - u'' <=> None - u'any string' <=> u'any string'""" - def __init__(self): - NoneValidator.__init__(self, Unicode()) - - -class Unsigned(formencode.FancyValidator): - """Converts an unsigned number to a string and vice versa: - u'0' <=> 0 - u'1' <=> 1 - u'45' <=> 45 - """ - def __init__(self, max=None): - self.iv = formencode.validators.Int(min=0, max=max) - - def to_python(self, value): - self.assert_string(value, None) - return self.iv.to_python(value) - - def from_python(self, value): - return str(value) - - -class UnsignedNone(NoneValidator): - """Converts an unsigned number to a string and vice versa: - u'' <=> None - u'0' <=> 0 - u'1' <=> 1 - u'45' <=> 45 - """ - def __init__(self, max=None): - NoneValidator.__init__(self, Unsigned(max)) - - -class UnsignedNeinNone(NoneValidator): - """ Translates a number of Nein to a number. - u'' <=> None - u'Nein' <=> 0 - u'1' <=> 1 - u'2' <=> 2 - ... - """ - def __init__(self): - NoneValidator.__init__(self, UnsignedNone()) - - -class Loop(formencode.FancyValidator): - """Takes a validator and calls from_python(to_python(value)).""" - def __init__(self, validator): - self.validator = validator - - def to_python(self, value): - self.assert_string(value, None) - return self.validator.from_python(self.validator.to_python(value)) - - def from_python(self, value): - # we don't call self.validator.to_python(self.validator.from_python(value)) - # here because our to_python implementation basically leaves the input untouches - # and so should from_python do. - return self.validator.from_python(self.validator.to_python(value)) - - -class DictValidator(formencode.FancyValidator): - """Translates strings to other values via a python directory. - >>> boolValidator = DictValidator({u'': None, u'Ja': True, u'Nein': False}) - >>> boolValidator.to_python(u'') - None - >>> boolValidator.to_python(u'Ja') - True - """ - def __init__(self, dict): - self.dict = dict - - def to_python(self, value): - self.assert_string(value, None) - if value not in self.dict: raise formencode.Invalid("Key not found in dict.", value, None) - return self.dict[value] - - def from_python(self, value): - for k, v in self.dict.items(): - if type(v) == type(value) and v == value: return k - raise formencode.Invalid('Invalid value', value, None) - - -class GermanBoolNone(DictValidator): - """Converts German bool values to the python bool type: - u'' <=> None - u'Ja' <=> True - u'Nein' <=> False - """ - def __init__(self): - DictValidator.__init__(self, {'': None, 'Ja': True, 'Nein': False}) - - -class GermanTristateTuple(DictValidator): - """Does the following conversion: - u'' <=> (None, None) - u'Ja' <=> (True, False) - u'Teilweise' <=> (True, True) - u'Nein' <=> (False, True)""" - def __init__(self, yes_python = (True, False), no_python = (False, True), partly_python = (True, True), none_python = (None, None)): - DictValidator.__init__(self, {'': none_python, 'Ja': yes_python, 'Nein': no_python, 'Teilweise': partly_python}) - - -class GermanTristateFloat(GermanTristateTuple): - """Converts the a property with the possible values 0.0, 0.5, 1.0 or None - to a German text: - u'' <=> None - u'Ja' <=> 1.0 - u'Teilweise' <=> 0.5 - u'Nein' <=> 0.0""" - def __init__(self): - GermanTristateTuple.__init__(self, yes_python=1.0, no_python=0.0, partly_python=0.5, none_python=None) - - -class ValueComment(formencode.FancyValidator): - """Converts value with a potentially optional comment to a python tuple: - u'' <=> (None, None) - u'value' <=> (u'value', None) - u'value (comment)' <=> (u'value', u'comment')""" - def __init__(self, value_validator=UnicodeNone(), comment_validator=UnicodeNone(), comment_is_optional=True): - self.value_validator = value_validator - self.comment_validator = comment_validator - self.comment_is_optional = comment_is_optional - - def to_python(self, value): - self.assert_string(value, None) - if value == '': - v = value - c = value - else: - left = value.find('(') - right = value.rfind(')') - if left < 0 and right < 0: - if not self.comment_is_optional: raise formencode.Invalid('Mandatory comment not present', value, None) - v = value - c = '' - elif left >= 0 and right >= 0 and left < right: - v = value[:left].strip() - c = value[left+1:right].strip() - else: raise formencode.Invalid('Invalid format', value, None) - return self.value_validator.to_python(v), self.comment_validator.to_python(c) - - def from_python(self, value): - assert len(value) == 2 - v = self.value_validator.from_python(value[0]) - c = self.comment_validator.from_python(value[1]) - if len(c) > 0: - if len(v) > 0: return '%s (%s)' % (v, c) - else: return '(%s)' % c - return v - - -class SemicolonList(formencode.FancyValidator): - """Applies a given validator to a semicolon separated list of values and returns a python list. - For an empty string an empty list is returned.""" - def __init__(self, validator=Unicode()): - self.validator = validator - - def to_python(self, value): - self.assert_string(value, None) - return [self.validator.to_python(s.strip()) for s in value.split(';')] - - def from_python(self, value): - return "; ".join([self.validator.from_python(s) for s in value]) - - -class ValueCommentList(SemicolonList): - """A value-comment list looks like one of the following lines: - value - value (optional comment) - value1; value2 - value1; value2 (optional comment) - value1 (optional comment1); value2 (optional comment2); value3 (otional comment3) - value1 (optional comment1); value2 (optional comment2); value3 (otional comment3) - This function returns the value-comment list as list of tuples: - [(u'value1', u'comment1'), (u'value2', None)] - If no comment is present, None is specified. - For an empty string, [] is returned.""" - def __init__(self, value_validator=Unicode(), comments_are_optional=True): - SemicolonList.__init__(self, ValueComment(value_validator, comment_is_optional=comments_are_optional)) - - -class GenericDateTime(formencode.FancyValidator): - """Converts a generic date/time information to a datetime class with a user defined format. - '2009-03-22 20:36:15' would be specified as '%Y-%m-%d %H:%M:%S'.""" - - def __init__(self, date_time_format = '%Y-%m-%d %H:%M:%S', **keywords): - formencode.FancyValidator.__init__(self, **keywords) - self.date_time_format = date_time_format - - def to_python(self, value, state=None): - self.assert_string(value, None) - try: return datetime.datetime.strptime(value, self.date_time_format) - except ValueError as e: raise formencode.Invalid(str(e), value, None) - - def from_python(self, value, state=None): - return value.strftime(self.date_time_format) - - -class DateTimeNoSec(GenericDateTime): - def __init__(self, **keywords): - GenericDateTime.__init__(self, '%Y-%m-%d %H:%M', **keywords) - - -class DateNone(NoneValidator): - """Converts date information to date classes with the format '%Y-%m-%d' or None.""" - def __init__(self): - NoneValidator.__init__(self, GenericDateTime('%Y-%m-%d')) - - -class Geo(formencode.FancyValidator): - """Formats to coordinates '47.076207 N 11.453553 E' to the (latitude, longitude) tuplet.""" - def to_python(self, value): - self.assert_string(value, None) - r = re.match('(\d+\.\d+) N (\d+\.\d+) E', value) - if r is None: raise formencode.Invalid("Coordinates '%s' have not a format like '47.076207 N 11.453553 E'" % value, value, None) - return (float(r.groups()[0]), float(r.groups()[1])) - - def from_python(self, value): - latitude, longitude = value - return '%.6f N %.6f E' % (latitude, longitude) - - -class GeoNone(NoneValidator): - """Formats to coordinates '47.076207 N 11.453553 E' to the (latitude, longitude) tuplet.""" - def __init__(self): - NoneValidator.__init__(self, Geo(), (None, None)) - - -class MultiGeo(formencode.FancyValidator): - "Formats multiple coordinates, even in multiple lines to [(latitude, longitude, elevation), ...] or [(latitude, longitude, None), ...] tuplets." - - # Valid for input_format - FORMAT_GUESS = 0 # guesses the input format; default for input_format - FORMAT_NONE = -1 # indicates missing formats - - # Valid for input_format and output_format - FORMAT_GEOCACHING = 1 # e.g. "N 47° 13.692 E 011° 25.535" - FORMAT_WINTERRODELN = 2 # e.g. "47.222134 N 11.467211 E" - FORMAT_GMAPPLUGIN = 3 # e.g. "47.232922, 11.452239" - FORMAT_GPX = 4 # e.g. "1090.57" - - input_format = FORMAT_GUESS - output_format = FORMAT_WINTERRODELN - last_input_format = FORMAT_NONE - - def __init__(self, input_format = FORMAT_GUESS, output_format = FORMAT_WINTERRODELN, **keywords): - self.input_format = input_format - self.output_format = output_format - formencode.FancyValidator.__init__(self, if_empty = (None, None, None), **keywords) - - def to_python(self, value): - self.assert_string(value, None) - input_format = self.input_format - if not input_format in [self.FORMAT_GUESS, self.FORMAT_GEOCACHING, self.FORMAT_WINTERRODELN, self.FORMAT_GMAPPLUGIN, self.FORMAT_GPX]: - raise formencode.Invalid("input_format %d is not recognized" % input_format, value, None) # Shouldn't it be an other type of runtime error? - lines = [line.strip() for line in value.split("\n") if len(line.strip()) > 0] - - result = [] - for line in lines: - if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_GEOCACHING: - r = re.match('N ?(\d+)° ?(\d+\.\d+) +E ?(\d+)° ?(\d+\.\d+)', line) - if not r is None: - g = r.groups() - result.append((float(g[0]) + float(g[1])/60, float(g[2]) + float(g[3])/60, None)) - last_input_format = self.FORMAT_WINTERRODELN - continue - - if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_WINTERRODELN: - r = re.match('(\d+\.\d+) N (\d+\.\d+) E', line) - if not r is None: - result.append((float(r.groups()[0]), float(r.groups()[1]), None)) - last_input_format = self.FORMAT_WINTERRODELN - continue - - if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_GMAPPLUGIN: - r = re.match('(\d+\.\d+), ?(\d+\.\d+)', line) - if not r is None: - result.append((float(r.groups()[0]), float(r.groups()[1]), None)) - last_input_format = self.FORMAT_GMAPPLUGIN - continue - - if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_GPX: - try: - xml = minidom.parseString(line) - coord = xml.documentElement - lat = float(coord.getAttribute('lat')) - lon = float(coord.getAttribute('lon')) - try: ele = float(coord.childNodes[0].childNodes[0].nodeValue) - except (IndexError, ValueError): ele = None - result.append((lat, lon, ele)) - last_input_format = self.FORMAT_GPX - continue - except (ExpatError, IndexError, ValueError): pass - - raise formencode.Invalid("Coordinates '%s' have no known format" % line, value, None) - - return result - - def from_python(self, value): - output_format = self.output_format - result = [] - for latitude, longitude, height in value: - if output_format == self.FORMAT_GEOCACHING: - degree = latitude - result.append('N %02d° %02.3f E %03d° %02.3f' % (latitude, latitude % 1 * 60, longitude, longitude % 1 * 60)) - - elif output_format == self.FORMAT_WINTERRODELN: - result.append('%.6f N %.6f E' % (latitude, longitude)) - - elif output_format == self.FORMAT_GMAPPLUGIN: - result.append('%.6f, %.6f' % (latitude, longitude)) - - elif output_format == self.FORMAT_GPX: - if not height is None: result.append('%.2f' % (latitude, longitude, height)) - else: result.append('' % (latitude, longitude)) - - else: - raise formencode.Invalid("output_format %d is not recognized" % output_format, value, None) # Shouldn't it be an other type of runtime error? - - return "\n".join(result) - - -# deprecated -class AustrianPhoneNumber(formencode.FancyValidator): - """ - Validates and converts phone numbers to +##/###/####### or +##/###/#######-### (having an extension) - @param default_cc country code for prepending if none is provided, defaults to 43 (Austria) - :: - >>> v = AustrianPhoneNumber() - >>> v.to_python(u'0512/12345678') - u'+43/512/12345678' - >>> v.to_python(u'+43/512/12345678') - u'+43/512/12345678' - >>> v.to_python(u'0512/1234567-89') # 89 is the extension - u'+43/512/1234567-89' - >>> v.to_python(u'+43/512/1234567-89') - u'+43/512/1234567-89' - >>> v.to_python(u'0512 / 12345678') # Exception - >>> v.to_python(u'0512-12345678') # Exception - """ - # Inspired by formencode.national.InternationalPhoneNumber - - default_cc = 43 # Default country code - messages = {'phoneFormat': "'%%(value)s' is an invalid format. Please enter a number in the form +43/###/####### or 0###/########."} - - def to_python(self, value): - self.assert_string(value, None) - m = re.match('^(?:\+(\d+)/)?([\d/]+)(?:-(\d+))?$', value) - # This will separate - # u'+43/512/1234567-89' => (u'43', u'512/1234567', u'89') - # u'+43/512/1234/567-89' => (u'43', u'512/1234/567', u'89') - # u'+43/512/1234/567' => (u'43', u'512/1234/567', None) - # u'0512/1234567' => (None, u'0512/1234567', None) - if m is None: raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, None) - (country, phone, extension) = m.groups() - - # Phone - if phone.find('//') > -1 or phone.count('/') == 0: raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, None) - - # Country - if country is None: - if phone[0] != '0': raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, None) - phone = phone[1:] - country = str(self.default_cc) - - if extension is None: return '+%s/%s' % (country, phone) - return '+%s/%s-%s' % (country, phone, extension) - - -# Deprecated -class AustrianPhoneNumberNone(NoneValidator): - def __init__(self): - NoneValidator.__init__(self, AustrianPhoneNumber()) - - -# Deprecated -class AustrianPhoneNumberCommentLoop(NoneValidator): - def __init__(self): - NoneValidator.__init__(self, Loop(ValueComment(AustrianPhoneNumber()))) - - -class GermanDifficulty(DictValidator): - """Converts the difficulty represented in a number from 1 to 3 (or None) - to a German representation: - u'' <=> None - u'leicht' <=> 1 - u'mittel' <=> 2 - u'schwer' <=> 3""" - def __init__(self): - DictValidator.__init__(self, {'': None, 'leicht': 1, 'mittel': 2, 'schwer': 3}) - - -class GermanAvalanches(DictValidator): - """Converts the avalanches property represented as number from 1 to 4 (or None) - to a German representation: - u'' <=> None - u'kaum' <=> 1 - u'selten' <=> 2 - u'gelegentlich' <=> 3 - u'häufig' <=> 4""" - def __init__(self): - DictValidator.__init__(self, {'': None, 'kaum': 1, 'selten': 2, 'gelegentlich': 3, 'häufig': 4}) - - -class GermanPublicTransport(DictValidator): - """Converts the public_transport property represented as number from 1 to 6 (or None) - to a German representation: - u'' <=> None - u'Sehr gut' <=> 1 - u'Gut' <=> 2 - u'Mittelmäßig' <=> 3 - u'Schlecht' <=> 4 - u'Nein' <=> 5 - u'Ja' <=> 6""" - def __init__(self): - DictValidator.__init__(self, {'': None, 'Sehr gut': 1, 'Gut': 2, 'Mittelmäßig': 3, 'Schlecht': 4, 'Nein': 5, 'Ja': 6}) - - -class GermanTristateFloatComment(ValueComment): - """Converts the a property with the possible values 0.0, 0.5, 1.0 or None and an optional comment - in parenthesis to a German text: - u'' <=> (None, None) - u'Ja' <=> (1.0, None) - u'Teilweise' <=> (0.5, None) - u'Nein' <=> (0.0, None) - u'Ja (aber schmal)' <=> (1.0, u'aber schmal') - u'Teilweise (oben)' <=> (0.5, u'oben') - u'Nein (aber breit)' <=> (0.0, u'aber breit') - """ - def __init__(self): - ValueComment.__init__(self, GermanTristateFloat()) - - -class UnsignedCommentNone(NoneValidator): - """Converts the a property with unsigned values an optional comment - in parenthesis to a text: - u'' <=> (None, None) - u'2 (Mo, Di)' <=> (2, u'Mo, Di') - u'7' <=> (7, None) - u'0' <=> (0, None) - """ - def __init__(self, max=None): - NoneValidator.__init__(self, ValueComment(Unsigned(max=max)), (None, None)) - - -class GermanCachet(formencode.FancyValidator): - """Converts a "Gütesiegel": - u'' <=> None - u'Nein' <=> 'Nein' - u'Tiroler Naturrodelbahn-Gütesiegel 2009 mittel' <=> u'Tiroler Naturrodelbahn-Gütesiegel 2009 mittel'""" - def to_python(self, value): - self.assert_string(value, None) - if value == '': return None - elif value == 'Nein': return value - elif value.startswith('Tiroler Naturrodelbahn-Gütesiegel '): - p = value.split(" ") - Unsigned().to_python(p[2]) # check if year can be parsed - if not p[3] in ['leicht', 'mittel', 'schwer']: raise formencode.Invalid("Unbekannter Schwierigkeitsgrad", value, None) - return value - else: raise formencode.Invalid("Unbekanntes Gütesiegel", value, None) - - def from_python(self, value): - if value == None: return '' - assert value != '' - return self.to_python(self, value) - - -class Url(formencode.FancyValidator): - """Validates an URL. In contrast to fromencode.validators.URL, umlauts are allowed.""" - urlv = formencode.validators.URL() - def to_python(self, value): - self.assert_string(value, None) - v = value - v = v.replace('ä', 'a') - v = v.replace('ö', 'o') - v = v.replace('ü', 'u') - v = v.replace('ß', 'ss') - v = self.urlv.to_python(v) - return value - - def from_python(self, value): - return value - - -class UrlNeinNone(NoneValidator): - """Validates an URL. In contrast to fromencode.validators.URL, umlauts are allowed. - The special value u"Nein" is allowed.""" - def __init__(self): - NoneValidator.__init__(self, NeinValidator(Url())) - - -class ValueCommentListNeinLoopNone(NoneValidator): - """Translates a semicolon separated list of values with optional comments in paranthesis or u'Nein' to itself. - An empty string is translated to None: - u'' <=> None - u'Nein' <=> u'Nein' - u'T-Mobile (gut); A1' <=> u'T-Mobile (gut); A1'""" - def __init__(self): - NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList()))) - - -class PhoneNumber(formencode.FancyValidator): - """Telefonnumber in international format, e.g. u'+43-699-1234567'""" - def __init__(self, default_cc=43): - self.validator = formencode.national.InternationalPhoneNumber(default_cc=lambda: default_cc) - - def to_python(self, value): - return str(self.validator.to_python(value)) - - def from_python(self, value): - return self.validator.from_python(value) - - -class PhoneCommentListNeinLoopNone(NoneValidator): - """List with semicolon-separated phone numbers in international format with optional comment or 'Nein' as string: - u'' <=> None - u'Nein' <=> u'Nein' - u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456' <=> u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456' - """ - def __init__(self, comments_are_optional): - NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(PhoneNumber(default_cc=43), comments_are_optional=comments_are_optional)))) - - -class EmailCommentListNeinLoopNone(NoneValidator): - """Converts a semicolon-separated list of email addresses with optional comments to itself. - The special value of u'Nein' indicates that there are no email addresses. - The empty string translates to None: - u'' <=> None - u'Nein' <=> u'Nein' - u'first@example.com' <=> u'first@example.com' - u'first@example.com (Nur Winter); second@example.com' <=> u'first@example.com (Nur Winter); second@example.com' - """ - def __init__(self): - NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(formencode.validators.Email())))) - - -class WikiPage(formencode.FancyValidator): - """Validates wiki page name like u'[[Birgitzer Alm]]'. - The page is not checked for existance. - An empty string is an error. - u'[[Birgitzer Alm]]' <=> u'[[Birgitzer Alm]]' - """ - def to_python(self, value): - self.assert_string(value, None) - if not value.startswith('[[') or not value.endswith(']]'): - raise formencode.Invalid('No valid wiki page name', value, None) - return value - - def from_python(self, value): - return value - - -class WikiPageList(SemicolonList): - """Validates a list of wiki pages like u'[[Birgitzer Alm]]; [[Kemater Alm]]'. - u'[[Birgitzer Alm]]; [[Kemater Alm]]' <=> [u'[[Birgitzer Alm]]', u'[[Kemater Alm]]'] - u'[[Birgitzer Alm]]' <=> [u'[[Birgitzer Alm]]'] - u'' <=> [] - """ - def __init__(self): - SemicolonList.__init__(self, WikiPage()) - - -class WikiPageListLoopNone(NoneValidator): - """Validates a list of wiki pages like u'[[Birgitzer Alm]]; [[Kemater Alm]]' as string. - u'[[Birgitzer Alm]]; [[Kemater Alm]]' <=> u'[[Birgitzer Alm]]; [[Kemater Alm]]' - u'[[Birgitzer Alm]]' <=> u'[[Birgitzer Alm]]' - u'' <=> None - """ - def __init__(self): - NoneValidator.__init__(self, Loop(WikiPageList())) - - -class TupleSecondValidator(formencode.FancyValidator): - """Does not really validate anything but puts the string through - a validator in the second part of a tuple. - Examples with an Unsigned() validator and the True argument: - u'6' <=> (True, 6) - u'2' <=> (True, 2)""" - def __init__(self, first=True, validator=UnicodeNone()): - self.first = first - self.validator = validator - - def to_python(self, value): - self.assert_string(value, None) - return self.first, self.validator.to_python(value) - - def from_python(self, value): - assert value[0] == self.first - return self.validator.from_python(value[1]) - - -class BoolUnicodeTupleValidator(NoneValidator): - """Translates an unparsed string or u'Nein' to a tuple: - u'' <=> (None, None) - u'Nein' <=> (False, None) - u'any text' <=> (True, u'any text') - """ - def __init__(self, validator=UnicodeNone()): - NoneValidator.__init__(self, NeinValidator(TupleSecondValidator(True, validator), (False, None)), (None, None)) - - -class GermanLift(BoolUnicodeTupleValidator): - """Checks a lift_details property. It is a value comment property with the following - values allowed: - u'Sessellift' - u'Gondel' - u'Linienbus' - u'Taxi' - u'Sonstige' - Alternatively, the value u'Nein' is allowed. - An empty string maps to (None, None). - - Examples: - u'' <=> (None, None) - u'Nein' <=> (False, None) - u'Sessellift <=> (True, u'Sessellift') - u'Gondel (nur bis zur Hälfte)' <=> (True, u'Gondel (nur bis zur Hälfte)') - u'Sessellift; Taxi' <=> (True, u'Sessellift; Taxi') - u'Sessellift (Wochenende); Taxi (6 Euro)' <=> (True, u'Sessellift (Wochenende); Taxi (6 Euro)') - """ - def __init__(self): - BoolUnicodeTupleValidator.__init__(self, Loop(ValueCommentList(DictValidator({'Sessellift': 'Sessellift', 'Gondel': 'Gondel', 'Linienbus': 'Linienbus', 'Taxi': 'Taxi', 'Sonstige': 'Sonstige'})))) - - -class SledRental(BoolUnicodeTupleValidator): - """The value can be an empty string, u'Nein' or a comma-separated list of unicode strings with optional comments. - u'' <=> (None, None) - u'Nein' <=> (False, None) - u'Talstation (nur mit Ticket); Schneealm' <=> (True, u'Talstation (nur mit Ticket); Schneealm')""" - def __init__(self): - BoolUnicodeTupleValidator.__init__(self, Loop(ValueCommentList()))