def velruse_complete(context, request): email = context.profile.get('verifiedEmail') user = DBSession.query(User).get(email) if not user: session = DBSession() try: given_name, family_name = context.profile['displayName'].split(' ') except ValueError: given_name = context.profile['displayName'] family_name = context.profile['displayName'] user = User(given_name=given_name, family_name=family_name, email=context.profile.get('verifiedEmail')) session.add(user) headers = remember(request, user.email) request.session.flash({'title': u'Zarejestrowany', 'body': u'Witamy w Szkole Czytania. Twoje konto zostało utworzone.'}, queue='success') return HTTPFound(location='/profile', headers=headers) request.session.flash({'title': u'Zalogowany', 'body': u'Witamy w Szkole Czytania!'}, queue='success') headers = remember(request, user.email) return HTTPFound(location='/', headers=headers)
def edit_group(context, request): if 'id' in request.matchdict: try: group = DBSession().query(Group).get(request.matchdict.get('id')) is_new = False except SQLAlchemyError: raise HTTPNotFound if not group: raise HTTPNotFound else: group = Group() is_new = True schema = GroupSchema(after_bind=maybe_remove_fields).bind(request=request, group=group) form = deform.Form(schema, buttons=('zapisz', 'anuluj'), css_class=u'form-horizontal', requirements = ( ('bootstrap', None), )) js.deform.auto_need(form) if request.POST: if not 'zapisz' in request.POST: return HTTPFound(location='/groups/only_mine') items = request.POST.items() try: appstruct = form.validate(items) except deform.ValidationFailure, e: return {'form': e.render(), 'group_nav': get_renderer('templates/group_macros.pt').implementation(), 'group': group, 'main': get_renderer('templates/master.pt').implementation()} if 'activation_code' in request.POST: group.state = u'aktywna' request.session.flash({'title': u'Gotowe!', 'body': u'Grupa %s została aktywowana.' % group.name}, queue='success') return HTTPFound(location='/groups/%s' % group.id) if appstruct['logo']: logo = File() logo.filename = appstruct['logo']['filename'] logo.mimetype = appstruct['logo']['mimetype'] appstruct['logo']['fp'].seek(0) logo.data = appstruct['logo']['fp'].read() appstruct['logo']['fp'].seek(0,2) logo.size = appstruct['logo']['fp'].tell() appstruct['logo']['fp'].close() appstruct['logo'] = logo group = merge_session_with_post(group, appstruct) session = DBSession() session.add(group) if is_new: group.add_member(request.user, 'owner') request.session.flash({'title': u'Gotowe!', 'body': u'Grupa %s została stworzona.' % group.name}, queue='success') else: request.session.flash({'title': u'Gotowe!', 'body': u'Grupa %s została zaktualizowana.' % group.name}, queue='success') return HTTPFound(location='/groups/only_mine')
def main(argv=sys.argv): if len(argv) != 2: usage(argv) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri, name="main") engine = engine_from_config(settings, "sqlalchemy.") DBSession.configure(bind=engine) Base.metadata.bind = engine from szcz import models Base.metadata.create_all() with transaction.manager: user1 = models.User(email=u"*****@*****.**", given_name=u"Andrew", family_name=u"Mleczko") DBSession.add(user1) user2 = models.User(email=u"*****@*****.**", given_name=u"Jan", family_name=u"Kowalski") DBSession.add(user2) user3 = models.User(email=u"*****@*****.**", given_name=u"Jan", family_name=u"Nowak") DBSession.add(user3) user4 = models.User(email=u"*****@*****.**", given_name=u"Piotr", family_name=u"Krauze") DBSession.add(user4) user5 = models.User(email=u"*****@*****.**", given_name=u"John", family_name=u"Smith") DBSession.add(user5) user6 = models.User(email=u"*****@*****.**", given_name=u"Marco", family_name=u"Rossi") DBSession.add(user6) user7 = models.User(email=u"*****@*****.**", given_name=u"Gustaw", family_name=u"Flawiusz") DBSession.add(user7) user8 = models.User(email=u"*****@*****.**", given_name=u"Roman", family_name=u"Kowalski") DBSession.add(user8) user9 = models.User(email=u"*****@*****.**", given_name=u"Marceli", family_name=u"Szpak") DBSession.add(user9) all_books = DBSession.query(models.Book).all() group1 = models.Group(name=u"Grupa krakowska") for i in range(10): group1.add_book(random.choice(all_books)) group1.add_member(user1, "owner") group1.add_member(user2, "member") group1.add_member(user3, "member") DBSession.add(group1) group2 = models.Group(name=u"Grupa z Ferrary") for i in range(10): group2.add_book(random.choice(all_books)) group2.add_member(user1, "member") group2.add_member(user4, "member") group2.add_member(user5, "member") group2.add_member(user6, "member") group2.add_member(user7, "member") group2.add_member(user8, "member") group2.add_member(user9, "member") DBSession.add(group2) group3 = models.Group(name=u"Grupa Lakoona") group3.add_member(user1, "owner") for i in range(10): group3.add_book(random.choice(all_books)) DBSession.add(group3)