diff --git a/db/moona_data.db b/db/moona_data.db index d7fb9ae..cbe7b0b 100644 Binary files a/db/moona_data.db and b/db/moona_data.db differ diff --git a/forms/post.py b/forms/post.py index dbcb221..fadc9b1 100644 --- a/forms/post.py +++ b/forms/post.py @@ -13,3 +13,4 @@ class AddPost(FlaskForm): link = TextAreaField('Вы можете оставить тут ссылки через пробел') public = BooleanField('Опубликовать?') submit = SubmitField('Сохранить') + del_photo = SubmitField('Удалить фотографию') diff --git a/main.py b/main.py index d63ded5..55da686 100644 --- a/main.py +++ b/main.py @@ -181,6 +181,13 @@ def add_question(): def post_edit(id): global photo post_ed = AddPost() + ph_f = False + if post_ed.del_photo.data: + session = db_session.create_session() + post_exc = session.query(DiaryPost).filter(DiaryPost.id == id, + DiaryPost.author == current_user.id).first() + post_exc.photo = None + session.commit() if request.method == "GET": session = db_session.create_session() post_exc = session.query(DiaryPost).filter(DiaryPost.id == id, @@ -194,11 +201,12 @@ def post_edit(id): post_ed.link.data = post_exc.link if post_exc.photo: photo = post_exc.photo + ph_f = True else: photo = None else: abort(404) - if post_ed.validate_on_submit(): + if post_ed.validate_on_submit() and not post_ed.del_photo.data: session = db_session.create_session() post_exc = session.query(DiaryPost).filter(DiaryPost.id == id, DiaryPost.author == current_user.id).first() @@ -210,14 +218,14 @@ def post_edit(id): post_exc.nig_emot = post_ed.nig_emot.data post_exc.link = post_ed.link.data if post_ed.photo.data: - post_exc.photo = save_photo(post_ed.photo, current_user.login, post=True, id_post=post_exc.id) + post_exc.photo = save_photo(post_ed.photo.data, current_user.login, post=True, id_post=post_exc.id) else: post_exc.photo = photo session.commit() return redirect('/diary') else: abort(404) - return render_template('post.html', form=post_ed, message='', title='Изменить запись') + return render_template('post.html', form=post_ed, message='', title='Изменить запись', pht=ph_f) @app.route('/post_deleted/', methods=['GET', 'POST']) diff --git a/static/app_image/post_photo/Duvakin_post_3.png b/static/app_image/post_photo/Duvakin_post_3.png index 2e1ab85..d30a3ba 100644 Binary files a/static/app_image/post_photo/Duvakin_post_3.png and b/static/app_image/post_photo/Duvakin_post_3.png differ diff --git a/templates/post.html b/templates/post.html index 25bfd37..29dd5f9 100644 --- a/templates/post.html +++ b/templates/post.html @@ -29,6 +29,9 @@ {% endfor %}

+ {% if pht %} + {{ form.del_photo(type="submit", class="btn btn-primary") }} + {% else %}

{{ form.photo.label }}
{{ form.photo(class="form-control") }}
@@ -38,6 +41,7 @@ {% endfor %}

+ {% endif %}

{{ form.pos_emot.label }}
{{ form.pos_emot(class="form-control") }}
@@ -66,8 +70,8 @@ {% endfor %}

-

{{ form.public(class="form-check-input")}} {{ form.public.label }}
- {% for error in form.public.errors %} +
{{ form.public(class="form-check-input")}} {{ form.public.label }}
+ {% for error in form.public.errors %}