Example #1
0
def show_events_by_slug(request, slug):
    event = Event.objects.active().get(slug=slug)
    if Event.can_view_event(slug, request.user) is True:
        comments = Comment.objects.active().sort()
        comments = comments.filter(event=event).order_by('-created_at')
        form = CommentForm(request.POST or None)
        username_form = UserForm(request.POST or None)

        storage = messages.get_messages(request)
        for message in storage:
            pass

        final_users = []
        final_team = []

        if request.user.is_authenticated:
            if AccountDetails.objects.filter(user=request.user).exists():
                users = AccountDetails.objects.get(
                    user=request.user).friends.all()
                for user in users:
                    if AccountDetails.objects.filter(user=user):
                        details = AccountDetails.objects.get(user=user)
                        user.details = details
                        final_users.append(user)

            if request.method == 'POST':
                if form.is_valid():
                    comment = form.save(commit=False)
                    comment.event = event
                    comment.author = request.user
                    comment.save()

        has_joined = Event.has_joined_event(request.user, slug)

        team = event.team_members.all()
        for user in team:
            if AccountDetails.objects.filter(user=user):
                details = AccountDetails.objects.get(user=user)
                user.details = details
                final_team.append(user)

        context = {
            'event': event,
            'comments': comments,
            'form': form,
            'has_joined': has_joined,
            'guests': Event.get_guests(slug),
            'users': final_users,
            'team': final_team,
            'is_team_member': Event.is_team_member(request.user, slug)
        }
        return render(request, 'events/event.html', context)

    error_message = "Event is not available yet\
          or you don't have permission to view it."

    context = {'error_message': error_message}
    return render(request, 'CRUDops/error.html', context)
Example #2
0
def index(request):
    events_list = Event.objects.active()

    events = []
    for event in events_list:
        if Event.can_view_event(event.slug, request.user):
            events.append(event)

    events_list = events
    paginator = Paginator(events_list, number_of_items_per_page)

    page = request.GET.get('page', 1)

    categories = Category.objects.active()
    try:
        events = paginator.page(page)
    except PageNotAnInteger:
        events = paginator.page(1)
    except EmptyPage:
        events = paginator.page(paginator.num_pages)

    context = {'events': events, 'categories': categories}
    return render(request, 'events/list_events.html', context)