Пример #1
0
def like(request):
    if request.method == 'POST':  # If the form has been submitted...
        like = Like.objects.filter(object_id=request.POST['object_id'],
                                   content_type=request.POST['content_type'],
                                   author__pk=request.user.pk)
        print(len(like))
        if like.exists():
            like.delete()
            if request.is_ajax():
                d = {'success': 'SUCCESS!!!!11'}
                return HttpResponse(json.dumps(d), content_type='application/json', status=201)
            else:
                messages.info(request, 'You no longer like this %s' % like.content_type)
                return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
        else:
            like = Like(author=request.user)
            form = LikeForm(request.POST, instance=like)
            if form.is_valid():
                like = form.save(commit=False)
                like.author = request.user
                like.save()
                if request.is_ajax():
                    d = {'success': 'SUCCESS!!!!11'}
                    return HttpResponse(json.dumps(d), content_type='application/json', status=201)
                else:
                    messages.success(request, 'Like absorbed')
                    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
            else:
                messages.error(request, 'Form invalid %s' % form.errors)
                return HttpResponse(json.dumps(form.errors), content_type='application/json', status=404)
    else:
        messages.error(request, 'Did not like')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Пример #2
0
def trainingbit_stop(request, trainingbit_id):
    trainingbit = get_object_or_404(TrainingBit, pk=trainingbit_id)

    request.user.trainingbits_in_progress.remove(trainingbit)
    messages.info(request, 'You are no longer taking this training bit')

    return HttpResponseRedirect(trainingbit.get_absolute_url())
Пример #3
0
def skill_stop(request, skill_id):
    skill = get_object_or_404(Skill, pk=skill_id)

    request.user.skills_in_progress.remove(skill)
    messages.info(request, 'You are no longer taking this skill')

    return HttpResponseRedirect(skill.get_absolute_url())
Пример #4
0
def trainingbit_stop(request, trainingbit_id):
    trainingbit = get_object_or_404(TrainingBit, pk=trainingbit_id)

    request.user.trainingbits_in_progress.remove(trainingbit)
    messages.info(request, 'You are no longer taking this training bit')

    return HttpResponseRedirect(trainingbit.get_absolute_url())
Пример #5
0
def skill_stop(request, skill_id):
    skill = get_object_or_404(Skill, pk=skill_id)

    request.user.skills_in_progress.remove(skill)
    messages.info(request, 'You are no longer taking this skill')

    return HttpResponseRedirect(skill.get_absolute_url())
Пример #6
0
def skill_recommend(request, skill_id):
    skill = get_object_or_404(Skill, pk=skill_id)
    if request.user.has_perm('skills.recommend_skill', skill):
        if skill.is_recommended:
            skill.is_recommended = False
            messages.info(request, 'The skill is no longer recommended')
        else:
            skill.is_recommended = True
            messages.success(request, 'Successfully recommended skill')
        skill.save()
        return HttpResponseRedirect(skill.get_absolute_url())
    else:
        messages.error(request, 'You do not have permission to recommend this skill')
        return HttpResponseRedirect(skill.get_absolute_url())
Пример #7
0
def trainingbit_recommend(request, trainingbit_id):
    trainingbit = get_object_or_404(TrainingBit, pk=trainingbit_id)
    if request.user.has_perm('skills.recommend_trainingbit', trainingbit):
        if trainingbit.is_recommended:
            trainingbit.is_recommended = False
            messages.info(request, 'The training bit is no longer recommended')
        else:
            trainingbit.is_recommended = True
            messages.success(request, 'Successfully recommended training bit')
        trainingbit.save()
        return HttpResponseRedirect(trainingbit.get_absolute_url())
    else:
        messages.error(request, 'You do not have permission to recommend this training bit')
        return HttpResponseRedirect(trainingbit.get_absolute_url())
Пример #8
0
def skill_publicize(request, skill_id):
    skill = get_object_or_404(Skill, pk=skill_id)
    if request.user.has_perm('skills.skill_publicize', skill):
        if skill.is_draft:
            skill.is_draft = False
            messages.info(request, 'The skill is now public')
        else:
            skill.is_draft = True
            messages.success(request, 'Reverted skill to draft status')
        skill.save()
    else:
        messages.error(request, 'You do not have permission to make this skill public')

    return HttpResponseRedirect(skill.get_absolute_url())
Пример #9
0
def skill_recommend(request, skill_id):
    skill = get_object_or_404(Skill, pk=skill_id)
    if request.user.has_perm('skills.recommend_skill', skill):
        if skill.is_recommended:
            skill.is_recommended = False
            messages.info(request, 'The skill is no longer recommended')
        else:
            skill.is_recommended = True
            messages.success(request, 'Successfully recommended skill')
        skill.save()
        return HttpResponseRedirect(skill.get_absolute_url())
    else:
        messages.error(request,
                       'You do not have permission to recommend this skill')
        return HttpResponseRedirect(skill.get_absolute_url())
Пример #10
0
def skill_publicize(request, skill_id):
    skill = get_object_or_404(Skill, pk=skill_id)
    if request.user.has_perm('skills.skill_publicize', skill):
        if skill.is_draft:
            skill.is_draft = False
            messages.info(request, 'The skill is now public')
        else:
            skill.is_draft = True
            messages.success(request, 'Reverted skill to draft status')
        skill.save()
    else:
        messages.error(request,
                       'You do not have permission to make this skill public')

    return HttpResponseRedirect(skill.get_absolute_url())
Пример #11
0
def trainingbit_recommend(request, trainingbit_id):
    trainingbit = get_object_or_404(TrainingBit, pk=trainingbit_id)
    if request.user.has_perm('skills.recommend_trainingbit', trainingbit):
        if trainingbit.is_recommended:
            trainingbit.is_recommended = False
            messages.info(request, 'The training bit is no longer recommended')
        else:
            trainingbit.is_recommended = True
            messages.success(request, 'Successfully recommended training bit')
        trainingbit.save()
        return HttpResponseRedirect(trainingbit.get_absolute_url())
    else:
        messages.error(
            request,
            'You do not have permission to recommend this training bit')
        return HttpResponseRedirect(trainingbit.get_absolute_url())
Пример #12
0
def like(request):
    if request.method == 'POST':  # If the form has been submitted...
        like = Like.objects.filter(object_id=request.POST['object_id'],
                                   content_type=request.POST['content_type'],
                                   author__pk=request.user.pk)
        if like.exists():
            like.delete()
            if request.is_ajax():
                d = {'success': 'SUCCESS!!!!11'}
                return HttpResponse(json.dumps(d),
                                    content_type='application/json',
                                    status=201)
            else:
                messages.info(request,
                              'You no longer like this %s' % like.content_type)
                return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
        else:
            like = Like(author=request.user)
            form = LikeForm(request.POST, instance=like)
            if form.is_valid():
                like = form.save(commit=False)
                like.author = request.user
                like.save()
                if request.is_ajax():
                    d = {'success': 'SUCCESS!!!!11'}
                    return HttpResponse(json.dumps(d),
                                        content_type='application/json',
                                        status=201)
                else:
                    messages.success(request, 'Like absorbed')
                    return HttpResponseRedirect(
                        request.META.get('HTTP_REFERER'))
            else:
                messages.error(request, 'Form invalid %s' % form.errors)
                return HttpResponse(json.dumps(form.errors),
                                    content_type='application/json',
                                    status=404)
    else:
        messages.error(request, 'Did not like')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))