示例#1
0
def create_user():
    name = request.forms.get('name')
    email = request.forms.get('email')
    department = request.forms.get('department')
    studentnumber = request.forms.get('studentnumber')
    print name, email, department
    UserService.add(app.dbs['users'], studentnumber, name, email, department)
示例#2
0
def get_user(id):
    user = UserService.selectByStudentnumber(app.dbs['users'], id)
    if user is None:
        return "{}"
    u = {'name': user.name, 'email': user.email,
         'studentnumber': user.studentnumber,
         'department': user.iddepartment}
    response.content_type = 'text/json; charset=utf-8'
    return dumps(u)
示例#3
0
def get_all_users():
    users = UserService.listAll(app.dbs['users'])
    if users is None:
        return ""
    us = []
    for user in users:
        u = {'name': user.name, 'email': user.email,
             'studentnumber': user.studentnumber,
             'department': user.iddepartment}
        us.append(u)
    response.content_type = 'text/json; charset=utf-8'
    return dumps(us)
示例#4
0
def update_user(id):
    name = request.forms.get('name')
    email = request.forms.get('email')
    department = request.forms.get('department')
    print name, email, department
    print request.body.read()
    return UserService.update(
        app.dbs['users'],
        id,
        name,
        email,
        department
    )
示例#5
0
def user_mails_sent(id):
    u = UserService.selectByStudentnumber(app.dbs['users'], id)
    dep = u.iddepartment
    addresses = UserAddressService.listByUser(app.dbs['users'], u.iduserthu)
    db = app.dbs[codes.codes['0{}'.format(dep)]]
    j = []
    mails = MailService.selectBySenderUserAdresses(
        db,
        [a.iduseraddress for a in addresses]
    )
    for m in mails:
        j.append(get_mail_barcode(m.barcode))
    response.content_type = 'text/json; charset=utf-8'
    return j
示例#6
0
def populate_user_db(user_database, ids):
    email_shift = 0
    ids['address'] = {}
    ids['department'] = {}
    ids['user'] = {}
    ids['useraddress'] = []
    for adress in adresses:
        ids['address'][adress] = AddressService.add(user_database, adress)
    for department in departments:
        ids['department'][department] = DepartmentService.add(user_database, department)
        for username in chinese_names:
            mail = "w_" + str(email_shift) + "@mail.tsinghua.edu.cn"
            ids['user'][username] = UserService.add(user_database, email_shift, username.decode('utf8'), mail, ids['department'][department]) 
            email_shift = email_shift + 1
            for _ in range(random.randint(1, 3)):
                addr_num = random.randint(0, len(adresses) - 1)
                ids['useraddress'].append(UserAddressService.add(user_database, ids['address'][adresses[addr_num]], ids['user'][username]))
 def listByUser(db_users, iduser):
     user = UserService.selectById(db_users, iduser)
     return user.addresses
示例#8
0
db_users = Database('mailsystem_users')
db_d1 = Database('mailsystem_d1')
databases = { 'users': db_users,
              'D1': db_d1 }

codes.codes = { "01": "D1" }
codes.rev_codes = { "D1": "01" }


a1 = AddressService.add(db_users, "A1")
a2 = AddressService.add(db_users, "A2")
d1 = DepartmentService.add(db_users, "D1")
s1 = StateService.add(db_users, "S1")
s2 = StateService.add(db_users, "S2")
s3 = StateService.add(db_users, "S3")
u1 = UserService.add(db_users, 2013400576, "U1", "[email protected]", d1)
ua1 = UserAddressService.add(db_users, a1, u1)
ua2 = UserAddressService.add(db_users, a2, u1)
bc = MailService.add(databases, s1, ua1, ua2)

las = UserAddressService.listByUser(db_users, u1)

selectedMail = MailService.selectByBarcode(databases['D1'], bc)

print las

print a1
print d1
print s1
print u1
print ua1