예제 #1
0
def load_builds(val):
    """
    Description: Returns a list of builds to show on index.html. This is called from the JS.
    Returns: A JSON with a dictionary of all the builds and their database fields.
    Note: No HTML associated with page
    """

    import json

    if val is None:
        return None

    project = db(db.build.project == val).select()
    builds = []

    for i in project:
        experiment_count = db(db.experiment.build_id == i.id).count()
        owner = db(db.auth_user.id == i.user_id).select()[0]
        meta_info = json.loads(i.meta)
        build_name = "Build " + str(i.id) + " for " + owner.username
        builds.append(
            dict(project=i.project,
                 user=i.user_id,
                 build_id=i.id,
                 name=build_name,
                 count=experiment_count,
                 meta_author=meta_info['head_commit']['author']['name'],
                 meta_timestamp=meta_info['head_commit']['timestamp'],
                 meta_commit=meta_info['head_commit']['id'],
                 meta_message=meta_info['head_commit']['message'],
                 status=i.status))

    return builds
def add_board():
    if not json.loads(request.vars.board_new):
        author = db().select(db.board.board_author).first().board_author
        if author != auth.user.id:
            return "ko"
    db.board.update_or_insert((db.board.board_id == request.vars.board_id),
            board_id=request.vars.board_id,
            board_title=request.vars.board_title)
    return "ok"
def add_post():
    if not json.loads(request.vars.post_new):
        author = db().select(db.post.post_author).first().post_author
        if author != auth.user.id:
            return "ko"
    db.post.update_or_insert((db.post.post_id == request.vars.post_id),
                             post_id=request.vars.post_id,
                             post_title=request.vars.post_title,
                             post_content=request.vars.post_content,
                             post_parent=request.vars.post_parent)
    return "ok"
예제 #4
0
파일: default.py 프로젝트: coltonUCSC/cs183
def index():
    team = 0
    form = 0
    forms = 0
    images = 0
    messages = ""
    if auth.is_logged_in():
        images = db(db.images.user==auth.user_id).select()
        if images:
            images = db(db.images.user==auth.user_id).select()[0]
            if not images:
                form = SQLFORM.factory(db.images,table_name='images')
                if form.process().accepted:
                    images = db.images.insert(image=form.vars.image, user=auth.user_id)
                    redirect(URL('index'))
        else:
            form = SQLFORM.factory(db.images,table_name='images')
            if form.process().accepted:
                images = db.images.insert(image=form.vars.image, user=auth.user_id)
                redirect(URL('index'))
        #code for chat start
        forms = SQLFORM(Post, formstyle = 'divs')
        if forms.process().accepted:
            #send messages on queue
            js = "jQuery('.new').slideDown('slow')"
            comet_send('http://127.0.0.1:8888', js, 'mykey', 'mygroup')
        messages = db(Post).select(orderby=~Post.created_on)
        #code for chat end

        groupid = 0
        if auth.user_groups.keys():
            groupid = auth.user_groups.keys()[0]
            team = db(db.Team.team_group == groupid).select().first()
        else:
            team=None
    else:
        first_name = ""
        last_name = ""
        identifier = ""
        email = ""
        password = "******"
        response.headers['content-type'] = 'text/xml'
        xml = request.body.read()  # retrieve the raw POST data
        token = xml[6:]
        print token
        if len(xml) == 0:
            xml = '<?xml version="1.0" encoding="utf-8" ?><root>no post data</root>'
        else:
            api_params = {
                'token': token,
                'apiKey': '73dab71b7fdfc0f49c10f8e64ee6a5adcf66b2c3',
                'format': 'json',
            }

            # make the api call
            http_response = urllib2.urlopen('https://rpxnow.com/api/v2/auth_info',
                                urllib.urlencode(api_params))

            # read the json response
            auth_info_json = http_response.read()

            # Step 3) process the json response
            auth_info = json.loads(auth_info_json)

            # Step 4) use the response to sign the user in
            if auth_info['stat'] == 'ok':
                profile = auth_info['profile']

                # 'identifier' will always be in the payload
                # this is the unique idenfifier that we use to sign the user
                # in to our site
                identifier = profile['identifier']
                first_name = profile["name"]["givenName"]
                last_name = profile["name"]["familyName"]
            else:
                 print 'An error occured: ' + auth_info['err']['msg']
        #checking if the user is already in the database
        users = db().select(db.auth_user.ALL)
        if users:
            users = db(db.auth_user.registration_id==identifier).select()
            if users:
                users = db(db.auth_user.registration_id==identifier).select()[0]
        if users:
            login = auth.login_bare(users.email,password)
            if (not login) & (auth_info['stat'] == 'ok'):
                db.auth_user.insert(
                first_name=first_name,
                last_name=last_name,
                registration_id=identifier,
                password=(db.auth_user.password.validate(password)[0]))
                login_again = auth.login_bare(email,password)
        else:
            print'Not able to login!'
    return dict(images=images,form=form,forms=forms,messages=messages,team=team)