Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jhg/sew
base: 1d9bfb84e3
...
head fork: jhg/sew
compare: 5983c042fb
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
22 blogs/views.py
@@ -4,19 +4,19 @@
from django.shortcuts import render_to_response
from django.template import Context, Template
from django.http import HttpResponse
-from settings_local import HOST
+from django.conf import settings
from blogs.models import Blog
-def blogs(plantilla, urlblog="", urlarticulo=""):
+def blogs(request, plantilla, urlblog="", urlarticulo=""):
blogs = Blog.objects.filter(publicado=True, bloqueado=False)
num_blogs = len(blogs)
- host = HOST.strip("/")
+ host = request.get_host().strip("/")
return render_to_response(plantilla, locals())
def index_blog(request):
- return blogs('blogs/index.htm')
+ return blogs(request, 'blogs/index.htm')
# NOTA: Optimizar y refactorizar todo el código de este archivo
@@ -24,11 +24,11 @@ def blog(request, urlblog):
try:
blog = Blog.objects.get(url=urlblog) # Encontramos el blog por su url
except:
- return blogs('blogs/blog_inexistente.htm', urlblog)
+ return blogs(request, 'blogs/blog_inexistente.htm', urlblog)
if blog.bloqueado:
- return blogs('blogs/blog_bloqueado.htm', urlblog)
+ return blogs(request, 'blogs/blog_bloqueado.htm', urlblog)
if not blog.publicado:
- return blogs('blogs/blog_inexistente.htm', urlblog)
+ return blogs(request, 'blogs/blog_inexistente.htm', urlblog)
# Extraemos los articulos publicados en el blog y los ordenamos
articulos = blog.articulo_set.filter(publicado=True)
articulos = articulos.order_by("publicacion").reverse()
@@ -56,15 +56,15 @@ def articulo_blog(request, urlblog, urlarticulo):
try:
blog = Blog.objects.get(url=urlblog) # Encontramos el blog por su url
except:
- return blogs('blogs/blog_inexistente.htm', urlblog)
+ return blogs(request, 'blogs/blog_inexistente.htm', urlblog)
if blog.bloqueado:
- return blogs('blogs/blog_bloqueado.htm', urlblog)
+ return blogs(request, 'blogs/blog_bloqueado.htm', urlblog)
if not blog.publicado:
- return blogs('blogs/blog_inexistente.htm', urlblog)
+ return blogs(request, 'blogs/blog_inexistente.htm', urlblog)
# Extraemos el articulo
articulos = blog.articulo_set.filter(publicado=True, url=urlarticulo)
if articulos.count() == 0:
- return blogs('blogs/blog_inexistente.htm', urlblog, urlarticulo)
+ return blogs(request, 'blogs/blog_inexistente.htm', urlblog, urlarticulo)
# Usamos la propia plantilla del blog
plantilla = Template('{% extends "blogs/blog_index.htm" %}\n'
+ "{% load i18n static %}\n"
View
2  plantillas/construccion.htm
@@ -1,2 +1,2 @@
{% extends "principal.htm" %}
-{% block titulo %}En construccion {{ idsite }}{% endblock %}
+{% block titulo %}En construccion{% endblock %}
View
11 settings_local.py
@@ -110,11 +110,6 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'vwz(3e9-zuqf)l-&6srbf7xk*gklc^*ed#=m7=lcq95mkvresz'
-# Host donde esta alojado SEW
-HOST = '127.0.0.1:8000'
-
-# Alojamiento de los archivos subidos
-MEDIA_HOST = '//' + HOST + '/'
-
-# Alojamiento de los archivos estaticos
-STATIC_HOST = '//' + HOST + '/'
+# Dominio predeterminado del servidor
+# Ejemplo: '127.0.0.1:8000'
+DEFAULT_HOST = '127.0.0.1:8000'
View
48 sew/middleware/DynamicSites.py
@@ -0,0 +1,48 @@
+#-*- coding: UTF-8 -*-
+from threading import local
+from django.conf import settings
+from django.contrib.sites.models import Site
+import re
+
+
+class SetDynamicSites(object):
+ def process_request(self, request):
+ try:
+ current_site = Site.objects.get(domain=request.get_host())
+ settings.SITE_ID._set(current_site.id)
+ settings.MEDIA_URL='//' + request.get_host() + settings.MEDIA_URL_DIR
+ settings.STATIC_URL='//' + request.get_host() + settings.STATIC_URL_DIR
+ except:
+ settings.SITE_ID._set(1)
+
+SITE_THREAD_INFO = local()
+
+class DynamicSiteId(object):
+ def __init__(self):
+ SITE_THREAD_INFO.SITE_ID = 1
+ def __unicode__(self):
+ try:
+ return unicode(SITE_THREAD_INFO.SITE_ID)
+ except AttributeError:
+ SITE_THREAD_INFO.SITE_ID = 1
+ return unicode(SITE_THREAD_INFO.SITE_ID)
+ def __str__(self):
+ try:
+ return str(SITE_THREAD_INFO.SITE_ID)
+ except AttributeError:
+ SITE_THREAD_INFO.SITE_ID = 1
+ return str(SITE_THREAD_INFO.SITE_ID)
+ def __hash__(self):
+ try:
+ return SITE_THREAD_INFO.SITE_ID
+ except AttributeError:
+ SITE_THREAD_INFO.SITE_ID = 1
+ return SITE_THREAD_INFO.SITE_ID
+ def __int__(self):
+ try:
+ return SITE_THREAD_INFO.SITE_ID
+ except AttributeError:
+ SITE_THREAD_INFO.SITE_ID = 1
+ return SITE_THREAD_INFO.SITE_ID
+ def _set(self, value):
+ SITE_THREAD_INFO.SITE_ID = int(value)
View
0  sew/middleware/__init__.py
No changes.
View
33 sew/settings.py
@@ -3,21 +3,18 @@
import os
from settings_local import *
+from sew.middleware.DynamicSites import DynamicSiteId, SITE_THREAD_INFO
MANAGERS = ADMINS
-SITE_ID = 1
+# ID de sitio dinamico segun peticiones
+SITE_ID = DynamicSiteId()
-# If you set this to False, Django will make some optimizations so as not
-# to load the internationalization machinery.
-USE_I18N = True
-
-# If you set this to False, Django will not format dates, numbers and
-# calendars according to the current locale.
-USE_L10N = True
+# URL despues del dominio para los archivos cargados
+MEDIA_URL_DIR = '/cargas/'
-# If you set this to False, Django will not use timezone-aware datetimes.
-USE_TZ = True
+# URL despues del dominio para los archivos estaticos
+STATIC_URL_DIR = '/estaticos/'
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
@@ -26,7 +23,7 @@
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
-MEDIA_URL = MEDIA_HOST + 'cargas/'
+MEDIA_URL = '//' + DEFAULT_HOST + MEDIA_URL_DIR
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
@@ -36,7 +33,7 @@
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
-STATIC_URL = STATIC_HOST + 'estaticos/'
+STATIC_URL = '//' + DEFAULT_HOST + STATIC_URL_DIR
# Additional locations of static files
STATICFILES_DIRS = (
@@ -53,6 +50,17 @@
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale.
+USE_L10N = True
+
+# If you set this to False, Django will not use timezone-aware datetimes.
+USE_TZ = True
+
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
@@ -61,6 +69,7 @@
)
MIDDLEWARE_CLASSES = (
+ 'sew.middleware.DynamicSites.SetDynamicSites',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
View
4 sew/views.py
@@ -1,8 +1,8 @@
from blogs.models import Blog
from django.shortcuts import render_to_response
from django.conf import settings
+from django.contrib.sites.models import Site
def index(request):
- idsite = settings.SITE_ID
- return render_to_response('construccion.htm', {"idsite": idsite})
+ return render_to_response('construccion.htm')

No commit comments for this range

Something went wrong with that request. Please try again.