コード例 #1
0
ファイル: test_forms.py プロジェクト: kcshafer/liwi-site
    def test_featured_artist_form_invalid_date_greater(self):
        """
            test the featured artist form fails with a greater start date than end date
        """

        user = fixtures.create_user(
            username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User'
        )

        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        date_format = '%m/%d/%Y'

        start = datetime.today()
        str_start = start.strftime(date_format)
        #TODO: this would fail in december
        end = datetime(start.year, start.month + 1, 1)
        str_end = end.strftime(date_format)

        post_dict = {'start_date': str_end, 'end_date': str_start}

        form = FeaturedArtistForm(post_dict)

        self.assertFalse(form.is_valid())
コード例 #2
0
ファイル: views.py プロジェクト: kcshafer/liwi-site
def get_featured_register(request):
    if request.method == 'POST':
        user_id = request.session.get('user_id')
        fa_form = FeaturedArtistForm(request.POST)
        if fa_form.is_valid():
            user_profile = Profile.objects.get(user_id=user_id)
            featured_artist = fa_form.save(commit=False)
            featured_artist.user_id = user_id
            featured_artist.active = True
            featured_artist.last_imprint = datetime.now()
            featured_artist.total_imprints = 0
            featured_artist.photo = user_profile.photo
            featured_artist.save()
            messages.add_message(request, messages.SUCCESS, 'Registered as a featured artist!')
            return HttpResponseRedirect('/')
        else:
            template = loader.get_template('artists/get_featured_form.html')
            context = RequestContext(request, {'fa_form': fa_form})
            return HttpResponse(template.render(context))
    else:
        log.error("Unauthorized get request made to get featured")
        return HttpResponseNotAllowed(['POST'], 'Unauthorized Request.')