Exemple #1
0
 def on_get(self, req, resp):
     rows = db.query("""
         select
             id, name, role, email, username, is_disabled
         from gambler g
         order by name""")
     resp.body = utils.sendOk(rows)
Exemple #2
0
    def on_get(self, req, resp, id):
        user = db.first("select id, name from gambler where id=%s", (id, ))

        if user:
            resp.body = utils.sendOk(user)
        else:
            resp.body = utils.sendMessage(False, "Usuario no existe")
Exemple #3
0
 def on_get(self, req, resp):
     rows = db.query("""
         select
             id, name, role, email, username, is_disabled
         from gambler g
         order by name""")
     resp.body = utils.sendOk(rows)
Exemple #4
0
    def on_get(self, req, resp, id):
        user = db.first("select id, name from gambler where id=%s", (id,))

        if user:
            resp.body = utils.sendOk(user)
        else:
            resp.body = utils.sendMessage(False,"Usuario no existe")
Exemple #5
0
    def on_get(self, req, resp, championship_id):
        obj = db.first(
            """
                select id, name,is_disabled
                from championship
                where id = %s
                order by name asc
                """, (championship_id, ))

        datesDetail = db.query(
            """
            select
                d.id,
                d.name
            from championship_date d
            where is_disabled = false and
                  id_championship = %s
            order by id asc
            """, (championship_id, ))

        dateWithMatchForClient = []
        for row in datesDetail:
            types = date.findTypeOfResults(row['id'])

            for key in types.keys():
                row[key] = types[key]['points']

            matchDetails = db.query(
                """
                select
                    m.id,
                    id_team1,
                    id_team2,
                    t1.name as name_team1,
                    t2.name as name_team2,
                    goals_team1,
                    goals_team2,
                    date_start
                from championship_match m
                inner join team t1
                    on t1.id = m.id_team1
                inner join team t2
                    on t2.id = m.id_team2
                where m.is_disabled = false and
                      m.id_championship_date = %s
                """, (row["id"], ))

            convertScoreInString(matchDetails)
            row["matchs"] = matchDetails
            dateWithMatchForClient.append(row)
        if obj is None:
            resp.body = utils.sendMessage(False, "Campeonato no encontrado")
        else:
            obj["dates"] = dateWithMatchForClient
            resp.body = utils.sendOk(obj)
Exemple #6
0
    def on_put(self, req, resp):
        data = req.context['doc']
        userid = req.context['userid'] 

        if userid == data['id']:
            resp.body = utils.sendMessage(False, 'No es posible cambiar datos del mismo usuario')
            return

        if user.update(data):
            resp.body = utils.sendOk('ok')
        else:
            resp.body = utils.sendMessage(False, 'Error al momento de registrar')
Exemple #7
0
    def on_get(self, req, resp, championship_id):
        obj = db.first("""
                select id, name,is_disabled
                from championship
                where id = %s
                order by name asc
                """, (championship_id,))

        datesDetail = db.query("""
            select
                d.id,
                d.name
            from championship_date d
            where is_disabled = false and
                  id_championship = %s
            order by id asc
            """, (championship_id,))

        dateWithMatchForClient = []
        for row in datesDetail:
            types = date.findTypeOfResults(row['id'])

            for key in types.keys():
                row[key] = types[key]['points']

            matchDetails = db.query("""
                select
                    m.id,
                    id_team1,
                    id_team2,
                    t1.name as name_team1,
                    t2.name as name_team2,
                    goals_team1,
                    goals_team2,
                    date_start
                from championship_match m
                inner join team t1
                    on t1.id = m.id_team1
                inner join team t2
                    on t2.id = m.id_team2
                where m.is_disabled = false and
                      m.id_championship_date = %s
                """, ( row["id"] ,) )

            convertScoreInString(matchDetails)
            row["matchs"] = matchDetails
            dateWithMatchForClient.append(row)
        if obj is None:
            resp.body = utils.sendMessage(False, "Campeonato no encontrado")
        else:
            obj["dates"] = dateWithMatchForClient
            resp.body = utils.sendOk(obj)
Exemple #8
0
    def on_put(self, req, resp):
        data = req.context['doc']
        userid = req.context['userid']

        if userid == data['id']:
            resp.body = utils.sendMessage(
                False, 'No es posible cambiar datos del mismo usuario')
            return

        if user.update(data):
            resp.body = utils.sendOk('ok')
        else:
            resp.body = utils.sendMessage(False,
                                          'Error al momento de registrar')
