Ejemplo n.º 1
0
def editcode_p(request, id=None):
    context = RequestContext(request)
    codetemplate = CodeTemplate.objects.order_by('-download_count')
    packages = Dependency.objects.order_by('-download_count')
    bundles = BundleTemplate.objects.order_by('-download_count')

    if id:
        print "Edit %s" % id
        code_template = get_object_or_404(CodeTemplate, pk=id)
        print code_template.user, code_template.name
        if code_template.user != request.user:
            return HttpResponseForbidden()

        if request.method == 'POST':
            codetemplate_form = CodeTemplateForm(data=request.POST,
                                                 instance=code_template)

            if codetemplate_form.is_valid():
                codetemplate = codetemplate_form.save(commit=False)

                if codetemplate.gist_url:
                    code_from_gist = load_gist(codetemplate.gist_url)
                    codetemplate.code = code_from_gist
                else:
                    codetemplate.code = request.POST['code']

                if 'screenshot' in request.FILES:
                    codetemplate.screenshot = request.FILES['screenshot']

                codetemplate.save()
                print "Code edited successfully."
                return HttpResponseRedirect("/emacshaqiba/code/edit/")
            else:
                print codetemplate_form.errors
                messages.error(request, "Error: Saving changes!")
        else:
            print "GET"
            codetemplate_form = CodeTemplateForm(instance=code_template)

    else:
        return HttpResponse("Code does not exist!!")

    context_dict = {
        'codetemplate_form': codetemplate_form,
        'codetemplate': codetemplate,
        'packages': packages,
        'bundles': bundles
    }

    return render_to_response('emacshaqiba/editcode_page.html', context_dict,
                              context)
Ejemplo n.º 2
0
def editcode_p(request, id=None):
    context = RequestContext(request)
    codetemplate = CodeTemplate.objects.order_by('-download_count')
    packages = Dependency.objects.order_by('-download_count')
    bundles = BundleTemplate.objects.order_by('-download_count')

    if id:
        print "Edit %s" % id
        code_template = get_object_or_404(CodeTemplate, pk=id)
        print code_template.user, code_template.name
        if code_template.user != request.user:
            return HttpResponseForbidden()

        if request.method == 'POST':
            codetemplate_form = CodeTemplateForm(data=request.POST,
                                                 instance=code_template)

            if codetemplate_form.is_valid():
                codetemplate = codetemplate_form.save(commit=False)

                if codetemplate.gist_url:
                    code_from_gist = load_gist(codetemplate.gist_url)
                    codetemplate.code = code_from_gist
                else:
                    codetemplate.code = request.POST['code']

                if 'screenshot' in request.FILES:
                    codetemplate.screenshot = request.FILES['screenshot']

                codetemplate.save()
                print "Code edited successfully."
                return HttpResponseRedirect("/emacshaqiba/code/edit/")
            else:
                print codetemplate_form.errors
                messages.error(request, "Error: Saving changes!")
        else:
            print "GET"
            codetemplate_form = CodeTemplateForm(instance=code_template)

    else:
        return HttpResponse("Code does not exist!!")

    context_dict = {'codetemplate_form': codetemplate_form,
                    'codetemplate': codetemplate,
                    'packages': packages,
                    'bundles': bundles}

    return render_to_response('emacshaqiba/editcode_page.html',
                              context_dict,
                              context)
Ejemplo n.º 3
0
def submitcode(request):
    context = RequestContext(request)
    codetemplate = CodeTemplate.objects.order_by('-download_count')
    packages = Dependency.objects.order_by('-download_count')
    bundles = BundleTemplate.objects.order_by('-download_count')

    if request.method == 'POST':
        codetemplate_form = CodeTemplateForm(data=request.POST)

        if codetemplate_form.is_valid():
            codetemplate = codetemplate_form.save(commit=False)

            if codetemplate.gist_url:
                code_from_gist = load_gist(codetemplate.gist_url)
                codetemplate.code = code_from_gist
            else:
                codetemplate.code = request.POST['code']

            if 'screenshot' in request.FILES:
                codetemplate.screenshot = request.FILES['screenshot']

            print request.user
            codetemplate.user = request.user
            codetemplate.save()
            messages.success(request, "Code submitted successfully !!")
            url = reverse('emacshaqiba.views.submitcode')
            return HttpResponseRedirect(url)
        else:
            print codetemplate_form.errors
            messages.error(request, "Error: Submitting code!")
    else:
        codetemplate_form = CodeTemplateForm()

    context_dict = {
        'codetemplate_form': codetemplate_form,
        'codetemplate': codetemplate,
        'packages': packages,
        'bundles': bundles
    }

    return render_to_response('emacshaqiba/submitcode.html', context_dict,
                              context)
Ejemplo n.º 4
0
def submitcode(request):
    context = RequestContext(request)
    codetemplate = CodeTemplate.objects.order_by('-download_count')
    packages = Dependency.objects.order_by('-download_count')
    bundles = BundleTemplate.objects.order_by('-download_count')

    if request.method == 'POST':
        codetemplate_form = CodeTemplateForm(data=request.POST)

        if codetemplate_form.is_valid():
            codetemplate = codetemplate_form.save(commit=False)

            if codetemplate.gist_url:
                code_from_gist = load_gist(codetemplate.gist_url)
                codetemplate.code = code_from_gist
            else:
                codetemplate.code = request.POST['code']

            if 'screenshot' in request.FILES:
                codetemplate.screenshot = request.FILES['screenshot']

            print request.user
            codetemplate.user = request.user
            codetemplate.save()
            messages.success(request, "Code submitted successfully !!")
            url = reverse('emacshaqiba.views.submitcode')
            return HttpResponseRedirect(url)
        else:
            print codetemplate_form.errors
            messages.error(request, "Error: Submitting code!")
    else:
        codetemplate_form = CodeTemplateForm()

    context_dict = {'codetemplate_form': codetemplate_form,
                    'codetemplate': codetemplate,
                    'packages': packages,
                    'bundles': bundles}

    return render_to_response('emacshaqiba/submitcode.html',
                              context_dict,
                              context)