Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent user from adding duplicate tag #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Flask
from flask_restful import Api

from flask_pagedown import PageDown
import os

Expand Down
16 changes: 13 additions & 3 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,17 @@ def add_tag():
form = AddTagForm()
if form.validate_on_submit():
tag = request.form['tag']
functions.add_tag(tag, session['id'])
return redirect('/profile/')
tags = functions.get_all_tags(session['id'])
res = list(zip(*tags))
res = set(res[1])
if tag in res:

flash("Tag Already Exists",'alert alert-danger')
return render_template('add_tag.html', form=form, username=session['username'])

else:
functions.add_tag(tag, session['id'])
return redirect('/profile/')
return render_template('add_tag.html', form=form, username=session['username'])


Expand Down Expand Up @@ -324,7 +333,8 @@ def background_process():
try:
notes = request.args.get('notes')
if notes == '':
return jsonify(result='')
temp = "No Data Exists"
return jsonify(result=Markup(temp))
results = functions.get_search_data(str(notes), session['id'])
temp = ''
for result in results:
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
app = create_app()

if __name__ == "__main__":
app.run(port="5000", debug=True, host="0.0.0.0")
app.run(port= "5000", debug=True, host="0.0.0.0")
Binary file modified notes.db
Binary file not shown.
9 changes: 9 additions & 0 deletions templates/add_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
{% block content %}
<div class="container">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}

{% for category, message in messages %}
<div class="{{ category }}">{{ message }}</div>
{% endfor %}

{% endif %}
{% endwith %}
{% for message in form.tag.errors %}
<div class="alert alert-danger">{{ message }}</div>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<tr>
<td class="text-center">{{ loop.index }}</td>
<td> <a href="/notes/{{ note[0] }}/">{{ note[3] }}</a></td>
<td>{{ note[1] | custom_date }}</td>
<td>{{ note[1] }}</td>
<td>
{{ tags[loop.index0] }}
</td>
Expand Down
4 changes: 2 additions & 2 deletions templates/profile_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<div class="thumbnail" style="padding: 3%">
{% for user in user_data %}
<legend><h3 class="text-center"><b>User Details:</b></h3></legend>
<h4><b>Registered on:</b> <br><br> {{ user[1] | custom_date }}</h4>
<h4><b>Registered on:</b> <br><br> {{ user[1] }}</h4>
<br>
<h4><b>Last Logged in on:</b> <br><br> {{ user[2] | custom_date }}</h4>
<h4><b>Last Logged in on:</b> <br><br> {{ user[2] }}</h4>
<br>
<h4><b>Email: <a href="/profile/settings/change_email/"><span class="glyphicon glyphicon-pencil"></span></a></b> <br><br> {{ user[5] }}</h4>
<br>
Expand Down
1 change: 1 addition & 0 deletions templates/view_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% block content %}
<div class="container" style="padding-top: 2%">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">

<h2> Notes tagged under: {{ tag_name }}</h2>
<br>
{% if username %}
Expand Down
2 changes: 1 addition & 1 deletion utils/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_wtf import FlaskForm
from wtforms import TextField, PasswordField, SubmitField, SelectMultipleField, HiddenField
from wtforms import TextField, PasswordField, SubmitField, SelectMultipleField, HiddenField,BooleanField
from flask_pagedown.fields import PageDownField
from wtforms import validators

Expand Down