0001-environment-use-current-domain-name-for-services-cre.patch
hobo/environment/utils.py | ||
---|---|---|
1 |
try: |
|
2 |
import urlparse |
|
3 |
except: |
|
4 |
import urllib.parse as urlparse |
|
5 | ||
1 | 6 |
from django.conf import settings |
2 | 7 |
from django.core.urlresolvers import reverse |
3 | 8 |
from django.db import connection |
... | ... | |
58 | 63 |
variable, created = Variable.objects.get_or_create(name=name, |
59 | 64 |
defaults={'auto': True, 'value': settings.VARIABLE_SETTINGS_DEFAULTS.get(name) or ''}) |
60 | 65 |
return variable |
66 | ||
67 |
def create_base_url(hostname, service_id): |
|
68 |
""" |
|
69 |
Distinguish mutualised domains (matching a "-" in the first part of the netloc) |
|
70 |
from the normal scenario with a dedicated parent domain. |
|
71 |
""" |
|
72 |
ph = urlparse.urlparse(hostname) |
|
73 |
parts = ph.netloc.split('.') |
|
74 |
if '-' in parts[0]: |
|
75 |
netloc = '%s-%s.%s' % (service_id, parts[0].split('-')[1], '.'.join(parts[1:])) |
|
76 |
else: |
|
77 |
netloc = '%s.%s' % (service_id, '.'.join(parts[1:])) |
|
78 |
return '%s://%s' % (ph.scheme, netloc) |
hobo/environment/views.py | ||
---|---|---|
114 | 114 | |
115 | 115 |
def get_initial(self): |
116 | 116 |
initial = super(ServiceCreateView, self).get_initial() |
117 |
initial['base_url'] = string.Template(settings.SERVICE_URL_TEMPLATE |
|
118 |
).substitute({'app': self.model.Extra.service_id}) |
|
117 |
initial['base_url'] = utils.create_base_url(self.request.build_absolute_uri(), self.model.Extra.service_id) |
|
119 | 118 |
initial['slug'] = self.model.Extra.service_default_slug |
120 | 119 |
return initial |
121 | 120 | |
122 |
- |