config.py 3.03 KB
Newer Older
Marc Duez's avatar
Marc Duez committed
1
# coding: utf8
Marc Duez's avatar
Marc Duez committed
2 3 4 5 6
import gluon.contrib.simplejson
if request.env.http_origin:
    response.headers['Access-Control-Allow-Origin'] = request.env.http_origin  
    response.headers['Access-Control-Allow-Credentials'] = 'true'
    response.headers['Access-Control-Max-Age'] = 86400
Marc Duez's avatar
Marc Duez committed
7 8

def index():
9 10 11 12
    if not auth.user : 
        res = {"redirect" : "default/user/login"}
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
    
Marc Duez's avatar
Marc Duez committed
13 14
    return dict(message=T('config_list'))

15

Marc Duez's avatar
Marc Duez committed
16 17 18
def add(): 
    return dict(message=T('add config'))

19

Marc Duez's avatar
Marc Duez committed
20 21
#TODO check data
def add_form(): 
22 23 24 25 26 27 28 29
    error =""

    if request.vars['config_name'] == "" :
        error += "name needed, "
    if request.vars['config_info'] == "" :
        error += "info needed, "
    if request.vars['config_command'] == "" : 
        error += "command needed, "  
Marc Duez's avatar
Marc Duez committed
30 31
    if request.vars['config_germline'] == "" : 
        error += "germline needed, "
32 33 34 35 36 37

    if error=="" :
        
        db.config.insert(name=request.vars['config_name'],
                        info=request.vars['config_info'],
                        command=request.vars['config_command'],
Marc Duez's avatar
Marc Duez committed
38
                        germline=request.vars['config_germline']
39 40
                        )

Marc Duez's avatar
Marc Duez committed
41 42
        res = {"redirect": "config/index",
               "message": "config added"}
43 44 45
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
        
    else :
Marc Duez's avatar
Marc Duez committed
46
        res = {"success" : "false", "message" : error}
47 48 49 50 51 52 53 54
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))


def edit(): 
    return dict(message=T('edit config'))


def edit_form(): 
Marc Duez's avatar
Marc Duez committed
55
    import shutil, os.path
Marc Duez's avatar
Marc Duez committed
56
    
57 58 59 60 61 62 63
    error =""

    if request.vars['config_name'] == "" :
        error += "name needed, "
    if request.vars['config_info'] == "" :
        error += "info needed, "
    if request.vars['config_command'] == "" : 
Marc Duez's avatar
Marc Duez committed
64 65 66
        error += "command needed, "
    if request.vars['config_germline'] == "" : 
        error += "germline needed, "
67 68 69 70 71 72

    if error=="" :

        db.config[request.vars["id"]] = dict(name=request.vars['config_name'],
                                            info=request.vars['config_info'],
                                            command=request.vars['config_command'],
Marc Duez's avatar
Marc Duez committed
73
                                            germline=request.vars['config_germline']
74 75
                                            )

Marc Duez's avatar
Marc Duez committed
76 77
        res = {"redirect": "config/index",
               "message": "config saved"}
78 79 80
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))

    else :
Marc Duez's avatar
Marc Duez committed
81
        res = {"success" : "false", "message" : error}
82
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
83 84 85 86 87

def confirm():
    return dict(message=T('confirm config deletion'))

def delete():
Marc Duez's avatar
Marc Duez committed
88
    import shutil, os.path
89 90 91 92 93 94 95
    
    #delete data_file using this config
    db(db.data_file.config_id==request.vars["id"]).delete()
    
    #delete config
    db(db.config.id==request.vars["id"]).delete() 
    
Marc Duez's avatar
Marc Duez committed
96 97
    res = {"redirect": "config/index",
           "message": "config deleted"}
98
    return gluon.contrib.simplejson.dumps(res, separators=(',',':'))