Exemple #9
0
    def on_get(self, req, resp):
        userid = req.context['userid']
        champs = db.query("""
            select id,name
            from championship
            where is_disabled=false
            order by name asc""")

        results = []

        for row in champs:
            item = {'name': row['name']}
            item['dates'] = getDatesAndMatches(row['id'], userid)
            results.append(item)
        #end-for
        resp.body = utils.sendOk(results)
Exemple #10
0
    def on_get(self, req, resp):
        userid = req.context['userid']
        champs = db.query("""
            select id,name
            from championship
            where is_disabled=false
            order by name asc""")

        results = []

        for row in champs:
            item = {'name': row['name'] }
            item['dates'] = getDatesAndMatches(row['id'], userid)
            results.append(item)
        #end-for
        resp.body = utils.sendOk(results)
Exemple #11
0
    def on_post(self, req, resp):
        inUser = req.context["doc"]

        inUser['username'] = inUser['username'].lower()

        foundUser = db.first(
            """
            select id,name,role,is_disabled
            from gambler
            where
                username = %(username)s
                --and password = %(password)s
                and is_disabled = false """, inUser)

        result = {}
        if foundUser == None:
            resp.body = utils.sendMessage(
                False, '''Todavía no te unes al Club de Eventos DS.
                    Para saber cómo hacerlo, haz clic <a href="https://www.conexionbcp.com/wikis/home?lang=es#!/wiki/W22300a7f9e01_4d59_ac64_3ec295877429/page/Qué hago para pertenecer al Club de Eventos-DS" target='_blank'>aquí</a>'''
            )
        else:
            try:
                #if not utils.isValidUserOnActiveDirectory(inUser['username'],inUser['password']):
                #    resp.body = utils.sendMessage(False,'Matrícula o contraseña no coincide')
                #    return
                #end-if

                token = utils.makeToken()
                db.execute("update gambler set token=%s where id=%s",
                           (token, foundUser["id"]))
                result = {
                    "token": token,
                    "id": foundUser["id"],
                    "name": foundUser["name"],
                    "role": foundUser["role"]
                }
                resp.body = utils.sendOk(result)
            except:
                resp.body = utils.sendMessage(
                    False, 'Error al intentar iniciar sesión')
Exemple #12
0
    def on_get(self, req, resp):
        champs = db.query("""
            select id,name
            from championship
            where is_disabled=false
            order by name""")

        results = []

        for row in champs:
            item = {'name': row['name']}
            gamblers = db.query(
                """
                select
                    g.id,
                    g.name,
                    coalesce(d.points,0) as points
                from gambler g
                left join (
                    select
                        gs.id_gambler,
                        gs.id_championship,
                        sum(gs.points) as points
                    from gambler_score gs
                    inner join championship_match m
                        on m.id = gs.id_championship_match
                    where
                        m.is_disabled = false and
                        gs.id_championship = %s
                    group by id_gambler, id_championship
                ) d
                on g.id = d.id_gambler
                order by coalesce(d.points,0) desc, g.name asc
            """, (row['id'], ))

            item['gamblers'] = gamblers
            results.append(item)
        #end-for
        resp.body = utils.sendOk(results)
Exemple #13
0
    def on_get(self, req, resp):
        champs = db.query("""
            select id,name
            from championship
            where is_disabled=false
            order by name""")

        results = []

        for row in champs:
            item = {'name': row['name']}
            gamblers = db.query("""
                select
                    g.id,
                    g.name,
                    coalesce(d.points,0) as points
                from gambler g
                left join (
                    select
                        gs.id_gambler,
                        gs.id_championship,
                        sum(gs.points) as points
                    from gambler_score gs
                    inner join championship_match m
                        on m.id = gs.id_championship_match
                    where
                        m.is_disabled = false and
                        gs.id_championship = %s
                    group by id_gambler, id_championship
                ) d
                on g.id = d.id_gambler
                order by coalesce(d.points,0) desc, g.name asc
            """, ( row['id'], ) )

            item['gamblers'] = gamblers
            results.append(item)
        #end-for
        resp.body = utils.sendOk(results)
