mirror of
https://github.com/sigmasternchen/Diary
synced 2025-03-15 07:08:56 +00:00
Merge pull request #3 from overflowerror/testing
You can now add diaries on the index-page
This commit is contained in:
commit
83e1d37663
2 changed files with 27 additions and 2 deletions
19
server.py
19
server.py
|
@ -31,7 +31,11 @@ def index():
|
|||
if not loggedin():
|
||||
return redirect(url_for('login'))
|
||||
diaries=db.query(Diary).filter_by(owner=session['id']).all()
|
||||
return render_template('index.html',diaries=diaries)
|
||||
if request.args.get('error') == '1':
|
||||
error='you already used that name'
|
||||
else:
|
||||
error=''
|
||||
return render_template('index.html',diaries=diaries, error=error)
|
||||
|
||||
@app.route('/login',methods=['GET','POST'])
|
||||
def login():
|
||||
|
@ -49,6 +53,19 @@ def logout():
|
|||
setuser('','')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/newdiary',methods=['POST'])
|
||||
def newdiary():
|
||||
if not loggedin():
|
||||
abort(403)
|
||||
d=db.query(Diary).filter_by(name=request.form['name'], owner=session['id']).first()
|
||||
if d:
|
||||
return redirect(url_for('index', error=1))
|
||||
nd=Diary(session['id'], request.form['name'])
|
||||
db.add(nd)
|
||||
db.commit()
|
||||
return redirect(url_for('diary', name=request.form['name']))
|
||||
|
||||
|
||||
@app.route('/diary/<name>')
|
||||
def diary(name=''):
|
||||
if not loggedin():
|
||||
|
|
|
@ -7,7 +7,15 @@
|
|||
<script src="{{ url_for('static',filename='script.js') }}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p><a href="{{ url_for('logout') }}">Logout</a></p>
|
||||
{% if error != '' %}
|
||||
<div style="border: red 1px solid; color: red;">{{ error }}</div>
|
||||
{% endif %}
|
||||
<p>
|
||||
<a href="{{ url_for('logout') }}">Logout</a>
|
||||
<form method="post" action="{{ url_for('newdiary')}}">
|
||||
New diary: <input type="text" name="name" placeholder="name of diary"><input type="submit">
|
||||
</form>
|
||||
</p>
|
||||
<ul>
|
||||
{% for d in diaries %}
|
||||
<li>
|
||||
|
|
Loading…
Reference in a new issue