def post(self): if not self.validate_resubmission(): self.error(self._('Your registration request has been queued. ' 'Please wait while your request will be ' 'processed. If your request fails please ' 'try again.')) return self.get() registration = Registration() if (not self.try_update_model(self.model) & self.try_update_model(registration) & self.try_update_model(registration.account) & self.try_update_model(registration.credential) or not self.validate(self.model, password_match_validator) & self.validate(registration, registration_validator) or not self.create_account(registration)): if self.request.ajax: return self.json_response({'errors': self.errors}) registration.credential.password = u('') self.model.confirm_password = u('') return self.get(registration) # with self.factory('ro') as f: f = self.factory('ro') try: f.__enter__() roles = f.membership.roles(registration.credential.username) finally: f.__exit__(None, None, None) self.principal = Principal( id=registration.credential.username, alias=registration.account.display_name, roles=roles) del self.resubmission return self.see_other_for('default')
def When(): return attrdict({ 'begin': u('') or datetime.today(), 'end': u('') or datetime.today(), 'total_duration': u(''), 'schedules': [] })
def post(self): m = attrdict(username=u(''), password=u('')) if (not self.try_update_model(m) or not self.validate(m, credential_validator) or not self.authenticate(m)): return self.json_errors() return self.json_response({'username': m.username})
def Schedules(): return attrdict({ 'number': u(''), 'description': u(''), 'start': u('') or datetime.today(), 'finish': u('') or datetime.today(), 'duration': u('') })
def post(self): m = attrdict(slug=u(''), message=u('')) if (not self.try_update_model(m, self.route_args) or not self.try_update_model(m) or not self.validate(m, post_comment_validator) or not self.add_post_comment(m)): return self.json_errors() r = self.json_response({}) r.status_code = 201 return r
def post(self): m = attrdict(email=u(''), username=u(''), password=u('')) p = attrdict(password=u(''), confirm_password=u('')) if (not self.try_update_model(m) & self.try_update_model(p) or not self.validate(m, credential_validator) & self.validate(m, signup_validator) & self.validate(p, password_match_validator) or not self.create_account(m)): return self.json_errors() return self.json_response({})
def __init__(self, id=0, first_name=u(''), middle_name=u(''), last_name=u(''), gender=None, current_weight=Dec(0), age_cohort=2000, sports_club=None, external_id=u('')): if id != 0: self.id = id self.first_name = first_name self.middle_name = middle_name self.last_name = last_name self.gender = gender self.current_weight = current_weight self.age_cohort = age_cohort self.sports_club = sports_club self.external_id = external_id
def Training(**other): return attrdict( { 'number': u(''), 'recorded': u(''), 'title': u(''), 'category': u(''), 'description': u(''), 'operator': Organization(), 'when': When(), 'where': Organization(), 'participants': Participants(), 'costs': Costs() }, **other)
def Organization(): return attrdict({ 'number': u(''), 'name': u(''), 'address': u(''), 'city': u(''), 'phone': u(''), 'email': u(''), 'fax': u('') })
def Costs(): return attrdict({ 'contribution': u(''), 'pktmoney': u(''), 'other_cost': u(''), 'total': u(''), 'tax': u(''), 'brutto': u(''), 'netto': u('') })
def Personal(): return attrdict( { 'number': u(''), 'name': u(''), 'nip': u(''), 'group': u(''), 'position': u(''), 'unit_wkplaces': u(''), 'main_wkplaces': u('') })
def post(self): if not self.validate_xsrf_token(): return self.redirect_for(self.route_args.route_name) credential = Credential() if (not self.try_update_model(credential) & self.try_update_model(self.model) or not self.validate(credential, credential_validator) or not self.authenticate(credential)): if self.request.ajax: return self.json_response({'errors': self.errors}) credential.password = u('') return self.get(credential) del self.xsrf_token return self.see_other_for('default')
def get(self): m = attrdict(slug=u(''), fields=['']) if (not self.try_update_model(m, self.route_args) or not self.try_update_model(m, self.request.query) or not self.validate(m, post_spec_validator)): return self.json_errors() p = self.get_post(m.slug, m.fields) if not p: return not_found() r = self.json_response(p) if self.principal: r.cache_dependency = ( keys.post(m.slug), keys.author_comments(self.principal.id)) else: r.cache_dependency = (keys.post_public(m.slug),) return r
class Tournament(Base, DataModelMixin): """ data class for tournaments. """ title = Column( String(50), default=u(''), doc=u('Title of the tournament.')) organiser = Column( String, default=u(''), doc=u('Organiser of the tournament.')) description = Column( String, default=u(''), doc=u('Short description of the tournament.')) def __init__(self, id=0, title=u(''), organiser=u(''), description=u('')): if id != 0: self.id = id self.title = title self.organiser = organiser self.description = description
def __init__(self,UserID=u(''), UserSecret=u('')): self.UserID = UserID self.UserSecret = UserSecret
def __init__(self, id=0, title=u(''), association=None): if id != 0: self.id = id self.title = title self.association = association
def __init__(self, id=0, title=u(''), description=u('')): if id != 0: self.id = id self.title = title self.description = description
def __init__(self, id=0, created_on=None, author=u(''), message=u('')): self.id = id self.created_on = created_on or datetime.now() self.author = author self.message = message
class EmailCredential(object): email = u('')
def __init__(self,UserID=u(''), UserSecret=u(''),weburl=u('')): self.UserID = UserID self.UserSecret = UserSecret self.weburl = weburl
return dao_class(klass, **dao_kwargs) def commit(self): for dao_context in self.__dao_contexts: dao_context.commit() def rollback(self): for dao_context in self.__dao_contexts: dao_context.rollback() if __name__ == '__main__': # TODO: read in configuration etc. # TODO: create database schema if necessary with DAOManager() as daom: dao = daom.dao(Tournament) tournament_dict = dict( title=u('Vereinsmeisterschaften'), organiser=u('JC Ettlingen'), description=u('Vereinsmeisterschaften des JC Ettlingen') ) # TODO: validation tournament = dao.create(**tournament_dict) daom.commit() print(tournament.id)
a.display_name = 'John Smith' a.email = next_name() + '@somewhere.com' return a def next_registration(question_id='1'): r = Registration() r.credential = next_credential() r.account = next_account() r.date_of_birth = next_date() r.question_id = question_id or str(random.randint(1, 3)) r.answer = random.choice(('1', '7', '9')) return r db = { 'user': { 'demo': u('P@ssw0rd'), 'biz': u('P@ssw0rd') }, 'user_role': { 'demo': ['user'], 'biz': ['business'] }, 'password_question': ( ('1', _('Favorite number')), ('2', _('City of birth')), ('3', _('Favorite color')) ) }
def __init__(self,PreferFreeFormats=0,UserID=u(''), UserSecret=u('')): self.UserID = UserID self.UserSecret = UserSecret self.PreferFreeFormats = PreferFreeFormats
def model(self): return attrdict({ 'username': u(''), 'remember_me': False })
""" for field, errorlist in errors.items(): for error in errorlist: print("ERROR IN FIELD: {} - {}".format(field, error)) if __name__ == '__main__': # Test code ValidatorRegistry.register(Tournament, tournament_validator) dal = DalSqlAlchemy() dal.create_database() session = dal.get_session() # Example 1: Validate before creating data object tournament_dict = dict( title=u('Vereinsmeisterschaften'), organiser=u('JC Ettlingen'), description=u('Vereinsmeisterschaften des JC Ettlingen')) errors = {} if not ValidatorRegistry.validate_values(Tournament, tournament_dict, errors): dump_validation_errors(errors) session.abort() sys.exit(1) t = dal.new(Tournament, **tournament_dict) session.commit() print(t.id) # Example 2: Validate after creating data object
def model(self): return attrdict({ 'password': u(''), 'confirm_password': u(''), 'question_id': '1' })
def get(self): m = attrdict(q=u(''), page=0) if (not self.try_update_model(m, self.request.query) or not self.validate(m, search_posts_validator)): return self.json_errors() return self.json_response(self.search_posts(m.q, m.page))
def Participants(): return attrdict({ 'total': u(''), 'peserta': [] })
def __init__(self,UserEmail=u('')): self.UserEmail = UserEmail
def __init__(self,TaskID=u(''),UserID=u(''), UserSecret=u('')): self.UserID = UserID self.UserSecret = UserSecret self.TaskID = TaskID