kopia lustrzana https://github.com/hholzgra/maposmatic/
fix reedit papersize choice step
also de-duplicate code actually shared by "new" and "reedit"dev-reedit-2
rodzic
6a974a52aa
commit
fe7f329280
|
@ -1,3 +1,61 @@
|
|||
# coding: utf-8
|
||||
|
||||
# maposmatic, the web front-end of the MapOSMatic city map generation system
|
||||
# Copyright (C) 2023 Hartmut Holzgraefe
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import www.settings
|
||||
|
||||
import ocitysmap
|
||||
|
||||
from django.utils.translation import gettext, gettext_lazy as _
|
||||
|
||||
# helper for the "new" and "reedit" views
|
||||
def _papersize_button(basename, width=None, height=None):
|
||||
format = "<button id='{0}_{1}_{2}' type='button' class='btn btn-primary papersize papersize_{1}_{2}' onclick='set_papersize({1}, {2});'><i class='fas fa-{3} fa-2x'></i></button> "
|
||||
|
||||
if width is None or height is None: # no values -> "best fit"
|
||||
return format.format(basename, "best", "fit", 'square')
|
||||
|
||||
if width == height: # square format, just one button
|
||||
return format.format(basename, width, height, 'square')
|
||||
|
||||
# individual buttons for landscape and portrait
|
||||
return format.format(basename, height, width, 'image') + format.format(basename, width, height, 'portrait')
|
||||
|
||||
def _papersize_buttons():
|
||||
_ocitysmap = ocitysmap.OCitySMap(www.settings.OCITYSMAP_CFG_PATH)
|
||||
|
||||
papersize_buttons = '<p>'
|
||||
papersize_buttons += _papersize_button('paper')
|
||||
papersize_buttons += "<b>%s</b> (<span id='best_width'>?</span>×<span id='best_height'>?</span>mm²)</p>" % _("Best fit")
|
||||
for p in _ocitysmap.get_all_paper_sizes():
|
||||
if p[1] is not None:
|
||||
papersize_buttons += "<p>"
|
||||
papersize_buttons += _papersize_button('paper', p[1], p[2])
|
||||
papersize_buttons += "<b>%s</b> (%s×%smm²)</p>" % (p[0], repr(p[1]), repr(p[2]))
|
||||
|
||||
multisize_buttons = ''
|
||||
for p in _ocitysmap.get_all_paper_sizes('multipage'):
|
||||
if p[1] is not None:
|
||||
multisize_buttons += "<p>"
|
||||
multisize_buttons += _papersize_button('multipaper', p[1], p[2])
|
||||
multisize_buttons += "<b>%s</b> (%s×%smm²)</p>" % (p[0], repr(p[1]), repr(p[2]))
|
||||
|
||||
return papersize_buttons, multisize_buttons
|
||||
|
||||
from .index import index
|
||||
|
||||
from .about import about
|
||||
|
@ -15,3 +73,5 @@ from .cancel import cancel
|
|||
from .heatmap import heatmap
|
||||
|
||||
from .congo import congo
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ from django.utils.safestring import mark_safe
|
|||
from django.urls import reverse
|
||||
|
||||
import www.settings
|
||||
from www.maposmatic import helpers, forms, models
|
||||
from www.maposmatic import helpers, forms, models, views
|
||||
|
||||
import ocitysmap
|
||||
|
||||
|
@ -54,18 +54,6 @@ def _create_upload_file(job, file, keep_until = None):
|
|||
file_instance.save()
|
||||
file_instance.job.add(job)
|
||||
|
||||
def _papersize_buttons(basename, width=None, height=None):
|
||||
format = "<button id='{0}_{1}_{2}' type='button' class='btn btn-primary papersize papersize_{1}_{2}' onclick='set_papersize({1}, {2});'><i class='fas fa-{3} fa-2x'></i></button> "
|
||||
|
||||
if width is None or height is None: # no values -> "best fit"
|
||||
return format.format(basename, "best", "fit", 'square')
|
||||
|
||||
if width == height: # square format, just one button
|
||||
return format.format(basename, width, height, 'square')
|
||||
|
||||
# individual buttons for landscape and portrait
|
||||
return format.format(basename, height, width, 'image') + format.format(basename, width, height, 'portrait')
|
||||
|
||||
def new(request):
|
||||
"""The map creation page and form."""
|
||||
|
||||
|
@ -158,23 +146,7 @@ def new(request):
|
|||
|
||||
form = forms.MapRenderingJobForm(initial=init_vals)
|
||||
|
||||
_ocitysmap = ocitysmap.OCitySMap(www.settings.OCITYSMAP_CFG_PATH)
|
||||
|
||||
papersize_buttons = '<p>'
|
||||
papersize_buttons += _papersize_buttons('paper')
|
||||
papersize_buttons += "<b>%s</b> (<span id='best_width'>?</span>×<span id='best_height'>?</span>mm²)</p>" % _("Best fit")
|
||||
for p in _ocitysmap.get_all_paper_sizes():
|
||||
if p[1] is not None:
|
||||
papersize_buttons += "<p>"
|
||||
papersize_buttons += _papersize_buttons('paper', p[1], p[2])
|
||||
papersize_buttons += "<b>%s</b> (%s×%smm²)</p>" % (p[0], repr(p[1]), repr(p[2]))
|
||||
|
||||
multisize_buttons = ''
|
||||
for p in _ocitysmap.get_all_paper_sizes('multipage'):
|
||||
if p[1] is not None:
|
||||
multisize_buttons += "<p>"
|
||||
multisize_buttons += _papersize_buttons('multipaper', p[1], p[2])
|
||||
multisize_buttons += "<b>%s</b> (%s×%smm²)</p>" % (p[0], repr(p[1]), repr(p[2]))
|
||||
papersize_buttons, multisize_buttons = views._papersize_buttons()
|
||||
|
||||
return render(request, 'maposmatic/new.html',
|
||||
{ 'form' : form ,
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
# coding: utf-8
|
||||
|
||||
# maposmatic, the web front-end of the MapOSMatic city map generation system
|
||||
# Copyright (C) 2009 David Decotigny
|
||||
# Copyright (C) 2009 Frédéric Lehobey
|
||||
# Copyright (C) 2009 Pierre Mauduit
|
||||
# Copyright (C) 2009 David Mentré
|
||||
# Copyright (C) 2009 Maxime Petazzoni
|
||||
# Copyright (C) 2009 Thomas Petazzoni
|
||||
# Copyright (C) 2009 Gaël Utard
|
||||
# Copyright (C) 2023 Hartmut Holzgraefe
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
|
@ -29,28 +22,11 @@ LOG = logging.getLogger('maposmatic')
|
|||
from django.shortcuts import get_object_or_404, render
|
||||
from django.http import HttpResponseRedirect, HttpResponseBadRequest
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext, gettext_lazy as _
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
import ocitysmap
|
||||
|
||||
import www.settings
|
||||
from www.maposmatic import helpers, forms, models
|
||||
|
||||
def _get_paper_from_size(w, h):
|
||||
oc = ocitysmap.OCitySMap(www.settings.OCITYSMAP_CFG_PATH)
|
||||
|
||||
paper_size = None
|
||||
paper_orientation = "landscape" if (w > h) else "portrait"
|
||||
|
||||
for paper in oc.get_all_paper_sizes():
|
||||
if int(paper[1]) == w and int(paper[2]) == h:
|
||||
paper_size = paper[0]
|
||||
break
|
||||
if int(paper[1]) == h and int(paper[2]) == w:
|
||||
paper_size = paper[0]
|
||||
break
|
||||
|
||||
return paper_size, paper_orientation
|
||||
|
||||
from www.maposmatic import helpers, forms, models, views
|
||||
|
||||
def reedit(request):
|
||||
if request.method == 'POST':
|
||||
|
@ -59,7 +35,6 @@ def reedit(request):
|
|||
job = get_object_or_404(models.MapRenderingJob,
|
||||
id=form.cleaned_data['id'])
|
||||
|
||||
paper_size, paper_orientation = _get_paper_from_size(job.paper_width_mm, job.paper_height_mm)
|
||||
|
||||
init_vals = {
|
||||
'layout': job.layout,
|
||||
|
@ -68,17 +43,14 @@ def reedit(request):
|
|||
'overlay': job.overlay.split(","),
|
||||
'maptitle': job.maptitle,
|
||||
'submittermail': job.submittermail,
|
||||
'default_papersize': paper_size,
|
||||
'default_paperorientation': paper_orientation,
|
||||
'paper_width_mm': job.paper_width_mm,
|
||||
'paper_height_mm': job.paper_height_mm,
|
||||
}
|
||||
|
||||
request.session['new_layout'] = job.layout
|
||||
request.session['new_indexer'] = job.indexer
|
||||
request.session['new_stylesheet'] = job.stylesheet
|
||||
request.session['new_overlay'] = job.overlay.split(",")
|
||||
|
||||
form = forms.MapRenderingJobForm(initial=init_vals)
|
||||
|
||||
papersize_buttons, multisize_buttons = views._papersize_buttons()
|
||||
|
||||
bounds = "L.latLngBounds(L.latLng(%f,%f),L.latLng(%f,%f))" % (job.lat_upper_left,
|
||||
job.lon_upper_left,
|
||||
job.lat_bottom_right,
|
||||
|
@ -88,6 +60,8 @@ def reedit(request):
|
|||
'maposmatic/new.html',
|
||||
{
|
||||
'form' : form,
|
||||
'papersize_suggestions': mark_safe(papersize_buttons),
|
||||
'multipage_papersize_suggestions': mark_safe(multisize_buttons),
|
||||
'SELECTION_BOUNDS': bounds,
|
||||
})
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue