Exemple #1
0
 def test_url_must_be_valid(self):
     form = SponsorForm({
         'name': 'foo',
         'url': 'barbaz',
         'path_to_logo': self.image
     })
     self.assertFalse(form.is_valid())
Exemple #2
0
 def test_create_object(self):
     count = Sponsor.objects.count()
     form = SponsorForm({
         'name': 'foo',
         'url': 'http://google.com'
     }, {'logo': self.image})
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(count + 1, Sponsor.objects.count())
Exemple #3
0
def update(request, sponsor_id=None):
    ctx = {}
    kwargs = {}
    if sponsor_id is not None:
        sponsor = get_object_or_404(Sponsor, pk=sponsor_id)
        ctx['object'] = sponsor
        kwargs['instance'] = sponsor

    form = SponsorForm(request.POST or None, request.FILES or None, **kwargs)
    ctx['form'] = form
    ctx['s3_objects'] = list_bucket_objects(BUCKET_NAME)
    ctx['bucket_url'] = BUCKET_URL

    if request.method == 'POST':
        if form.is_valid():
            form.save()
            messages.success(request, _("Form saved!"))
            return redirect(reverse('sponsors_index'))
        else:
            messages.error(request, errors_format(form))

    return render(request, 'sponsors/update.html', ctx)
Exemple #4
0
def addSponsor(request):
    if request.method == 'POST':
        sponsor_form = SponsorForm(request.POST)
        if sponsor_form.is_valid():
            sponsor_form.save()
            return redirect('sponsor-list')
        else:
            pass

    else:
        sponsor_form = SponsorForm()
        context = {'sponsor_form': sponsor_form}
        return render(request, 'addsponsor.html', context)
Exemple #5
0
def update(request, sponsor_id=None):
    ctx = {}
    kwargs = {}
    if sponsor_id is not None:
        sponsor = get_object_or_404(Sponsor, pk=sponsor_id)
        ctx['object'] = sponsor
        kwargs['instance'] = sponsor

    ctx['form'] = SponsorForm(request.POST or None, request.FILES or None,
                              **kwargs)

    if request.method == 'POST':
        if ctx['form'].is_valid():
            ctx['form'].save()
            messages.success(request, _("Form saved!"))
            return redirect(reverse('sponsors_index'))
        else:
            messages.error(request, _("There has been errors"))

    return render(request, 'sponsors/update.html', ctx)
Exemple #6
0
 def test_no_data(self):
     form = SponsorForm()
     self.assertFalse(form.is_valid())