Esempio n. 1
0
def profile(request):
    #user_id = authenticated_userid(request)
    #user = User.query.get(user_id)
    profile = request.user.profile
    form = ProfileForm(request.POST, profile)
    if request.method == "POST" and form.validate():
        form.populate_obj(profile)
        DBSession.add(profile)
    return {'profile': profile, 'form': form}
Esempio n. 2
0
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}
Esempio n. 3
0
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}
Esempio n. 4
0
File: views.py Progetto: simlmx/ppl
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}
Esempio n. 5
0
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}
Esempio n. 6
0
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}
Esempio n. 7
0
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}
Esempio n. 8
0
File: views.py Progetto: simlmx/ppl
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}
Esempio n. 9
0
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}
Esempio n. 10
0
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)
Esempio n. 11
0
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()
Esempio n. 12
0
def home(request):
    session = DBSession()
    people = session.query(func.count(Profile.id)).scalar()
    companies = session.query(func.count(Company.id)).scalar()
    groups = session.query(func.count(Group.id)).scalar()
    return {'people': people, 'companies': companies,'groups': groups}
Esempio n. 13
0
File: tests.py Progetto: simlmx/ppl
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()
Esempio n. 14
0
def home(request):
    session = DBSession()
    people = session.query(func.count(Profile.id)).scalar()
    companies = session.query(func.count(Company.id)).scalar()
    groups = session.query(func.count(Group.id)).scalar()
    return {'people': people, 'companies': companies, 'groups': groups}