if commit:
user.save()
return user
if commit:
user.save()
return user
from registration.backends.default.views import RegistrationView
а не from registration.views import RegistrationView
ACCOUNT_USER_DISPLAY (=a callable returning user.username)
A callable (or string of the form 'some.module.callable_name') that takes a user as its only argument and returns the display name of the user. The default implementation returns user.username.
ACCOUNT_USER_DISPLAY = lambda user: u'%s %s' % (user.first_name, user.last_name)
илиACCOUNT_USER_DISPLAY = lambda user: user.get_full_name()
илиACCOUNT_USER_DISPLAY = 'myapp.somemodule.utils.user_display'
def authenticate(username=None, password=None, **kwargs):
from django.contrib.auth import get_user_model
UserModel = get_user_model()
if username is None:
username = kwargs.get(UserModel.USERNAME_FIELD)
try:
user = UserModel._default_manager.get_by_natural_key(username)
if user.check_password(password):
return user
except UserModel.DoesNotExist:
# Run the default password hasher once to reduce the timing
# difference between an existing and a non-existing user (#20760).
UserModel().set_password(password)
You may need to add u'www.cirk.irk.ru' to ALLOWED_HOSTS
def base_context(func):
def wrapped(*args, **kwargs):
context_dict = {'categories_menu': Category.objects.filter(menu=True)}
kwargs['context_dict'] = context_dict
return func(*args, **kwargs)
return wrapped
@base_context
def index(request, **kwargs):
page_list_new = Page.objects.order_by('-datetime')[:5]
context_dict = kwargs.get('context_dict', {})
context_dict['pages_new'] = page_list_new
return render(request, 'home/index.html', context_dict)
class NewOrdersMiddleware(object):
def process_request(self, request):
request.some_variable = 'some value'
for element in Element.objects.filter(contest = active_contest):
header_table.append(element.title)
header_table = Element.objects.filter(contest = active_contest).values_list('title', flat=True)
tmp_user.update({
'username': get_object_or_none(User, id = user.user.id).username
})
tmp_user['username'] = user.user.username if user.user else None
try:
tmp_user.update({
'last_date_find_element': Data.objects.filter(showing=2, useractive=user.id).order_by('-date_review')[:1].get().date_review
})
except:
tmp_user.update({
'last_date_find_element': None
})
data_obj = Data.objects.filter(showing=2, useractive=user.id).order_by('-date_review').first()
tmp_user['last_date_find_element'] = data_obj.date_review if data_obj else None