Exemplo n.º 1
0
def feeds(request, id):
    digest = get_object(request, Digest, id)
    form_twitter = FeedForm();
    form_rss = RssForm()
    total_feeds = digest.feeds.all().count() + digest.rss.all().count()
    groupinfo = GroupInfo(request.user)
    message = ''
    return_url = '/control/%i/feeds' % digest.id

    if request.method == 'POST':
        if total_feeds == groupinfo.get_feeds_limit():
            message = 'You are at the Feed limit for this digest.\
                Remove a feed or <a href="/pricing">upgrade your package</a>\
                to add more.'

        elif request.POST.get('username'):    # user submitted Twitter form
            if twitter_add(request.POST, digest):
                return HttpResponseRedirect(return_url)
            else:
                form_twitter = FeedForm(request.POST)

        elif request.POST.get('url'):   # user submitted RSS form
            try:
                rss = Rss.objects.get(url=request.POST.get('url'))
                digest.rss.add(rss)
                digest.save()
                return HttpResponseRedirect(return_url)
            except:
                form_rss = RssForm(request.POST)
                if form_rss.is_valid():
                    rss = form_rss.save()
                    digest.rss.add(rss)
                    digest.save()
                    return HttpResponseRedirect(return_url)

    return render_to_response('control/feed.html', {'digest': digest,
                                                    'form_twitter': form_twitter,
                                                    'form_rss': form_rss,
                                                    'total': total_feeds,
                                                    'groupinfo': groupinfo,
                                                    'message': message},
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def new(request):
    message = ''
    groupinfo = GroupInfo(request.user)
    form = DigestForm()
    form.fields['template'].choices = templates_as_choices(request)

    if groupinfo.get_digests_limit() == Digest.objects.filter(user=request.user).count():
        message = 'You have reached your Digest limit of %i. \
            Please remove a Digest or <a href="/pricing">upgrade your package</a>\
            to add more.' % (groupinfo.get_digests_limit())

    elif request.method == 'POST':
        form = DigestForm(request.POST)
        if form.is_valid():
            digest = form.save(commit=False)
            digest.user = request.user
            digest.save()
            return HttpResponseRedirect(digest.get_feeds_url())

    return render_to_response('control/digest.html', {'form': form,
                                                      'message': message},
                              context_instance=RequestContext(request))