Ejemplo n.º 1
0
def oneliner_edit(request, pk):
    params = _common_params(request)
    initial = _common_initial(request)
    params['next_url'] = initial['next_url']

    try:
        oneliner0 = OneLiner.objects.get(pk=pk, user=request.user)
    except:
        return render_to_response('main/pages/access_error.html', params)

    if request.method == 'POST':
        form = EditOneLinerForm(request.user, request.POST, instance=oneliner0)
        if form.is_valid():
            if form.is_save:
                oneliner1 = form.save()
                if oneliner1.is_published:
                    tweet(oneliner1)
                return redirect(form.cleaned_data.get('next_url'))
            elif form.is_delete:
                oneliner0.delete()
                return redirect(profile)
        else:
            params['next_url'] = request.POST.get('next_url')
    else:
        form = EditOneLinerForm(request.user, instance=oneliner0, initial=initial)

    params['form'] = form

    return render_to_response('main/pages/oneliner_edit.html', params, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def oneliner_edit(request, pk):
    params = _common_params(request)
    params['cancel_url'] = reverse(oneliner, args=(pk, ))

    try:
        oneliner0 = OneLiner.objects.get(pk=pk, user=request.user)
        oneliner0.score = sum([x.value for x in oneliner0.vote_set.all()])
    except OneLiner.DoesNotExist:
        return render_to_response('oneliners/pages/access_error.html', params)

    if request.method == 'POST':
        form = EditOneLinerForm(request.user, request.POST, instance=oneliner0)
        if form.is_valid():
            if form.is_save:
                oneliner1 = form.save()
                if oneliner1.is_published:
                    tweet(oneliner1, format_canonical_url(request))
                return redirect(oneliner1)
            elif form.is_delete:
                oneliner0.delete()
                return redirect(profile)
    else:
        form = EditOneLinerForm(request.user, instance=oneliner0)

    params['form'] = form

    return render_to_response('oneliners/pages/oneliner_edit.html',
                              params,
                              context_instance=RequestContext(request))
Ejemplo n.º 3
0
def oneliner_edit(request, pk):
    params = _common_params(request)
    params['cancel_url'] = reverse(oneliner, args=(pk, ))

    try:
        if request.user.is_staff:
            oneliner0 = OneLiner.objects.get(pk=pk)
        else:
            oneliner0 = OneLiner.objects.get(pk=pk, user=request.user)
    except OneLiner.DoesNotExist:
        return render(request, 'oneliners/pages/access_error.html', params)

    if request.method == 'POST':
        form = EditOneLinerForm(oneliner0.user,
                                request.POST,
                                instance=oneliner0)
        if form.is_valid():
            if form.is_save:
                oneliner1 = form.save()
                return redirect(oneliner1)
            elif form.is_delete:
                oneliner0.delete()
                return redirect(profile)
    else:
        form = EditOneLinerForm(request.user, instance=oneliner0)

    params['form'] = form

    return render(request, 'oneliners/pages/oneliner_edit.html', params)
Ejemplo n.º 4
0
def oneliner_edit(request, pk):
    params = _common_params(request)
    params["cancel_url"] = reverse(oneliner, args=(pk,))

    try:
        oneliner0 = OneLiner.objects.get(pk=pk, user=request.user)
        oneliner0.score = sum([x.value for x in oneliner0.vote_set.all()])
    except OneLiner.DoesNotExist:
        return render_to_response("oneliners/pages/access_error.html", params)

    if request.method == "POST":
        form = EditOneLinerForm(request.user, request.POST, instance=oneliner0)
        if form.is_valid():
            if form.is_save:
                oneliner1 = form.save()
                if oneliner1.is_published:
                    tweet(oneliner1, format_canonical_url(request))
                return redirect(oneliner1)
            elif form.is_delete:
                oneliner0.delete()
                return redirect(profile)
    else:
        form = EditOneLinerForm(request.user, instance=oneliner0)

    params["form"] = form

    return render_to_response("oneliners/pages/oneliner_edit.html", params, context_instance=RequestContext(request))
Ejemplo n.º 5
0
def oneliner_edit(request, pk):
    params = _common_params(request)
    params['cancel_url'] = reverse(oneliner, args=(pk,))

    try:
        oneliner0 = OneLiner.objects.get(pk=pk, user=request.user)
    except:
        return render_to_response('oneliners/pages/access_error.html', params)

    if request.method == 'POST':
        form = EditOneLinerForm(request.user, request.POST, instance=oneliner0)
        if form.is_valid():
            if form.is_save:
                oneliner1 = form.save()
                if oneliner1.is_published:
                    tweet(oneliner1, format_canonical_url(request))
                return redirect(oneliner1)
            elif form.is_delete:
                oneliner0.delete()
                return redirect(profile)
    else:
        form = EditOneLinerForm(request.user, instance=oneliner0)

    params['form'] = form

    return render_to_response('oneliners/pages/oneliner_edit.html', params, context_instance=RequestContext(request))
Ejemplo n.º 6
0
    def test_save_own_success(self):
        oneliner0 = self.jacks_oneliner
        data = {
            'summary': oneliner0.summary,
            'line': oneliner0.line,
            'explanation': oneliner0.explanation,
            'action': EditOneLinerForm.action_save,
        }
        new_summary = oneliner0.summary + ' some change'
        data['summary'] = new_summary

        form = EditOneLinerForm(self.jack, data, instance=oneliner0)
        self.assertTrue(form.is_valid())
        oneliner1 = form.save()

        self.assertEquals(oneliner1.summary, new_summary)
        self.assertEquals(oneliner1.user, self.jack)
Ejemplo n.º 7
0
    def test_save_own_success(self):
        oneliner0 = self.jacks_oneliner
        data = {
            'summary': oneliner0.summary,
            'line': oneliner0.line,
            'explanation': oneliner0.explanation,
            'action': EditOneLinerForm.action_save,
        }
        new_summary = oneliner0.summary + ' some change'
        data['summary'] = new_summary

        form = EditOneLinerForm(self.jack, data, instance=oneliner0)
        self.assertTrue(form.is_valid())
        oneliner1 = form.save()

        self.assertEquals(oneliner1.summary, new_summary)
        self.assertEquals(oneliner1.user, self.jack)