Возможность удалять фотографии из постов
This commit is contained in:
parent
0d4d3b61ee
commit
44b21f3a6e
BIN
db/moona_data.db
BIN
db/moona_data.db
Binary file not shown.
@ -13,3 +13,4 @@ class AddPost(FlaskForm):
|
|||||||
link = TextAreaField('Вы можете оставить тут ссылки через пробел')
|
link = TextAreaField('Вы можете оставить тут ссылки через пробел')
|
||||||
public = BooleanField('Опубликовать?')
|
public = BooleanField('Опубликовать?')
|
||||||
submit = SubmitField('Сохранить')
|
submit = SubmitField('Сохранить')
|
||||||
|
del_photo = SubmitField('Удалить фотографию')
|
||||||
|
|||||||
14
main.py
14
main.py
@ -181,6 +181,13 @@ def add_question():
|
|||||||
def post_edit(id):
|
def post_edit(id):
|
||||||
global photo
|
global photo
|
||||||
post_ed = AddPost()
|
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":
|
if request.method == "GET":
|
||||||
session = db_session.create_session()
|
session = db_session.create_session()
|
||||||
post_exc = session.query(DiaryPost).filter(DiaryPost.id == id,
|
post_exc = session.query(DiaryPost).filter(DiaryPost.id == id,
|
||||||
@ -194,11 +201,12 @@ def post_edit(id):
|
|||||||
post_ed.link.data = post_exc.link
|
post_ed.link.data = post_exc.link
|
||||||
if post_exc.photo:
|
if post_exc.photo:
|
||||||
photo = post_exc.photo
|
photo = post_exc.photo
|
||||||
|
ph_f = True
|
||||||
else:
|
else:
|
||||||
photo = None
|
photo = None
|
||||||
else:
|
else:
|
||||||
abort(404)
|
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()
|
session = db_session.create_session()
|
||||||
post_exc = session.query(DiaryPost).filter(DiaryPost.id == id,
|
post_exc = session.query(DiaryPost).filter(DiaryPost.id == id,
|
||||||
DiaryPost.author == current_user.id).first()
|
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.nig_emot = post_ed.nig_emot.data
|
||||||
post_exc.link = post_ed.link.data
|
post_exc.link = post_ed.link.data
|
||||||
if post_ed.photo.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:
|
else:
|
||||||
post_exc.photo = photo
|
post_exc.photo = photo
|
||||||
session.commit()
|
session.commit()
|
||||||
return redirect('/diary')
|
return redirect('/diary')
|
||||||
else:
|
else:
|
||||||
abort(404)
|
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/<int:id>', methods=['GET', 'POST'])
|
@app.route('/post_deleted/<int:id>', methods=['GET', 'POST'])
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 798 KiB After Width: | Height: | Size: 198 KiB |
@ -29,6 +29,9 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</p>
|
</p>
|
||||||
|
{% if pht %}
|
||||||
|
{{ form.del_photo(type="submit", class="btn btn-primary") }}
|
||||||
|
{% else %}
|
||||||
<p>
|
<p>
|
||||||
{{ form.photo.label }}<br>
|
{{ form.photo.label }}<br>
|
||||||
{{ form.photo(class="form-control") }}<br>
|
{{ form.photo(class="form-control") }}<br>
|
||||||
@ -38,6 +41,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</p>
|
</p>
|
||||||
|
{% endif %}
|
||||||
<p>
|
<p>
|
||||||
{{ form.pos_emot.label }}<br>
|
{{ form.pos_emot.label }}<br>
|
||||||
{{ form.pos_emot(class="form-control") }}<br>
|
{{ form.pos_emot(class="form-control") }}<br>
|
||||||
@ -66,8 +70,8 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<div class="box">{{ form.public(class="form-check-input")}} {{ form.public.label }}<br></div>
|
<div class="box">{{ form.public(class="form-check-input")}} {{ form.public.label }}<br></div>
|
||||||
{% for error in form.public.errors %}
|
{% for error in form.public.errors %}
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
{{ error }}
|
{{ error }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user