Exemple #1
0
def poll_vote(request):
    """
    View of poll vote.
    
    """
    if request.method == 'POST':
        if request.POST.has_key('id_choice'):
            if request.POST['id_choice']:
                id_poll = request.POST['id_poll']
                id_choice = request.POST['id_choice']
                ip_address = request.POST['ip_address']
                poll = Poll.objects.get(pk=id_poll)
                choice = Choice.objects.get(pk=id_choice)
                vote = Vote(poll=poll, choice=choice, ip_address=ip_address)
                vote.save()
                return HttpResponseRedirect(reverse('polls_poll_results', args=[poll.slug]))
            else:
                return HttpResponseRedirect(reverse('home'))
        else:
            return HttpResponseRedirect(reverse('home'))
    else:
        return HttpResponseRedirect(reverse('home'))
Exemple #2
0
def home(request, **kwargs):
    """
    Displays the Homepage.
    
    """
    # Initialize context
    # --------------------------------------------------------------------------
    context = _initialize_context(kwargs)
    issue = context["issue"]

    # Poll
    # --------------------------------------------------------------------------
    from critica.apps.polls.models import Poll
    from critica.apps.polls.models import Choice
    from critica.apps.polls.models import Vote

    if request.method == "POST":
        if request.POST.has_key("poll"):
            poll = Poll.objects.get(pk=request.POST["id_poll"])
            choice = Choice.objects.get(pk=request.POST["id_choice"])
            ip_address = request.POST["ip_address"]
            vote = Vote(poll=poll, choice=choice, ip_address=ip_address)
            vote.save()

    # Articles
    # --------------------------------------------------------------------------
    category_positions = IssueCategoryPosition.objects.filter(issue=issue)
    for category_position in category_positions:
        if category_position.position is not None:
            varname = "article_%s" % category_position.position.id
            if context["is_preview"]:
                try:
                    article = Article.preview.filter(issues__id=issue.id, category=category_position.category)
                    context[varname] = article[0:1].get()
                except ObjectDoesNotExist:
                    context[varname] = None
            else:
                try:
                    article = Article.published.filter(issues__id=issue.id, category=category_position.category)
                    article = article[0:1].get()
                    context[varname] = article
                except ObjectDoesNotExist:
                    context[varname] = None

    # Regions
    # --------------------------------------------------------------------------
    if context["is_preview"]:
        context["region_note"] = RegionNote.preview.get_featured(issue_id=issue.id)
    else:
        context["region_note"] = RegionNote.published.get_featured(issue_id=issue.id)

    # Voyages
    # --------------------------------------------------------------------------
    if context["is_preview"]:
        context["voyages_article"] = VoyagesArticle.preview.issue_article(issue_id=issue.id)
    else:
        context["voyages_article"] = VoyagesArticle.published.issue_article(issue_id=issue.id)

    # Epicurien
    # --------------------------------------------------------------------------
    epicurien_articles = []
    if context["is_preview"]:
        a = EpicurienArticle.preview.issue_article_cotegourmets(issue_id=issue.id)
        epicurien_articles.append(a)
        a = EpicurienArticle.preview.issue_article_cotebar(issue_id=issue.id)
        epicurien_articles.append(a)
        a = EpicurienArticle.preview.issue_article_cotefumeurs(issue_id=issue.id)
        epicurien_articles.append(a)
    else:
        a = EpicurienArticle.published.issue_article_cotegourmets(issue_id=issue.id)
        epicurien_articles.append(a)
        a = EpicurienArticle.published.issue_article_cotebar(issue_id=issue.id)
        epicurien_articles.append(a)
        a = EpicurienArticle.published.issue_article_cotefumeurs(issue_id=issue.id)
        epicurien_articles.append(a)
    context["epicurien_articles"] = epicurien_articles

    # Anger
    # --------------------------------------------------------------------------
    if context["is_preview"]:
        context["anger_article"] = AngerArticle.preview.issue_article(issue_id=issue.id)
    else:
        context["anger_article"] = AngerArticle.published.issue_article(issue_id=issue.id)

    # Illustration of the day
    # --------------------------------------------------------------------------
    context["illustration"] = IllustrationOfTheDay.objects.issue_illustration(issue_id=issue.id)

    # Video
    # --------------------------------------------------------------------------
    context["video"] = Video.published.issue_video(issue_id=issue.id)

    # Tag cloud
    # --------------------------------------------------------------------------
    all_tags = []
    article_tags = Tag.objects.usage_for_queryset(Article.published.all(), counts=True)
    for tag in article_tags:
        all_tags.append(tag)

    note_tags = Tag.objects.usage_for_queryset(Note.published.all(), counts=True)
    for tag in note_tags:
        all_tags.append(tag)

    region_tags = Tag.objects.usage_for_queryset(RegionNote.published.all(), counts=True)
    for tag in region_tags:
        all_tags.append(tag)

    voyages_tags = Tag.objects.usage_for_queryset(VoyagesArticle.published.all(), counts=True)
    for tag in voyages_tags:
        all_tags.append(tag)

    epicurien_tags = Tag.objects.usage_for_queryset(VoyagesArticle.published.all(), counts=True)
    for tag in epicurien_tags:
        all_tags.append(tag)

    anger_tags = Tag.objects.usage_for_queryset(AngerArticle.published.all(), counts=True)
    for tag in anger_tags:
        all_tags.append(tag)

    tags = calculate_cloud(all_tags, steps=10)
    if len(tags) <= 50:
        tagcloud = tags
    else:
        tagcloud = []
        for tag in tags:
            if tag.count > 2:
                tagcloud.append(tag)
    context["tagcloud"] = tagcloud[:50]

    return direct_to_template(request, "front/home.html", context)