Example #1
0
def coop_add(request):
    if request.method == 'POST':
        post = request.POST
    else:
        post = None
    form = CoopForm(post, auto_id = True)
    if form.is_valid():
        c = Coop(**form.cleaner_data())
        c.put()
        return HttpResponseRedirect('/')
    return render_to_response('coops/add.html', {'form': form})
Example #2
0
def coop_list(request):
    # TODO: parse GET search parameters
    coops = Coop.all().order('-modified')
    paginator = Paginator(coops, 10)
    page = paginator.page(request.GET.get('p', 1))
    return render_to_response('coops/list.html', {
        'page': page,
        'querystring': '',
        'first_item_number': paginator.per_page * (page.number - 1) + 1
    })
Example #3
0
    def testCoopRevisions(self):
        """
        Test the saving mechanism for "Coop" which maintains revisions.
        """

        # Set up a Coop to work with
        c = Coop()
        c.name = "Testy Coop"
        c.created_by = CoopUser.objects.all()[0]
        c.picture = CoopPicture.objects.all()[0]
        c.contactable = Contactable.objects.all()[0]
        c.save()

        # Make sure it saved right
        orig_id = c.id
        self.assertEquals(c.branch.id, orig_id)
        self.assertEquals(c.revision, 0)

        # Try making a revision
        c.name = "Testy Coop Revised"
        c.save()
        self.assertEquals(c.revision, 1)
        self.assertEquals(c.id, orig_id)
        self.assertEquals(c.branch.id, orig_id)
        old_version = Coop.objects.get(name = "Testy Coop")
        self.assertEquals(old_version.id, orig_id + 1)
        self.assertEquals(old_version.revision, c.revision - 1)

        # Make sure the old version copied right
        old_revisions = Coop.objects.filter(name = "Testy Coop")
        self.failUnless(len(old_revisions) > 0)
        old_revision = old_revisions[0]
        self.assertEqual(old_revision.branch, c.branch)
        self.assertNotEqual(old_revision.id, c.id)

        # Make sure you can't duplicate revision numbers
        bad = Coop()
        bad.name = "Bad"
        bad.created_by = CoopUser.objects.all()[0]
        bad.contactable = Contactable.objects.all()[0]
        bad.branch = c
        bad.revision = 0
        self.assertRaises(IntegrityError, bad.save)

        # Make sure revision of an old version pops out on top.  If we try to
        # edit an old revision, it should become the latest revision when
        # saved.
        all_revisions = Coop.objects.filter(branch__id = orig_id)
        latest = all_revisions[len(all_revisions) - 1]
        fork = all_revisions[0]
        self.assertEquals(fork.revision, 0)
        fork.name = "Testy Coop fork from old rev."
        fork.save()
        self.assertEqual(fork.revision, latest.revision + 1)