From 981b49880f80ceb137a10d0452f4977413c1130b Mon Sep 17 00:00:00 2001 From: Priyal Vyas Date: Fri, 9 Apr 2021 12:56:09 +0530 Subject: [PATCH] prevent user from adding duplicate tag --- app.py | 1 + core/views.py | 16 +++++++++++++--- manage.py | 2 +- notes.db | Bin 9216 -> 9216 bytes templates/add_tag.html | 9 +++++++++ templates/profile.html | 2 +- templates/profile_settings.html | 4 ++-- templates/view_tag.html | 1 + utils/forms.py | 2 +- 9 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index d141945..a99a5ed 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ from flask import Flask from flask_restful import Api + from flask_pagedown import PageDown import os diff --git a/core/views.py b/core/views.py index 840da2f..1bb41fa 100644 --- a/core/views.py +++ b/core/views.py @@ -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']) @@ -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: diff --git a/manage.py b/manage.py index 64f0877..1d4107d 100644 --- a/manage.py +++ b/manage.py @@ -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") diff --git a/notes.db b/notes.db index 285d806fe7313ad3e04c7a7290a46912da3d943b..31ca93d74efc34e0350ed71f96f0be7fb572fef9 100644 GIT binary patch delta 308 zcmZqhXz-XI#l*-yQO1dlk)1)$eZ|I}$c14{)%BP&A-DOj5^}Ldd0hJ{g`FYID5ez6CBV-v>VMaqEV~`qYK}JVU5JL#Y;Dj)q zGI+xnPB4ZgjA4K<>?wmXOjJse2X6aQ2HwdNr9(Lw7$D|NekZNSXgsk|jnQ*rqwD4x HnHF{coU25} delta 135 zcmZqhXz-XI#l&!MqKp$8!$Ah!k2^M|v~r6Ja56HBGnN*o78SE_G69)+`6a2vLYsIV zF^L+Q>l#?<8k#8>m|K}zS{YaXWlAPT@GEQ<=YP#1_LzZYCcl$boY<7Rxkjdi9RMY~CV~I} diff --git a/templates/add_tag.html b/templates/add_tag.html index 40cddd4..1e2060c 100644 --- a/templates/add_tag.html +++ b/templates/add_tag.html @@ -3,6 +3,15 @@ {% block content %}
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + + {% for category, message in messages %} +
{{ message }}
+ {% endfor %} + + {% endif %} + {% endwith %} {% for message in form.tag.errors %}
{{ message }}
{% endfor %} diff --git a/templates/profile.html b/templates/profile.html index 5d70313..3c1f1f9 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -32,7 +32,7 @@ {{ loop.index }} {{ note[3] }} - {{ note[1] | custom_date }} + {{ note[1] }} {{ tags[loop.index0] }} diff --git a/templates/profile_settings.html b/templates/profile_settings.html index c3450d7..7d7909c 100644 --- a/templates/profile_settings.html +++ b/templates/profile_settings.html @@ -6,9 +6,9 @@
{% for user in user_data %}

User Details:

-

Registered on:

{{ user[1] | custom_date }}

+

Registered on:

{{ user[1] }}


-

Last Logged in on:

{{ user[2] | custom_date }}

+

Last Logged in on:

{{ user[2] }}


Email:

{{ user[5] }}


diff --git a/templates/view_tag.html b/templates/view_tag.html index 77086c8..0f73e09 100644 --- a/templates/view_tag.html +++ b/templates/view_tag.html @@ -3,6 +3,7 @@ {% block content %}
+

Notes tagged under: {{ tag_name }}


{% if username %} diff --git a/utils/forms.py b/utils/forms.py index 41e99af..fcedc25 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -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