Last active
August 29, 2015 14:22
-
-
Save osantana/3c179063f3125da2807e to your computer and use it in GitHub Desktop.
subdomain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
import re | |
from django.contrib.sites.models import get_current_site | |
from app.models.store import Store | |
from django.conf import settings | |
class MultiStoreMiddleware: | |
def process_request(self, request): | |
fulldomain = request.get_host() | |
sitedomain = get_current_site(request).domain | |
hostname = re.sub(r"\.?%s$" % (sitedomain,), "", fulldomain) | |
try: | |
request.store = Store.objects.get(hostname=hostname) | |
request.owner = request.store.owner == request.user | |
request.analytics = request.store.analytics if request.store else settings.GOOGLE_ANALYTICS | |
except Store.DoesNotExist: | |
request.store = None | |
request.owner = False | |
request.analytics = settings.GOOGLE_ANALYTICS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIDDLEWARE_CLASSES = ( | |
'django.middleware.common.CommonMiddleware', | |
'django.contrib.sessions.middleware.SessionMiddleware', | |
'django.contrib.messages.middleware.MessageMiddleware', | |
'django.middleware.locale.LocaleMiddleware', | |
'django.middleware.csrf.CsrfViewMiddleware', | |
'django.middleware.csrf.CsrfResponseMiddleware', | |
'django.contrib.auth.middleware.AuthenticationMiddleware', | |
'app.middleware.MultiStoreMiddleware', # <---------------------- HERE! | |
'utils.ssl.SSLRedirect', | |
'utsessions.middleware.UTSessionMiddleware', | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def detail(request, product_url): | |
store = request.store | |
product = get_object_or_404(Product, store=store, url=product_url) | |
template_data = { | |
'store': store, | |
'product': product, | |
'analytics': request.analytics, | |
'submit': _('Buy'), | |
} | |
return direct_to_template(request, "product/detail.html", template_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment