Пример #1
0
def get_login_status(request):
    if request.user.is_authenticated():
        return json({
            'status':'authenticated',
            'username' : request.user.username
        });
    else:
        return json({'status' : 'not_authenticated'});
Пример #2
0
def authenticate_and_login(request, username,password):
    user = auth.authenticate(username=username, password=password)
    if user is not None:
        auth.login(request, user)
        return json({
            'status': 'success',
            'username': user.username
        });
    else:
        return json({'status': 'failure'});
Пример #3
0
 def get(self, request, *args, **kwargs):
     data = {
         "fish_total": Fish.living.count(),
         "fish_today": Fish.today_reg_count(),
         "mobile_black_total": ExcceedMobile.living.count(),
         "mobile_black_today": ExcceedMobile.today_count(),
     }
     return utils.json(data)
Пример #4
0
def search_pet(request):
    if request.method == 'POST':
        form = SearchForm(request.POST)
        return json({
                'success': 'true',
                'redirect_url': '/pets/pets/'
        })
    raise Http404
Пример #5
0
def new_pet(request):
    if request.method == 'POST':
        form = DatingForm(request.POST)
        if form.is_valid():
            pet = form.save()
            return json({
                'success': 'true',
                'redirect_url': '/pets/pets/'
            })
    raise Http404
Пример #6
0
def new_question(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.normalize_description()
            question.questioner = request.user
            question.save()
            return json({
                'success': 'true',
                'redirect_url': '/forum/questions/'+ str(question.pk)
            })
    raise Http404
Пример #7
0
def answer(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            answer = form.save(commit=False)
            answer.answerer = request.user
            question_id = atoi(request.POST['question_id'])
            answer.question = Question.objects.get(id=question_id)
            answer.user = request.user
            answer.normalize_text()
            answer.save()
            return json({
                'success' : True,
                'redirect_url' : '/forum/questions/' + str(question_id)
            })
    raise Http404