Exemple #14
0
    def on_post(self, req, resp):
        inUser = req.context["doc"]

        inUser['username'] = inUser['username'].lower()

        foundUser = db.first("""
            select id,name,role,is_disabled
            from gambler
            where
                username = %(username)s
                --and password = %(password)s
                and is_disabled = false """, inUser)

        result = {}
        if foundUser == None:
            resp.body = utils.sendMessage(False,
                '''Todavía no te unes al Club de Eventos DS.
                    Para saber cómo hacerlo, haz clic <a href="https://www.conexionbcp.com/wikis/home?lang=es#!/wiki/W22300a7f9e01_4d59_ac64_3ec295877429/page/Qué hago para pertenecer al Club de Eventos-DS" target='_blank'>aquí</a>''')
        else:
            try:
                #if not utils.isValidUserOnActiveDirectory(inUser['username'],inUser['password']):
                #    resp.body = utils.sendMessage(False,'Matrícula o contraseña no coincide')
                #    return
                #end-if

                token = utils.makeToken()
                db.execute("update gambler set token=%s where id=%s",
                            (token, foundUser["id"]) )
                result = {
                    "token": token,
                    "id": foundUser["id"],
                    "name": foundUser["name"],
                    "role": foundUser["role"]}
                resp.body = utils.sendOk(result)
            except:
                resp.body = utils.sendMessage(False,'Error al intentar iniciar sesión')
Exemple #15
0
 def on_get(self, req, resp):
     rows = db.query("""
         select id, name
         from championship
         order by is_disabled, id desc""")
     resp.body = utils.sendOk(rows)
Exemple #16
0
    def on_get(self, req, resp, id_user):
        listMatchs = db.query("""
            select
                c.id as id_championship,
                d.id as id_championship_date,
                m.id as id_championship_match,
                c.name as name_championship,
                d.name as name_date,
                m.goals_team1 as score_team1,
                m.goals_team2 as score_team2,
                t1.name as name_team1,
                t2.name as name_team2,
                t1.url_logo as url_logo_team1,
                t2.url_logo as url_logo_team2
            from championship c
            inner join championship_date d
                on d.id_championship = c.id
            inner join championship_match m
                on m.id_championship_date = d.id
            inner join team t1
                on m.id_team1 = t1.id
            inner join team t2
                on m.id_team2 = t2.id
            where
                c.is_disabled = false and
                d.is_disabled = false and
                m.is_disabled = false
                and isBeforeLimiteDateByUnixtime(m.date_start/1000) = false
            """)

        champs = {}

        for rowMatch in listMatchs:
            if rowMatch['id_championship'] in champs:
                dates = champs[rowMatch['id_championship']]['dates']

                if not rowMatch['id_championship_date'] in dates:
                    dates[rowMatch['id_championship_date']] = {
                        'name': rowMatch['name_date'],
                        'matchs': []
                    }
            else:
                objDate = {}
                objDate[rowMatch['id_championship_date']] = {
                    'name': rowMatch['name_date'],
                    'matchs': []
                }

                champs[rowMatch['id_championship']] = {
                    'name': rowMatch['name_championship'],
                    'dates': objDate
                }

        #query each match
        for rowMatch in listMatchs:

            userScore = db.first(
                '''
                select
                    score_team1 as user_score_team1,
                    score_team2 as user_score_team2,
                    coalesce(gs.points,0) as points,
                    dp.description
                from gambler_score gs
                left join championship_date_points dp
                    on dp.id = gs.id_championship_date_points
                where id_gambler = %s and gs.id_championship_match = %s
            ''', (id_user, rowMatch['id_championship_match']))

            objMatch = {
                'name_team1': rowMatch['name_team1'],
                'name_team2': rowMatch['name_team2'],
                'url_logo_team1': rowMatch['url_logo_team1'],
                'url_logo_team2': rowMatch['url_logo_team2'],
                'score_team1': rowMatch['score_team1'],
                'score_team2': rowMatch['score_team2'],
                'user_score_team1': None,
                'user_score_team2': None,
                'points': 0,
                'description': '-'
            }

            if userScore:
                objMatch['user_score_team1'] = userScore['user_score_team1']
                objMatch['user_score_team2'] = userScore['user_score_team2']
                objMatch['points'] = userScore['points']
                if not userScore['description'] is None:
                    objMatch['description'] = userScore['description']

            idChamp = rowMatch['id_championship']
            idDate = rowMatch['id_championship_date']
            champs[idChamp]['dates'][idDate]['matchs'].append(objMatch)

        results = []
        for keyChamp in champs.keys():
            oneChamp = champs[keyChamp]
            dates = []
            for keyDate in oneChamp['dates'].keys():
                dates.append(oneChamp['dates'][keyDate])

            results.append({'name': oneChamp['name'], 'dates': dates})
        resp.body = utils.sendOk(results)
