config.py 4.61 KB
Newer Older
Marc Duez's avatar
Marc Duez committed
1
2
3
4
# coding: utf8


def index():
5
    import gluon.contrib.simplejson
Marc Duez's avatar
Marc Duez committed
6
7
8
9
    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
10
11
12
13
14
        
    if not auth.user : 
        res = {"redirect" : "default/user/login"}
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
    
Marc Duez's avatar
Marc Duez committed
15
16
    return dict(message=T('config_list'))

17

Marc Duez's avatar
Marc Duez committed
18
19
20
21
22
23
24
def add(): 
    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
    return dict(message=T('add config'))

25

Marc Duez's avatar
Marc Duez committed
26
27
28
29
30
31
32
33
#TODO check data
def add_form(): 
    import gluon.contrib.simplejson, shutil, os.path
    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
    
34
35
36
37
38
39
40
41
42
        
    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
43
44
    if request.vars['config_germline'] == "" : 
        error += "germline needed, "
45
46
47
48
49
50

    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
51
                        germline=request.vars['config_germline']
52
53
                        )

Marc Duez's avatar
Marc Duez committed
54
55
        res = {"redirect": "config/index",
               "message": "config added"}
56
57
58
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
        
    else :
Marc Duez's avatar
Marc Duez committed
59
        res = {"success" : "false", "message" : error}
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))


def edit(): 
    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
    return dict(message=T('edit config'))


def edit_form(): 
    import gluon.contrib.simplejson, shutil, os.path
    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
77
    
78
79
80
81
82
83
84
    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
85
86
87
        error += "command needed, "
    if request.vars['config_germline'] == "" : 
        error += "germline needed, "
88
89
90
91
92
93

    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
94
                                            germline=request.vars['config_germline']
95
96
                                            )

Marc Duez's avatar
Marc Duez committed
97
98
        res = {"redirect": "config/index",
               "message": "config saved"}
99
100
101
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))

    else :
Marc Duez's avatar
Marc Duez committed
102
        res = {"success" : "false", "message" : error}
103
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

def confirm():
    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
    return dict(message=T('confirm config deletion'))

def delete():
    import gluon.contrib.simplejson, shutil, os.path
    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
    
    #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
125
126
    res = {"redirect": "config/index",
           "message": "config deleted"}
127
    return gluon.contrib.simplejson.dumps(res, separators=(',',':'))