65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
# combo - content management system
|
|
# Copyright (C) 2015 Entr'ouvert
|
|
#
|
|
# 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
|
|
# (at your option) 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 django.apps
|
|
from django.conf import settings
|
|
from django.core.urlresolvers import reverse
|
|
from django.db import connection
|
|
from django.test.client import RequestFactory
|
|
from django.utils import translation
|
|
from django.utils.six.moves.urllib.parse import urlparse
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
class AppConfig(django.apps.AppConfig):
|
|
name = 'combo.apps.momo'
|
|
verbose_name = _('Mobile Application')
|
|
|
|
def is_enabled(self):
|
|
return getattr(settings, 'ENABLE_MOMO', False)
|
|
|
|
def get_before_urls(self):
|
|
from . import urls
|
|
return urls.urlpatterns
|
|
|
|
def get_extra_manager_actions(self):
|
|
return [{'href': reverse('momo-manager-homepage'),
|
|
'text': _('Mobile Application')}]
|
|
|
|
def hourly(self):
|
|
from .utils import GenerationInfo
|
|
try:
|
|
self.update_momo_manifest()
|
|
except GenerationInfo:
|
|
pass
|
|
|
|
def update_momo_manifest(self):
|
|
from .utils import generate_manifest
|
|
tenant = connection.get_tenant()
|
|
parsed_base_url = urlparse(tenant.get_base_url())
|
|
if ':' in parsed_base_url.netloc:
|
|
server_name, server_port = parsed_base_url.netloc.split(':')
|
|
else:
|
|
server_name = parsed_base_url.netloc
|
|
server_port = '80' if parsed_base_url.scheme == 'http' else '443'
|
|
request = RequestFactory().get('/', SERVER_NAME=server_name,
|
|
SERVER_PORT=server_port)
|
|
request._get_scheme = lambda: parsed_base_url.scheme
|
|
|
|
with translation.override(settings.LANGUAGE_CODE):
|
|
generate_manifest(request)
|
|
|
|
default_app_config = 'combo.apps.momo.AppConfig'
|