Пример #1
0
def user_chapters_delete(request, object_id, book_id):
    ids = request.POST.getlist('chapter_id')
    if ids:
        for chapter in Chapter.objects.filter(id__in=ids):
            chapter.delete()
    return ajax.ajax_ok(next=setting('URLROOT') + '/user/%s/book/%s/' %
                        (object_id, book_id))
Пример #2
0
def user_login(request):
    v = LoginValidator()
    f, result = v.validate(request)
    if not f:
        return ajax.ajax_fail(result)
    
    username = result['username']
    password = result['password']
    user = authenticate(username=username, password=password)
    if user is None:
        message = {'_':_('Authentication is failed!')}
        if '@' in username:
            # Mistakenly entered e-mail address instead of username? Look it up.
            try:
                user = User.objects.get(email=username)
            except User.DoesNotExist:
                message['username'] = _("Usernames cannot contain the '@' character.")
            else:
                message['username'] = _("Your e-mail address is not your username. Try '%s' instead.") % user.username
        return ajax.ajax_fail(message)
    
    # The user data is correct; log in the user in and continue.
    else:
        if user.is_staff:
            login(request, user)
            user.last_login = datetime.datetime.now()
            user.save()
        return ajax.ajax_ok(True, next=request.POST.get('next', setting('URLROOT') + '/'))
Пример #3
0
def user_register(request):
    v = RegisterValidator(request)
    if request.POST:
        f, obj = v.validate_and_save(request)
        if f:
            user = authenticate(username=obj.username, password=obj.password)
            if user and user.is_staff:
                login(request, user)
                user.last_login = datetime.datetime.now()
                user.save()
            return ajax.ajax_ok(True, next=setting('URLROOT') + '/')
        return ajax.ajax_fail(obj)
    else:
        return render_template(request, 'users/register.html')
Пример #4
0
def user_chapters_delete(request, object_id, book_id):
    ids = request.POST.getlist('chapter_id')
    if ids:
        for chapter in Chapter.objects.filter(id__in=ids):
            chapter.delete()
    return ajax.ajax_ok(next=setting('URLROOT') + '/user/%s/book/%s/' % (object_id, book_id))
Пример #5
0
            else:
                message['username'] = _("Your e-mail address is not your username. Try '%s' instead.") % user.username
        return ajax.ajax_fail(message)
    
    # The user data is correct; log in the user in and continue.
    else:
        if user.is_staff:
            login(request, user)
            user.last_login = datetime.datetime.now()
            user.save()
        return ajax.ajax_ok(True, next=request.POST.get('next', setting('URLROOT') + '/'))

from django.dispatch import dispatcher
import apps.users.signals

@decorator.redirect(setting('URLROOT') + '/')                
def user_logout(request):
    dispatcher.send(signal=apps.users.signals.user_logout, request=request)
    logout(request)

@transaction.autocommit
def user_register(request):
    v = RegisterValidator(request)
    if request.POST:
        f, obj = v.validate_and_save(request)
        if f:
            user = authenticate(username=obj.username, password=obj.password)
            if user and user.is_staff:
                login(request, user)
                user.last_login = datetime.datetime.now()
                user.save()
Пример #6
0
 def link(self):
     return setting('URLROOF') + '/booklist/'
Пример #7
0
 def link(self):
     return setting('URLROOF') + '/book/%s/' % self.book_id
Пример #8
0
 def item_link(self, item):
     return setting('URLROOF') + '/book/%s/%s/#%s' % (
         self.book_id, item.chapter.num, item.comment_num)
Пример #9
0
 def item_link(self, item):
     return setting('URLROOF') + '/book/%d/' % item.id
Пример #10
0
 def item_link(self, item):
     return setting('URLROOF') + '/book/%d/%s/' % (item.book.id, item.num)
Пример #11
0
 def item_link(self, item):
     return setting('URLROOF') + '/book/%s/%s/#%s' % (self.book_id, item.chapter.num, item.comment_num)
Пример #12
0
 def link(self):
     return setting('URLROOF') + '/booklist/'
Пример #13
0
 def link(self):
     return setting('URLROOF') + '/book/%s/' % self.book_id
Пример #14
0
 def item_link(self, item):
     return setting('URLROOF') + '/book/%d/%s/' % (item.book.id, item.num)
Пример #15
0
 def item_link(self, item):
     return setting('URLROOF') + '/book/%d/' % item.id