Esempio n. 1
0
def templateset_checkout(request, id):

    if request.method == "GET":
        return {
            'form': CheckoutForm(),
            }

    form = CheckoutForm(data=request.POST)
    if not form.is_valid():
        return {
            'form': CheckoutForm(),
            }

    slug = form.cleaned_data['slug']

    templateset = get_object_or_404(Templateset.objects.using("ak"), id=id)

    templates = Template.objects.using("ak").filter(templateset=templateset)
    for template in templates:
        block = CodeBlock(filename="%s/%s" % (slug, template.filename))
        block.code = template.code
        block.save()

        map = CodeMap(templateset=id, template=template.filename, local_file=block,
                      slug=slug)
        map.save()
    return redirect("/checkout/%s/" % slug)
Esempio n. 2
0
def templateset_checkout(request, id):

    if request.method == "GET":
        return {
            'form': CheckoutForm(),
        }

    form = CheckoutForm(data=request.POST)
    if not form.is_valid():
        return {
            'form': CheckoutForm(),
        }

    slug = form.cleaned_data['slug']

    templateset = get_object_or_404(Templateset.objects.using("ak"), id=id)

    templates = Template.objects.using("ak").filter(templateset=templateset)
    for template in templates:
        block = CodeBlock(filename="%s/%s" % (slug, template.filename))
        block.code = template.code
        block.save()

        map = CodeMap(templateset=id,
                      template=template.filename,
                      local_file=block,
                      slug=slug)
        map.save()
    return redirect("/checkout/%s/" % slug)
Esempio n. 3
0
def changeset_added(request):
    # @@TODO conflict detection?
    body = json.loads(request.body)
    for commit in body['commits']:
        path = commit['path']
        change = commit['change']
        if change == "edit":
            try:
                block = CodeBlock.objects.get(filename=path)
            except CodeBlock.DoesNotExist:
                block = CodeBlock(filename=path)
            block.code = commit['content']
            block.save()
        elif change == "add":
            try:
                block = CodeBlock.objects.get(filename=path)
            except CodeBlock.DoesNotExist:
                block = CodeBlock(filename=path)
            block.code = commit['content']
            block.save()
        elif change == "move":
            try:
                block = CodeBlock.objects.get(filename=commit['original_path'])
            except CodeBlock.DoesNotExist:
                block = CodeBlock(filename=commit['original_path'])
            block.code = commit['content']
            block.filename = path
            block.code = commit['content']
            block.save()
        elif change == "delete":
            try:
                block = CodeBlock.objects.get(filename=path)
            except CodeBlock.DoesNotExist:
                pass
            else:
                block.delete()
    # @@TODO return something interesting
    return HttpResponse("ok")
Esempio n. 4
0
def changeset_added(request):
    # @@TODO conflict detection?
    body = json.loads(request.body)
    for commit in body['commits']:
        path = commit['path']
        change = commit['change']
        if change == "edit":
            try:
                block = CodeBlock.objects.get(filename=path)
            except CodeBlock.DoesNotExist:
                block = CodeBlock(filename=path)
            block.code = commit['content']
            block.save()
        elif change == "add":
            try:
                block = CodeBlock.objects.get(filename=path)
            except CodeBlock.DoesNotExist:
                block = CodeBlock(filename=path)
            block.code = commit['content']
            block.save()
        elif change == "move":
            try:
                block = CodeBlock.objects.get(filename=commit['original_path'])
            except CodeBlock.DoesNotExist:
                block = CodeBlock(filename=commit['original_path'])
            block.code = commit['content']
            block.filename = path
            block.code = commit['content']
            block.save()
        elif change == "delete":
            try:
                block = CodeBlock.objects.get(filename=path)
            except CodeBlock.DoesNotExist:
                pass
            else:
                block.delete()
    # @@TODO return something interesting
    return HttpResponse("ok")