Exemplo n.º 1
0
def create_contribution(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/login/github/?redirect=/contributor/create')

    # If the user doesn't have a github social auth, redirect to login
    if not request.user.social_auth.filter(provider='github').count():
        return HttpResponseRedirect('/login/github/?redirect=/contributor/create')
    
    try:
        contributor = Contributor.objects.get(user = request.user)
    except Contributor.DoesNotExist:
        contributor = Contributor(user = request.user)
        contributor.save()
       
    if request.method == 'POST':
        form = CreateContributionForm(request.POST)
    
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/contributor/contributions/%s' % form.instance.id)

    else:
        initial = {'contributor': contributor.id}
        form = CreateContributionForm(initial=initial)
       
    return render(request, 'contributor/create_contribution.html', {'form': form})
Exemplo n.º 2
0
def create_contribution(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect("/social-auth/login/github?redirect=/contributor/create")

    # If the user doesn't have a github social auth, redirect to login
    if not request.user.social_auth.filter(provider="github").count():
        return HttpResponseRedirect("/social-auth/login/github?redirect=/contributor/create")

    try:
        contributor = Contributor.objects.get(user=request.user)
    except Contributor.DoesNotExist:
        contributor = Contributor(user=request.user)
        contributor.save()

    if request.method == "POST":
        form = CreateContributionForm(request.POST)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/contributor/contributions/%s" % form.instance.id)

    else:
        initial = {"contributor": contributor.id}
        form = CreateContributionForm(initial=initial)

    context = RequestContext(request, {"form": form})
    return render_to_response("contributor/create_contribution.html", context)
Exemplo n.º 3
0
def contributor_contributions(request, username):
    try:
        contributor = Contributor.objects.get(user__username=username)
    except Contributor.DoesNotExist:
        contributor = Contributor(user=request.user)
        contributor.save()

    if contributor.user != request.user:
        return HttpResponse("Unauthorized", status=401)

    context = {"contributions": contributor.contributions.all().order_by("-id")}

    return render_to_response("contributor/my_contributions.html", context)
Exemplo n.º 4
0
def contributor_contributions(request, username):
    try:
        contributor = Contributor.objects.get(user__username = username)
    except Contributor.DoesNotExist:
        contributor = Contributor(user = request.user)
        contributor.save()

    if contributor.user != request.user:
        return HttpResponse('Unauthorized', status=401)

    context = {
        'contributions': contributor.contributions.all().order_by('-id'),
    }

    return render(request, 'contributor/my_contributions.html', context)