Exemple #1
0
    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')
Exemple #2
0
def When():
    return attrdict({
        'begin': u('') or datetime.today(),
        'end': u('') or datetime.today(),
        'total_duration': u(''),
        'schedules': []
    })
Exemple #3
0
 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})
Exemple #4
0
def Schedules():
    return attrdict({
        'number': u(''),
        'description': u(''),
        'start': u('') or datetime.today(),
        'finish': u('') or datetime.today(),
        'duration': u('')
    })
Exemple #5
0
 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
Exemple #6
0
 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({})
Exemple #7
0
 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
Exemple #8
0
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)
Exemple #9
0
def Organization():
    return attrdict({
        'number': u(''),
        'name': u(''),
        'address': u(''),
        'city': u(''),
        'phone': u(''),
        'email': u(''),
        'fax': u('')
    })
Exemple #10
0
def Costs():
    return attrdict({
        'contribution': u(''),
        'pktmoney': u(''),
        'other_cost': u(''),
        'total': u(''),
        'tax': u(''),
        'brutto': u(''),
        'netto': u('')
    })
Exemple #11
0
def Personal():
    return attrdict(
        {
            'number': u(''),
            'name': u(''),
            'nip': u(''),
            'group': u(''),
            'position': u(''),
            'unit_wkplaces': u(''),
            'main_wkplaces': u('')
        })
Exemple #12
0
 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')
Exemple #13
0
 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
Exemple #14
0
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
Exemple #15
0
 def __init__(self,UserID=u(''), UserSecret=u('')):
     self.UserID = UserID
     self.UserSecret = UserSecret
Exemple #16
0
 def __init__(self, id=0, title=u(''), association=None):
     if id != 0:
         self.id = id
     self.title = title
     self.association = association
Exemple #17
0
 def __init__(self, id=0, title=u(''), description=u('')):
     if id != 0:
         self.id = id
     self.title = title
     self.description = description
Exemple #18
0
 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
 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
Exemple #20
0
class EmailCredential(object):
    email = u('')
Exemple #21
0
 def __init__(self,UserID=u(''), UserSecret=u(''),weburl=u('')):
     self.UserID = UserID
     self.UserSecret = UserSecret
     self.weburl = weburl
Exemple #22
0
        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)
Exemple #23
0
    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'))
    )
}
Exemple #24
0
 def __init__(self,PreferFreeFormats=0,UserID=u(''), UserSecret=u('')):
     self.UserID = UserID
     self.UserSecret = UserSecret
     self.PreferFreeFormats = PreferFreeFormats
Exemple #25
0
 def model(self):
     return attrdict({
         'username': u(''),
         'remember_me': False
     })
Exemple #26
0
    """
    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
Exemple #27
0
 def model(self):
     return attrdict({
         'password': u(''),
         'confirm_password': u(''),
         'question_id': '1'
     })
Exemple #28
0
 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))
Exemple #29
0
def Participants():
    return attrdict({
        'total': u(''),
        'peserta': []
    })
Exemple #30
0
 def __init__(self,UserEmail=u('')):
     self.UserEmail = UserEmail
Exemple #31
0
 def __init__(self,TaskID=u(''),UserID=u(''), UserSecret=u('')):
     self.UserID = UserID
     self.UserSecret = UserSecret
     self.TaskID = TaskID