Add mobile static path configuration and update upload view for mobile files

1 parent 9d593687
5.0.2
Menambahkan path static 'mobi' and configuration 'mobile_static_path'
5.0.1 5.0.1
- Bug Saat get captcha session tidak berfungsi dimana ditambahkan checking melalui - Bug Saat get captcha session tidak berfungsi dimana ditambahkan checking melalui
file jpg yang tersimpan dalam folder captcha files file jpg yang tersimpan dalam folder captcha files
......
...@@ -8,6 +8,7 @@ import datetime ...@@ -8,6 +8,7 @@ import datetime
import decimal import decimal
import deform import deform
import traceback import traceback
import opensipkd
from pkg_resources import resource_filename from pkg_resources import resource_filename
from pyramid.renderers import JSON from pyramid.renderers import JSON
from pyramid_beaker import session_factory_from_settings from pyramid_beaker import session_factory_from_settings
...@@ -303,9 +304,16 @@ def get_config(settings): ...@@ -303,9 +304,16 @@ def get_config(settings):
# if not os.path.exists(partner_files): # if not os.path.exists(partner_files):
# os.makedirs(partner_files) # os.makedirs(partner_files)
config.add_static_view('static', 'opensipkd.base:static', config.add_static_view('static', 'opensipkd.base:static', cache_max_age=3600)
cache_max_age=3600) mobile_static_path = settings.get('mobile_static_path')
if not mobile_static_path:
mobi_path = os.path.dirname(opensipkd.base.__file__)
mobile_static_path = os.path.join(mobi_path, 'static', 'mobile')
if not os.path.exists(mobile_static_path):
mobile_static_path = os.makedirs(mobile_static_path)
config.add_static_view('mobi', mobile_static_path+os.sep, cache_max_age=3600)
config.add_static_view('deform_static', 'deform:static') config.add_static_view('deform_static', 'deform:static')
# config.add_static_view(partner_idcard_url, # config.add_static_view(partner_idcard_url,
......
...@@ -45,7 +45,8 @@ class AddSchema(CSRFSchema): ...@@ -45,7 +45,8 @@ class AddSchema(CSRFSchema):
image_for = colander.SchemaNode( image_for = colander.SchemaNode(
colander.String(), colander.String(),
widget=widget.SelectWidget(values=(('oth', "Other"), ('logo', "Logo"), widget=widget.SelectWidget(values=(('oth', "Other"), ('logo', "Logo"),
('bg', "Background"))), ('bg', "Background"),
('mobile', "Mobile Files"),)),
title='Peruntukan') title='Peruntukan')
...@@ -75,6 +76,14 @@ def view_file(request): ...@@ -75,6 +76,14 @@ def view_file(request):
fname = f"logo{ext}" fname = f"logo{ext}"
elif request.POST["image_for"] == "bg": elif request.POST["image_for"] == "bg":
fname = f"background{ext}" fname = f"background{ext}"
elif request.POST["image_for"] == "mobile":
mobile_static_path = request.registry.settings.get(
'mobile_static_path', None)
if not mobile_static_path:
request.session.flash("Mobile static path belum dikonfigurasi", 'error')
return dict(form=form.render())
static_path = os.path.join(mobile_static_path)
typ = ext == '.png' and "img" or 'icon' typ = ext == '.png' and "img" or 'icon'
folder = os.path.join(static_path, typ) folder = os.path.join(static_path, typ)
if not os.path.exists(folder): if not os.path.exists(folder):
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!