~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to userdb/query.py

  • Committer: Matt Giuca
  • Date: 2009-01-19 17:28:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119172859-htjq3rfpp0fhtpc9
ivle.worksheet: Added calculate_score. This is a nice clean Storm port of
    ivle.db.calculate_worksheet_score.
tutorial: Replaced use of ivle.db.calculate_worksheet_score with
    ivle.worksheet.calculate_score.
    Guess What!! Removed this module's dependency on ivle.db! Hooray!
    (Note: tutorialservice still depends on it).
bin/ivle-marks: Updated this script to use ivle.worksheet_calculate_score.
    Note that this DOES NOT execute properly -- it seems it didn't even
    before my changes (tries to call db.get_users). Not my fault; I'm
    committing and going to bed!
ivle.db: Removed calculate_worksheet_score.
    As this removes the dependency on get_problem_status, removed that too!
    Almost all the worksheet stuff is gone now!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import pg
 
2
 
 
3
def getCredentials(db, login):
 
4
    cred = {}
 
5
 
 
6
    res = db.query('SELECT users.nick FROM users WHERE users.login=\'' + login + '\'').dictresult()
 
7
    if len(res) <> 1:
 
8
        return None
 
9
    cred['nick'] = res[0]['nick']
 
10
 
 
11
    res = db.query('SELECT groupid FROM group_members WHERE login=\'' + login + '\'').dictresult()
 
12
    cred['groups'] = map(lambda x: x.get('groupid'), res)
 
13
 
 
14
    res = db.query('SELECT role FROM roles WHERE login=\'' + login + '\'').dictresult()
 
15
    if len(res) <> 1:
 
16
        return None
 
17
    cred['role'] = res[0]['role']
 
18
 
 
19
    return cred
 
20
 
 
21
def contains(m, l):
 
22
    for i in l:
 
23
        if m == i:
 
24
            return True
 
25
    return False
 
26
 
 
27
db = pg.connect('tom', 'localhost', 5432, None, None, 'tom', 'sh0r3ham')
 
28
c = getCredentials(db, 'conway')
 
29
 
 
30
if c['role'] != 'student' or contains('2007-INFO10001-321', c['groups']):
 
31
    print c['nick'] + ' may view files for group \'2007-INFO10001-321\'.'
 
32