Blogs
parent
f27d79d67a
commit
112cb677e9
|
@ -0,0 +1,8 @@
|
|||
|
||||
class SubdomainMiddleware:
|
||||
def process_request(self, request):
|
||||
request.subdomain = None
|
||||
host = request.META.get('HTTP_HOST', '')
|
||||
host_s = host.replace('www.', '').split('.')
|
||||
if len(host_s) > 2:
|
||||
request.subdomain = ''.join(host_s[:-2])
|
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -0,0 +1,5 @@
|
|||
{{ user }} has some sniptz:<br /><br />
|
||||
{% for snipt in snipts %}
|
||||
<strong>{{ snipt.title }}</strong><br />
|
||||
{{ snipt.code }}<br /><br />
|
||||
{% endfor %}
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
|
@ -0,0 +1 @@
|
|||
# Create your views here.
|
|
@ -117,6 +117,7 @@ MIDDLEWARE_CLASSES = (
|
|||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'pagination.middleware.PaginationMiddleware',
|
||||
'blogs.middleware.SubdomainMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'snipt.urls'
|
||||
|
@ -151,6 +152,7 @@ INSTALLED_APPS = (
|
|||
'taggit',
|
||||
'tastypie',
|
||||
|
||||
'blogs',
|
||||
'snipts',
|
||||
'utils',
|
||||
)
|
||||
|
@ -199,14 +201,12 @@ LOGIN_URL = '/login/'
|
|||
LOGOUT_URL = '/logout/'
|
||||
ACCOUNT_ACTIVATION_DAYS = 0
|
||||
|
||||
# Cookies
|
||||
SESSION_COOKIE_DOMAIN = '.snipt.net'
|
||||
|
||||
# HTTPS
|
||||
if not DEBUG:
|
||||
USE_HTTPS = True
|
||||
SESSION_COOKIE_SECURE = True
|
||||
CSRF_COOKIE_SECURE = True
|
||||
SESSION_COOKIE_DOMAIN = '.snipt.net'
|
||||
|
||||
# Messages
|
||||
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
|
||||
|
|
|
@ -18,6 +18,10 @@ from haystack.query import EmptySearchQuerySet, SearchQuerySet
|
|||
RESULTS_PER_PAGE = getattr(settings, 'HAYSTACK_SEARCH_RESULTS_PER_PAGE', 20)
|
||||
|
||||
def home(request):
|
||||
|
||||
if request.subdomain:
|
||||
return list_blog(request, request.subdomain)
|
||||
|
||||
if request.user.is_authenticated():
|
||||
return HttpResponseRedirect('/%s/' % request.user.username)
|
||||
else:
|
||||
|
@ -104,6 +108,23 @@ def list_user(request, username_or_custom_slug, tag_slug=None):
|
|||
|
||||
return context
|
||||
|
||||
@render_to('blogs/list.html')
|
||||
def list_blog(request, subdomain):
|
||||
|
||||
user = get_object_or_404(User, username=subdomain)
|
||||
snipts = Snipt.objects.filter(user=user, blog_post=True, public=True).order_by('-created')
|
||||
|
||||
context = {
|
||||
'snipts': snipts,
|
||||
'user': user,
|
||||
}
|
||||
|
||||
if 'rss' in request.GET:
|
||||
context['snipts'] = context['snipts'][:20]
|
||||
return rss(request, context)
|
||||
|
||||
return context
|
||||
|
||||
@render_to('snipts/detail.html')
|
||||
def detail(request, username, snipt_slug):
|
||||
|
||||
|
|
Loading…
Reference in New Issue