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
from django import forms | |
from app.models import User | |
from django.contrib.auth.hashers import check_password | |
from django.db.models import Q | |
class SignInForm(forms.Form): | |
username = forms.CharField(max_length=User._meta.get_field('email').max_length) | |
password = forms.CharField(min_length=6, max_length=16, widget=forms.PasswordInput()) |
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
from app.views.about import About | |
url(r'^about/$', About.as_view(), name='about'), |
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
from django.http import HttpResponseRedirect | |
from django.core.urlresolvers import reverse | |
class RequireSignIn(object): | |
def dispatch(self, request, *args, **kwargs): | |
if not request.user.is_authenticated(): | |
url = '{0}?next={1}'.format(reverse('signin'), request.path) |
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
from django.views import generic | |
from app.views.mixins import RequireSignIn | |
class About(RequireSignIn, generic.TemplateView): | |
template_name = 'about/index.html' | |
def get_context_data(self, **kwargs): | |
ctx = super(About, self).get_context_data(**kwargs) |
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
if form.is_valid(): | |
# ... logic to login the user ... | |
# redirect to a protected page | |
return HttpResponseRedirect(reverse('account')) |
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
from app.views.signout import SignOut | |
url(r'^signout/$', SignOut.as_view(), name='signout'), |
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
from django.views.generic.base import RedirectView | |
from django.contrib.auth import logout | |
from django.core.urlresolvers import reverse | |
class SignOut(RedirectView): | |
permanent = False | |
query_string = True |
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
HOST_IP_ADDRESS = socket.gethostbyname(socket.gethostname()) | |
HOST_NAME = socket.gethostname() | |
if string.find(HOST_NAME, '.local') is not -1: | |
DJANGO_CONF = 'dev' | |
elif HOST_IP_ADDRESS is '123.123.123.123': | |
DJANGO_CONF = 'staging' | |
else: | |
DJANGO_CONF = 'prod' |
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
from blog import Blog | |
from blogcomment import BlogComment |
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
from django.db import models | |
class Blog(models.Model): | |
title = models.CharField(max_length=255) | |
slug = models.CharField(max_length=255) | |
author = models.CharField(max_length=100) | |
blog = models.TextField() | |
image = models.CharField(max_length=20) |
OlderNewer