Пример #1
0
def show(request, production_id, edit_mode=False):
    production = get_object_or_404(Production, id=production_id)
    if production.supertype != 'graphics':
        return HttpResponseRedirect(production.get_absolute_url())

    if request.user.is_authenticated:
        comment = Comment(commentable=production, user=request.user)
        comment_form = CommentForm(instance=comment, prefix="comment")
        tags_form = ProductionTagsForm(instance=production)

        awards_accepting_recommendations = [
            (event, event.get_recommendation_options(request.user, production))
            for event in Event.accepting_recommendations_for(production)
        ]
    else:
        comment_form = None
        tags_form = None

        awards_accepting_recommendations = [
            (event, None)
            for event in Event.accepting_recommendations_for(production)
        ]

    if production.can_have_pack_members():
        pack_members = [
            link.member for link in
            production.pack_members.select_related('member').prefetch_related('member__author_nicks__releaser', 'member__author_affiliation_nicks__releaser')
        ]
    else:
        pack_members = None

    try:
        meta_screenshot = random.choice(production.screenshots.exclude(standard_url=''))
    except IndexError:
        meta_screenshot = None

    return render(request, 'productions/show.html', {
        'production': production,
        'prompt_to_edit': settings.SITE_IS_WRITEABLE and (request.user.is_staff or not production.locked),
        'credits': production.credits_for_listing(),
        'carousel': Carousel(production, request.user),
        'download_links': production.download_links,
        'external_links': production.external_links,
        'info_files': production.info_files.all(),
        'packed_in_productions': [
            pack_member.pack for pack_member in
            production.packed_in.prefetch_related('pack__author_nicks__releaser', 'pack__author_affiliation_nicks__releaser').order_by('pack__release_date_date')
        ],
        'tags': production.tags.order_by('name'),
        'blurbs': production.blurbs.all() if request.user.is_staff else None,
        'pack_members': pack_members,
        'comment_form': comment_form,
        'tags_form': tags_form,
        'meta_screenshot': meta_screenshot,
        'awards_accepting_recommendations': awards_accepting_recommendations,
    })
Пример #2
0
def user_recommendations(request, event_slug):
    event = get_object_or_404(
        Event.active_for_user(request.user), slug=event_slug
    )

    if request.user.is_authenticated():
        recommendations = Recommendation.objects.filter(
            user=request.user, category__event=event
        ).select_related('category', 'production').prefetch_related(
            'production__author_nicks__releaser', 'production__author_affiliation_nicks__releaser'
        ).order_by('category', 'production__sortable_title')

        recommendations_by_category = [
            (category, list(recs))
            for category, recs in itertools.groupby(recommendations, lambda r: r.category)
        ]
    else:
        recommendations_by_category = []

    return render(request, 'awards/user_recommendations.html', {
        'event': event,
        'recommendations_by_category': recommendations_by_category,
        'can_view_reports': event.user_can_view_reports(request.user),
        'can_remove_recommendations': event.recommendations_enabled,
    })
Пример #3
0
def recommend(request, event_slug, production_id):
    production = get_object_or_404(Production, id=production_id)
    event = get_object_or_404(
        Event.accepting_recommendations_for(production), slug=event_slug
    )

    available_category_ids = event.categories.values_list('id', flat=True)
    selected_category_ids = [
        id for id in request.POST.getlist('category_id', [])
        if int(id) in available_category_ids
    ]
    unselected_category_ids = [
        id for id in available_category_ids
        if id not in selected_category_ids
    ]

    # delete recommendations for unchecked categories
    Recommendation.objects.filter(
        user=request.user, production=production, category_id__in=unselected_category_ids
    ).delete()

    # get-or-create recommendations for checked categories
    for category_id in selected_category_ids:
        Recommendation.objects.get_or_create(
            user=request.user, production=production, category_id=category_id
        )

    messages.success(request, "Thank you for your recommendation!")
    return HttpResponseRedirect(production.get_absolute_url())
Пример #4
0
def user_menu(context):
    user = context['request'].user

    menu_items = [
        (reverse('account_change_password'), "Change password"),
    ]

    for event in Event.active_for_user(user):
        menu_items.append((reverse('awards_user_recommendations',
                                   args=(event.slug, )), event.name), )

    menu_items.append((reverse('user', args=(user.id, )), "Activity"), )

    if user.is_staff:
        menu_items.append((reverse('maintenance:index'), "Maintenance"), )

    menu_items.append((reverse('log_out'), "Log out"), )

    return {
        'menu_items': menu_items,
    }
Пример #5
0
    def get_context_data(self):
        if self.request.user.is_authenticated:
            comment = Comment(commentable=self.production,
                              user=self.request.user)
            comment_form = CommentForm(instance=comment, prefix="comment")
            tags_form = ProductionTagsForm(instance=self.production)

            awards_accepting_recommendations = [
                (event,
                 event.get_recommendation_options(self.request.user,
                                                  self.production))
                for event in Event.accepting_recommendations_for(
                    self.production)
            ]
        else:
            comment_form = None
            tags_form = None

            awards_accepting_recommendations = [
                (event, None) for event in Event.accepting_recommendations_for(
                    self.production)
            ]

        if self.production.can_have_pack_members():
            pack_members = [
                link.member
                for link in (self.production.pack_members.select_related(
                    'member').prefetch_related(
                        'member__author_nicks__releaser',
                        'member__author_affiliation_nicks__releaser'))
            ]
        else:
            pack_members = None

        try:
            meta_screenshot = random.choice(
                self.production.screenshots.exclude(standard_url=''))
        except IndexError:
            meta_screenshot = None

        return {
            'production':
            self.production,
            'prompt_to_edit':
            settings.SITE_IS_WRITEABLE
            and (self.request.user.is_staff or not self.production.locked),
            'download_links':
            self.production.download_links,
            'external_links':
            self.production.external_links,
            'info_files':
            self.production.info_files.all(),
            'editing_credits': (self.request.GET.get('editing') == 'credits'),
            'credits':
            self.production.credits_for_listing(),
            'carousel':
            Carousel(self.production, self.request.user),
            'tags':
            self.production.tags.order_by('name'),
            'blurbs':
            self.production.blurbs.all()
            if self.request.user.is_staff else None,
            'comment_form':
            comment_form,
            'tags_form':
            tags_form,
            'meta_screenshot':
            meta_screenshot,
            'awards_accepting_recommendations':
            awards_accepting_recommendations,
            'pack_members':
            pack_members,
        }