Exemple #17
0
    def on_get(self, req, resp, id_user):
        listMatchs = db.query("""
            select
                c.id as id_championship,
                d.id as id_championship_date,
                m.id as id_championship_match,
                c.name as name_championship,
                d.name as name_date,
                m.goals_team1 as score_team1,
                m.goals_team2 as score_team2,
                t1.name as name_team1,
                t2.name as name_team2,
                t1.url_logo as url_logo_team1,
                t2.url_logo as url_logo_team2
            from championship c
            inner join championship_date d
                on d.id_championship = c.id
            inner join championship_match m
                on m.id_championship_date = d.id
            inner join team t1
                on m.id_team1 = t1.id
            inner join team t2
                on m.id_team2 = t2.id
            where
                c.is_disabled = false and
                d.is_disabled = false and
                m.is_disabled = false
                and isBeforeLimiteDateByUnixtime(m.date_start/1000) = false
            """ )

        champs = {}

        for rowMatch in listMatchs:
            if rowMatch['id_championship'] in champs:
                dates = champs[rowMatch['id_championship']]['dates']

                if not rowMatch['id_championship_date'] in dates:
                    dates[ rowMatch['id_championship_date'] ] = {
                        'name': rowMatch['name_date'],
                        'matchs': []
                    }
            else:
                objDate = {}
                objDate[ rowMatch['id_championship_date'] ] = {
                    'name': rowMatch['name_date'],
                    'matchs': []
                }

                champs[ rowMatch['id_championship'] ] = {
                    'name': rowMatch['name_championship'],
                    'dates': objDate
                }

        #query each match
        for rowMatch in listMatchs:

            userScore = db.first('''
                select
                    score_team1 as user_score_team1,
                    score_team2 as user_score_team2,
                    coalesce(gs.points,0) as points,
                    dp.description
                from gambler_score gs
                left join championship_date_points dp
                    on dp.id = gs.id_championship_date_points
                where id_gambler = %s and gs.id_championship_match = %s
            ''', (id_user,rowMatch['id_championship_match']))

            objMatch = {
                    'name_team1' : rowMatch['name_team1'] ,
                    'name_team2' : rowMatch['name_team2'] ,
                    'url_logo_team1' : rowMatch['url_logo_team1'] ,
                    'url_logo_team2' : rowMatch['url_logo_team2'] ,
                    'score_team1' : rowMatch['score_team1'] ,
                    'score_team2' : rowMatch['score_team2'] ,
                    'user_score_team1' : None ,
                    'user_score_team2' : None ,
                    'points' : 0 ,
                    'description' : '-'
            }

            if userScore:
                objMatch['user_score_team1'] = userScore['user_score_team1']
                objMatch['user_score_team2'] = userScore['user_score_team2']
                objMatch['points'] = userScore['points']
                if not userScore['description'] is None:
                    objMatch['description'] = userScore['description']

            idChamp = rowMatch['id_championship']
            idDate = rowMatch['id_championship_date']
            champs[idChamp]['dates'][idDate]['matchs'].append(objMatch)

        results = []
        for keyChamp in champs.keys():
            oneChamp = champs[keyChamp]
            dates = []
            for keyDate in oneChamp['dates'].keys():
                dates.append(oneChamp['dates'][keyDate])

            results.append({
                'name': oneChamp['name'],
                'dates': dates
            })
        resp.body = utils.sendOk(results)
Exemple #18
0
 def on_get(self, req, resp, team_id):
     obj = db.first("select * from team where id = %s", (team_id,))
     if obj is None:
         resp.body = utils.sendMessage(False, "Equipo no encontrado")
     else:
         resp.body = utils.sendOk(obj)
Exemple #19
0
 def on_get(self, req, resp):
     rows = db.query("select id, name from team order by name")
     resp.body = utils.sendOk(rows)