-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyFirstUI.py
More file actions
executable file
·164 lines (145 loc) · 5.87 KB
/
myFirstUI.py
File metadata and controls
executable file
·164 lines (145 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
from quixote.publish import Publisher
from quixote.directory import Directory
from quixote.util import StaticDirectory
import quixote
from urllib import quote_plus
import pkg_resources
import os.path
import jinja2
from quixote.form import Form, StringWidget, PasswordWidget
from sqlite3 import *
import startami
from session2.Session import Session as _Session
from quixote import get_user, get_session, get_session_manager, get_field
class Session(_Session, object):
def __init__(self, id):
super(Session, self).__init__(id)
self.message = None
self.my_chemicals = []
self.my_message = None
self.my_removed = []
self.search = None
def __str__(self):
return "<Session %s>" % pprint.pformat(vars(self))
def set_user(self, user):
self.user = user.db_id
def get_user(self):
if self.user is None: # user not set
return None
return database.load_user(self.user)
def has_info(self):
return True
class myFirstUI(Directory):
_q_exports = ['','A', 'B','css','imageFolder','dataSubmitted','login','registerThisUser']
imageFolder=StaticDirectory('/Volumes/KoMoDo/science/WebRelated/myFirst/mySubfolder', list_directory=1)
def __init__(self):
self.theLoginText="""<form name="theLogin" action="login" method="post">login: <input type="text" name="user" />password: <input type="password" name="pwd" /><input type="submit" name="loginButton" value="login" /><input type="submit" name="registerButton" value="register" /></form>"""
self.theLogoutText="""<form name="theLogin" action="login" method="post"><input type="submit" name="logoutButton" value="logout" /></form>"""
self.registerText=self.theLoginText
def _q_index(self):
registerText=self.registerText
# template = env.get_template('BasicView/index.html')
myVariable=templatesdir
# zipForm.add(Form.StringWidget, 'user_name', '[enter user name]',title='User name:',hint='Enter your name',size=40,required=False)
template = env.get_template('myBase.html')
theUser=get_user()
print(theUser)
return template.render(locals())
def dataSubmitted(self):
request = quixote.get_request()
form = request.form
k=request.form.keys();
myData="<p>"+form['accessKey']+"</p><p>"+form['secretKey']+"</p><p>"+form['pkName']+"</p>"
myVariable=templatesdir
template = env.get_template('mySubmit.html')
T=startami.prepareInstance('ubuntu1004x64', 'm1.large', form['accessKey'], form['secretKey'],form['pkName'], ['zsh', 'screen', 'git'],'thePIPELINEURL')
val1=T(1)
val2=T(2)
return template.render(locals())
def css(self):
cssfile = os.path.join(templatesdir, 'myStyle.css')
response = quixote.get_response()
response.set_content_type('text/css')
return open(cssfile).read()
def login(self):
request = quixote.get_request()
form = request.form
if form.has_key('registerButton'):
myVariable=templatesdir
template = env.get_template('myRegisterForm.html')
return template.render(locals())
elif form.has_key('logoutButton'):
self.registerText=self.theLoginText
registerText=self.registerText
myVariable=templatesdir
template = env.get_template('myBase.html')
return template.render(locals())
elif form.has_key('loginButton'):
conn = connect('vertexUserDB.db')
curs = conn.cursor()
curs.execute("select * from item")
identified=False
for row in curs:
print row
if row[1]==form['user'] and row[2]==form['pwd']:
accessKey=row[3]
secretKey=row[4]
pkName=row[5]
identified=True
if identified:
self.registerText=self.theLogoutText
else:
self.registerText=self.theLoginText
registerText=self.registerText
myVariable=templatesdir
template = env.get_template('myBase.html')
return template.render(locals())
def registerThisUser(self):
request = quixote.get_request()
form = request.form
conn = connect('vertexUserDB.db')
curs = conn.cursor()
curs.execute("select user from item")
identified=False
for row in curs:
if row[0]==form['user']:
identified=True
if identified:
registrationFeedback="""<p>Sorry but this user already exists, please choose a different user name.</p>"""
else:
curs.execute("insert or replace into item values (NULL,'"+form['user']+"','"+form['pwd']+"','"+form['accessKey']+"','"+form['secretKey']+"','"+form['pkName']+"')")
conn.commit()
registrationFeedback="""<p>Congratulations, you are now a registered VERTEX user! When you now login, we will alredy know all the data required to process you pipeline.</p>"""
myVariable=templatesdir
template = env.get_template('myUserRegistered.html')
return template.render(locals())
def A(self):
mfsfc=myFirstServices.firstClass;
return '''<html><p>A</p></html>'''
def B(self):
mfsfc=myFirstServices.firstClass;
return '''<html><p>B</p></html>'''
def session_manager():
from session2.store.VolatileSessionStore import VolatileSessionStore
store = VolatileSessionStore()
#DirectorySessionStore(config.sessions_dir, create=True)
from session2.SessionManager import SessionManager
session_manager = SessionManager(store)
return SessionManager(store, Session)
def create_publisher():
#publisher=Publisher(myFirstUI(),display_exceptions='plain')
#publisher=Publisher(myFirstUI(),session_manager)
#quixote.DEFAULT_CHARSET = config.output_encoding
publisher = Publisher(myFirstUI(),display_exceptions='plain',session_cookie_name="VORTEX_Session",session_manager=session_manager(),)
return publisher
if __name__ == '__main__':
thisdir = os.path.dirname(__file__)
templatesdir = os.path.join(thisdir, 'mySubfolder')
templatesdir = os.path.abspath(templatesdir)
loader = jinja2.FileSystemLoader(templatesdir)
env = jinja2.Environment(loader=loader)
from quixote.server.simple_server import run
print 'creating demo listening on http://localhost:8080/'
run(create_publisher, host='user-e47d8b.user.msu.edu', port=8080)
#run(create_publisher, host='localhost', port=8080)