Redigera och ta bort foton
This commit is contained in:
parent
0cdc75f1f9
commit
d2d122fc98
@ -16,3 +16,8 @@ class PageForm(FlaskForm):
|
|||||||
widget=widgets.ListWidget(prefix_label=False),
|
widget=widgets.ListWidget(prefix_label=False),
|
||||||
get_label = lambda p: '<img src="/thumbnail/{}">'.format(p.id))
|
get_label = lambda p: '<img src="/thumbnail/{}">'.format(p.id))
|
||||||
submit = SubmitField('Ok')
|
submit = SubmitField('Ok')
|
||||||
|
|
||||||
|
class PhotoForm(FlaskForm):
|
||||||
|
alt = StringField('Beskrivning', validators=[DataRequired()])
|
||||||
|
link = QuerySelectField('Länkar till', get_label = lambda p: '{} - {}'.format(p.permalink, p.title))
|
||||||
|
submit = SubmitField('Ok')
|
||||||
|
@ -127,7 +127,7 @@
|
|||||||
<div class="thumbnail">
|
<div class="thumbnail">
|
||||||
<img src="{{ photo.thumbnail }}" class="img-responsive">
|
<img src="{{ photo.thumbnail }}" class="img-responsive">
|
||||||
<div class="panel-footer">
|
<div class="panel-footer">
|
||||||
<a class="btn btn-default"><span class="glyphicon glyphicon-pencil"></a>
|
<a href="{{url_for('admin_photo', id=photo.id)}}" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></a>
|
||||||
{{ delete_button('photo', photo.alt, photo.id) }}
|
{{ delete_button('photo', photo.alt, photo.id) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -154,7 +154,7 @@ $('#deletemodal').on('show.bs.modal', function (event) {
|
|||||||
var href = '/admin/delpage/' + id
|
var href = '/admin/delpage/' + id
|
||||||
} else {
|
} else {
|
||||||
var message = 'Vill du verkligen ta bort bilden - ' + title + '?'
|
var message = 'Vill du verkligen ta bort bilden - ' + title + '?'
|
||||||
var href = '##'
|
var href = '/admin/delphoto/' + id
|
||||||
}
|
}
|
||||||
modal.find('.modal-body p').text(message)
|
modal.find('.modal-body p').text(message)
|
||||||
modal.find('.modal-footer a').attr('href', href)
|
modal.find('.modal-footer a').attr('href', href)
|
||||||
|
31
app/templates/admin_photo.html
Normal file
31
app/templates/admin_photo.html
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% import "bootstrap/wtf.html" as wtf %}
|
||||||
|
{% block navbar %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<form class="form-horizontal" method="post" role="form">
|
||||||
|
|
||||||
|
{{ wtf.form_field(form.alt, form_type="horizontal") }}
|
||||||
|
|
||||||
|
{{ wtf.form_field(form.link, form_type="horizontal") }}
|
||||||
|
|
||||||
|
{{ wtf.form_field(form.submit, form_type="horizontal") }}
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="thumbnail">
|
||||||
|
<img src="{{photo.slide}}" class="img-responsive">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
27
app/views.py
27
app/views.py
@ -3,7 +3,7 @@ from flask import render_template, send_from_directory, redirect, url_for, reque
|
|||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from . import app, db
|
from . import app, db
|
||||||
from .models import Page, Photo
|
from .models import Page, Photo
|
||||||
from .forms import PageForm
|
from .forms import PageForm, PhotoForm
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@ -100,3 +100,28 @@ def upload():
|
|||||||
os.remove(tempname)
|
os.remove(tempname)
|
||||||
|
|
||||||
return redirect(url_for('admin'))
|
return redirect(url_for('admin'))
|
||||||
|
@app.route('/admin/delphoto/<id>')
|
||||||
|
def admin_delphoto(id):
|
||||||
|
photo = Photo.query.filter_by(id=id).first_or_404()
|
||||||
|
db.session.delete(photo)
|
||||||
|
db.session.commit()
|
||||||
|
filename = '{}.jpg'.format(id)
|
||||||
|
imgpath = os.path.join('app', 'photos', filename)
|
||||||
|
thumb = os.path.join('app', 'photos', 'thumbs', filename)
|
||||||
|
slide = os.path.join('app', 'photos', 'slides', filename)
|
||||||
|
os.remove(imgpath)
|
||||||
|
os.remove(thumb)
|
||||||
|
os.remove(slide)
|
||||||
|
return redirect(url_for('admin'))
|
||||||
|
@app.route('/admin/photo/<id>', methods=['GET', 'POST'])
|
||||||
|
def admin_photo(id):
|
||||||
|
photo = Photo.query.filter_by(id=id).first_or_404()
|
||||||
|
form = PhotoForm(obj=photo)
|
||||||
|
form.link.query = Page.query.all()
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
form.populate_obj(photo)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('admin'))
|
||||||
|
else:
|
||||||
|
return render_template('admin_photo.html', photo=photo, form=form)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user