-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.py
161 lines (136 loc) · 4.79 KB
/
path.py
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
__author__ = 'Zenith'
import random
import sys
import os
from flask import Flask, url_for, request, render_template, redirect
from sharplang import app
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
# database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sharplang.db'
db = SQLAlchemy(app)
class Lang(db.Model):
id = db.Column(db.Integer, primary_key=True)
word = db.Column(db.Text, unique=False)
meanEnglish = db.Column(db.Text, unique=False)
inLang = db.Column(db.Text, unique=False)
form = db.Column(db.Text, unique=False)
meaning = db.Column(db.Text, unique=False)
postdate = db.Column(db.DateTime)
is_completed = db.Column(db.Boolean)
def __init__(self, word, meanEnglish, inLang, form, meaning, postdate=None):
# def __init__(self, word,meanEnglish,inLang,form,meaning):
self.word = word.lower()
self.meanEnglish = meanEnglish.lower()
self.inLang = inLang.lower()
self.form = form.lower()
self.meaning = meaning.lower()
if postdate is None:
postdate = datetime.utcnow()
self.postdate = postdate
self.is_completed = 0
'''@app.route('/', methods=['GET', 'POST'])
def hello_world():
qr = Lang.query.all()
return render_template("index.html", qr=qr)
'''
# server: /
@app.route('/')
def hello_world():
inputLink = '<a href=' + url_for('input') + '>Input a word</a>'
lookupLink = '<a href=' + url_for('lookup') + '>Look up</a>'
return ''' <html>
<head>
<title>SharpLangs</title>
<link rel="stylesheet" href="../static/css/styles.css" type="text/css"/>
</head>
<body>
<h1>SharpLangs WebApp</h1>
''' '<div class="vasemma">' + inputLink + '</div> <div class="vasemma">' + lookupLink + '</div>' '''
</body>
</html>'''
# /add
@app.route('/add', methods=['POST'])
def add():
word = request.form['word'].lower()
inLang = request.form['inLang'].lower()
qr = Lang.query.filter_by(word=word, inLang=inLang).first()
# qr=Lang.query.filter_by(word=word).first()
# if qr is None or Lang.query.filter_by(inLang=inLang).first() is None:
if qr is None:
db.session.add(Lang(word,
meanEnglish=request.form['meanEnglish'],
inLang=request.form['inLang'],
form=request.form['form'],
meaning=request.form['meaning']))
db.session.commit()
return redirect('/')
else:
return render_template("existing.html", qr=qr)
# /add
@app.route('/filter', methods=['POST'])
def filter():
word = request.form['word'].lower()
qr = Lang.query.filter_by(word=word).first_or_404()
qrs = Lang.query.filter_by(meanEnglish=qr.meanEnglish).all()
ct = Lang.query.filter_by(meanEnglish=qr.meanEnglish).count()
return render_template("matrix.html", qrs=qrs, ct=ct)
# /input
@app.route('/input')
def input():
if request.method == 'GET':
# send user the form
return render_template('input.html')
else:
return '<h2>Invalid request</h2>'
# /lookup
@app.route('/lookup')
def lookup():
if request.method == 'GET':
# send user a form
return render_template('lookup.html')
else:
return '<h2>Invalid request</h2>'
'''old code
# /input
@app.route('/input')
def input():
if request.method == 'GET':
# send user the form
return render_template('input.html')
elif request.method == 'POST':
# read form data and save it
userId = request.form['userId']
aWord = request.form['aWord']
inLang = request.form['inLang']
wordForm = request.form['wordForm']
wordMeaning = request.form['wordMeaning']
wordSample = request.form['wordSample']
# Store data in database
# todotodo ! trying to figure these parts
return render_template('preview.html', aWord = aWord)
else:
return '<h2>Invalid request</h2>'
# /lookup
@app.route('/lookup')
def lookup():
if request.method == 'GET':
# send user a form
return render_template('lookup.html')
elif request.method == 'POST':
# read form data and save it
aWord = request.form['aWord']
inLang = request.form['inLang']
# Relate to database and find the word
# todotodo !!
return render_template('matrix.html', aWord = aWord)
else:
return '<h2>Invalid request</h2>'
# /<word>
@app.route('/<word>')
def translate(word):
aWord = 'a WORD'
# Read word from database
return render_template()
return 'Spreedsheet for <b>' + word + '</b> as follow
old code '''