def new(request): form = CompanyForm(request.POST) if request.method == "POST" and form.validate(): company = Company() form.populate_obj(company) DBSession.add(company) DBSession.flush() request.session.flash('{} has been created'.format(company.name)) url = request.route_url('companies.detail', slug=company.slug) return HTTPFound(location=url) return {'form': form}
def new(request): form = GroupForm(request.POST) if request.method == "POST" and form.validate(): group = Group() form.populate_obj(group) DBSession.add(group) DBSession.flush() request.session.flash('{} has been created'.format(group.name)) url = request.route_url('groups.detail', slug=group.slug) return HTTPFound(location=url) return {'form': form}
def edit(request): slug = request.matchdict['slug'] company = Company.query.filter_by(slug=slug).one() form = CompanyForm(request.POST, company) if request.method == "POST" and form.validate(): form.populate_obj(company) DBSession.add(company) DBSession.flush() request.session.flash(u'{} was updated, the version number is now {}'.format(company.name, company.version)) url = request.route_url('companies.detail', slug=company.slug) return HTTPFound(location=url) return {'company': company, 'form': form}
def edit(request): slug = request.matchdict['slug'] group = Group.query.filter_by(slug=slug).one() form = GroupForm(request.POST, group) if request.method == "POST" and form.validate(): form.populate_obj(group) DBSession.add(group) DBSession.flush() request.session.flash(u'{} was updated, the version number is now {}'.format(group.name, group.version)) url = request.route_url('groups.detail', slug=group.slug) return HTTPFound(location=url) return {'group': group, 'form': form}
def login_complete_view(request): context = request.context session = DBSession() #url = "https://api.github.com/user?access_token=%s" result = { 'provider_type': context.provider_type, 'provider_name': context.provider_name, 'profile': context.profile, 'credentials': context.credentials, } token = context.credentials['oauthAccessToken'] provider = context.profile.get('accounts')[0] identifier = sha1(str(provider.get('userid')) + _SALT).hexdigest() emails = [item['value'] for item in context.profile.get('emails',[])] if emails: email = emails[0] else: email = None logger.warn(result) #r = requests.get(url%token) #create user user = User.query.filter_by(identifier=identifier).first() if user: #update token user.auth_token = token user.provider = context.provider_name else: user = User( auth_token=token, provider=context.provider_name, identifier=identifier ) if context.profile['displayName'] is None or context.profile['displayName'].strip() == '': display_name = context.profile['preferredUsername'] else: display_name = context.profile['displayName'] profile = Profile( email=email, user=user, name=display_name ) if context.provider_name == 'github': profile.github_name = context.profile['preferredUsername'] session.add(profile) #create profile if needed session.add(user) session.flush() #login user headers = remember(request, user.id) request.session.flash(u'Logged in successfully.') return HTTPFound(location=request.route_url('home'), headers=headers)
def edit(request): slug = request.matchdict['slug'] company = Company.query.filter_by(slug=slug).one() form = CompanyForm(request.POST, company) if request.method == "POST" and form.validate(): form.populate_obj(company) DBSession.add(company) DBSession.flush() request.session.flash( u'{} was updated, the version number is now {}'.format( company.name, company.version)) url = request.route_url('companies.detail', slug=company.slug) return HTTPFound(location=url) return {'company': company, 'form': form}
def edit(request): slug = request.matchdict['slug'] group = Group.query.filter_by(slug=slug).one() form = GroupForm(request.POST, group) if request.method == "POST" and form.validate(): form.populate_obj(group) DBSession.add(group) DBSession.flush() request.session.flash( u'{} was updated, the version number is now {}'.format( group.name, group.version)) url = request.route_url('groups.detail', slug=group.slug) return HTTPFound(location=url) return {'group': group, 'form': form}