parent
bf33790b92
commit
df244e47cd
|
@ -8,7 +8,6 @@ django-solo==1.1.0
|
|||
django-import-export==0.2.6
|
||||
|
||||
# Fixes
|
||||
longerusername==0.4
|
||||
|
||||
# Statics
|
||||
django-compressor==1.4
|
||||
|
|
|
@ -22,6 +22,7 @@ def user_configuration(request):
|
|||
},
|
||||
}
|
||||
|
||||
|
||||
def auth(request):
|
||||
result = {}
|
||||
if request.user.is_authenticated():
|
|
@ -0,0 +1,137 @@
|
|||
# coding: utf-8
|
||||
from hashlib import md5
|
||||
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth.models import UserManager
|
||||
from django.contrib.auth.models import (AbstractBaseUser, PermissionsMixin)
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class User(AbstractBaseUser,
|
||||
PermissionsMixin):
|
||||
"""
|
||||
|
||||
"""
|
||||
MALE = 'male'
|
||||
FEMALE = 'female'
|
||||
GENDER_CHOICES = (
|
||||
(MALE, _('Male')),
|
||||
(FEMALE, _('Female'))
|
||||
)
|
||||
|
||||
@property
|
||||
def avatar(self):
|
||||
avatar = '{}{}?s=300'.format(
|
||||
'http://www.gravatar.com/avatar/',
|
||||
md5(self.email.lower()).hexdigest()
|
||||
)
|
||||
return avatar
|
||||
|
||||
email = models.EmailField(
|
||||
verbose_name=_('Email address'),
|
||||
max_length=255,
|
||||
unique=True,
|
||||
db_index=True,
|
||||
help_text=_('An user email that should be verified.')
|
||||
)
|
||||
|
||||
username = models.CharField(
|
||||
verbose_name=_('Username'),
|
||||
max_length=128,
|
||||
unique=True,
|
||||
blank=True,
|
||||
null=True,
|
||||
db_index=True,
|
||||
default=None,
|
||||
)
|
||||
|
||||
# personal info
|
||||
first_name = models.CharField(
|
||||
verbose_name=_('First name'),
|
||||
max_length=80, blank=True, default='',
|
||||
)
|
||||
|
||||
last_name = models.CharField(
|
||||
verbose_name=_('Last name'),
|
||||
max_length=80, blank=True, default='',
|
||||
)
|
||||
|
||||
birthdate = models.DateField(
|
||||
verbose_name=_('Birthdate'),
|
||||
null=True,
|
||||
blank=True,
|
||||
default=None,
|
||||
)
|
||||
|
||||
gender = models.CharField(
|
||||
verbose_name=_('Gender'),
|
||||
max_length=80,
|
||||
choices=GENDER_CHOICES,
|
||||
blank=True,
|
||||
default=''
|
||||
)
|
||||
|
||||
date_joined = models.DateTimeField(
|
||||
verbose_name=_('Date joined'),
|
||||
auto_now_add=True,
|
||||
editable=False,
|
||||
)
|
||||
|
||||
is_active = models.BooleanField(
|
||||
verbose_name=_('Active status'),
|
||||
default=True,
|
||||
help_text=_('Designates whether this user should be treated as '
|
||||
'active. Unselect this instead of deleting accounts.')
|
||||
)
|
||||
|
||||
is_staff = models.BooleanField(
|
||||
verbose_name=_('Staff status'),
|
||||
default=False,
|
||||
help_text=_('Designates whether the user can log into this admin '
|
||||
'site.')
|
||||
)
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
REQUIRED_FIELDS = ('email', )
|
||||
|
||||
objects = UserManager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('User')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.username
|
||||
|
||||
@property
|
||||
def is_confirmed(self):
|
||||
return self.CONFIRMED == self.status
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return '{first_name} {last_name}'.format(
|
||||
first_name=self.first_name.strip(),
|
||||
last_name=self.last_name.strip()
|
||||
)
|
||||
|
||||
@property
|
||||
def age(self):
|
||||
"""Age of the user
|
||||
|
||||
Returns the age of the user if she has a defined birthdate.
|
||||
"""
|
||||
if self.birthdate is None:
|
||||
return None
|
||||
else:
|
||||
today = timezone.now()
|
||||
birthdate = self.birthdate
|
||||
try:
|
||||
birthdate.replace(year=today.year)
|
||||
except ValueError:
|
||||
# Raises only with 29th February and current not leap year
|
||||
birthdate_day = 28
|
||||
else:
|
||||
birthdate_day = birthdate.day
|
||||
return today.year - birthdate.year - (
|
||||
(today.month, today.day) < (birthdate.month, birthdate_day)
|
||||
)
|
|
@ -1,6 +1,6 @@
|
|||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import LoginView, LogoutView,UserProfileView
|
||||
from .views import LoginView, LogoutView, UserProfileView
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
|
@ -2,7 +2,7 @@ from django.views.generic import View
|
|||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response
|
||||
from django.db.models import Count
|
||||
from shelfzilla.apps.users.models import User
|
||||
from django.contrib.auth import get_user_model
|
||||
from shelfzilla.apps.manga.models import Volume, Series
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@ class HomepageView(View):
|
|||
data = {}
|
||||
from datetime import datetime
|
||||
# TOP 5
|
||||
data['TOP_5_COLLECTORS'] = User.objects.filter(pk__gt=1)\
|
||||
data['TOP_5_COLLECTORS'] = get_user_model().objects.filter(pk__gt=1)\
|
||||
.annotate(num_volumes=Count('have_volumes'))\
|
||||
.order_by('-num_volumes')[:5]
|
||||
|
||||
|
@ -29,7 +29,7 @@ class HomepageView(View):
|
|||
|
||||
# Stats
|
||||
data['STATS'] = {
|
||||
'users': User.objects.count() - 1,
|
||||
'users': get_user_model().objects.count() - 1,
|
||||
'series': Series.objects.count(),
|
||||
'series_review': Series.objects.filter(for_review=True).count(),
|
||||
'volumes': Volume.objects.count(),
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
[
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "auth.group",
|
||||
"fields": {
|
||||
"name": "Beta Access",
|
||||
"permissions": []
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,15 +0,0 @@
|
|||
from hashlib import md5
|
||||
from django.contrib.auth.models import User as UserModel
|
||||
|
||||
|
||||
class User(UserModel):
|
||||
@property
|
||||
def avatar(self):
|
||||
avatar = '{}{}?s=300'.format(
|
||||
'http://www.gravatar.com/avatar/',
|
||||
md5(self.email.lower()).hexdigest()
|
||||
)
|
||||
return avatar
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
|
@ -32,14 +32,13 @@ ALLOWED_HOSTS = []
|
|||
# Application definition
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'longerusername',
|
||||
|
||||
# Admin
|
||||
'suit',
|
||||
'django.contrib.admin',
|
||||
'solo',
|
||||
|
||||
# Django
|
||||
'shelfzilla.apps.account',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
|
@ -63,7 +62,6 @@ INSTALLED_APPS = (
|
|||
# Apps
|
||||
'shelfzilla.apps._admin',
|
||||
'shelfzilla.apps.config',
|
||||
'shelfzilla.apps.users',
|
||||
'shelfzilla.apps.homepage',
|
||||
'shelfzilla.apps.landing',
|
||||
'shelfzilla.apps.manga',
|
||||
|
@ -85,9 +83,9 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
|||
'shelfzilla.apps.manga.context_processors.user_have_volumes',
|
||||
'shelfzilla.apps.manga.context_processors.user_wishlisted_volumes',
|
||||
'shelfzilla.apps.manga.context_processors.user_read_volumes',
|
||||
'shelfzilla.apps.users.context_processors.auth',
|
||||
'shelfzilla.apps.users.context_processors.user_is_staff',
|
||||
'shelfzilla.apps.users.context_processors.user_configuration',
|
||||
'shelfzilla.apps.account.context_processors.auth',
|
||||
'shelfzilla.apps.account.context_processors.user_is_staff',
|
||||
# 'shelfzilla.apps.account.context_processors.user_configuration',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
|
@ -292,3 +290,8 @@ CKEDITOR_CONFIGS = {
|
|||
'width': '100%',
|
||||
},
|
||||
}
|
||||
|
||||
#
|
||||
# AUTH
|
||||
#
|
||||
AUTH_USER_MODEL = 'account.User'
|
||||
|
|
|
@ -13,7 +13,7 @@ urlpatterns = patterns(
|
|||
url(r'^messages/$', MessagesView.as_view(), name="contrib.messages"),
|
||||
url(r'^$', include('shelfzilla.apps.homepage.urls')),
|
||||
url(r'^', include('shelfzilla.apps.landing.urls')),
|
||||
url(r'^', include('shelfzilla.apps.users.urls')),
|
||||
url(r'^', include('shelfzilla.apps.account.urls')),
|
||||
url(r'^blog/', include('shelfzilla.apps.blog.urls', namespace='blog')),
|
||||
url(r'^series/', include('shelfzilla.apps.manga.urls.series')),
|
||||
url(r'^volumes/', include('shelfzilla.apps.manga.urls.volumes')),
|
||||
|
|
Reference in New Issue