def post(self, request, book_id):
     if request.user.is_authenticated:
         cf = CommentForm(request.POST)
         comment = cf.save(commit=False)
         comment.book_id = book_id
         comment.save()
     return redirect('book-detail', slug=Book.objects.get(id=book_id).slug)
예제 #2
0
 def post(self, request, id, slug):
     if request.user.is_authenticated:
         comment = Comment.objects.get(id=id)
         if request.user in comment.author_comment.all():
             u_comment = CommentForm(data=request.POST, instance=comment)
             u_comment.save(commit=True)
             return redirect('open-comment', slug=slug)
     return redirect('index-page')
예제 #3
0
 def post(self, request, slug):
     if request.user.is_authenticated:
         cf = CommentForm(data=request.POST)
         comment = cf.save(commit=False)
         comment.author_id = request.user.id
         comment.book_id = slug
         comment.save()
     return redirect("book-detail", slug=slug)
예제 #4
0
def add_comment(request, sede_url, pk):
    """Add a new comment."""
    comment = Comment(proposal=TalkProposal.objects.get(pk=pk), user=request.user)
    comment_form = CommentForm(request.POST, instance=comment)
    if comment_form.is_valid():
        comment = comment_form.save(commit=False)
        comment.save(notify=True)
    return HttpResponseRedirect(reverse("proposal_detail", args=[sede_url, pk]))
예제 #5
0
 def post(self, request, id):
     if request.user.is_authenticated:
         comment = Comment.objects.get(id=id)
         if request.user == comment.author:
             cf = CommentForm(instance=comment, data=request.POST)
             if cf.is_valid():
                 cf.save(commit=True)
     return redirect('book-detail', slug=comment.book.slug)
예제 #6
0
 def post(self, request, slug, location=None):
     if request.user.is_authenticated:
         cf = CommentForm(data=request.POST)
         comment = cf.save(commit=False)
         comment.book_id = Book.objects.get(slug=slug).slug
         comment.author = request.user
         comment = cf.save(commit=True)
         comment.save()
     return redirect("book-detail", slug=slug)
예제 #7
0
 def post(self, request, slug):
     if request.user.is_authenticated:
         # Comment.objects.create(book_id=id, text=request.POST.get('text'), author_id=request.user.id)
         cf = CommentForm(data=request.POST)
         comment = cf.save(commit=False)
         comment.author_id = request.user.id
         comment.book_id = slug
         comment.save()
     return redirect("book-detail", slug=slug)
예제 #8
0
def add_comment(request, event_slug, pk):
    """Add a new comment."""
    proposal = TalkProposal.objects.filter(pk=pk).first()
    if not proposal:
        return handler404(request)
    comment = Comment(activity=proposal.activity, user=request.user)
    comment_form = CommentForm(request.POST, instance=comment)
    if comment_form.is_valid():
        comment = comment_form.save(commit=False)
        comment.save(notify=True)
    return HttpResponseRedirect(reverse("proposal_detail", args=[event_slug, pk]))
예제 #9
0
 def get(self, request, slug):
     context = {}
     list_rid = RidBookUser.objects.filter(user=request.user.id,
                                           book_id=slug)
     if list_rid:
         pass
     else:
         RidBookUser.objects.create(user=request.user, book_id=slug)
     comment_query = Comment.objects.select_related("author")
     if request.user.is_authenticated:
         is_liked = Exists(
             User.objects.filter(liked_comment=OuterRef('pk'),
                                 id=request.user.id))
         is_owner = Exists(
             User.objects.filter(comments_user=OuterRef('pk'),
                                 id=request.user.id))
         comment_query = comment_query.annotate(is_liked=is_liked)
         comment_query = comment_query.annotate(is_owner=is_owner)
     comments = Prefetch("comments", comment_query)
     book = Book.objects.prefetch_related('authors', comments)
     if request.user.is_authenticated:
         is_owners = Exists(
             User.objects.filter(books=OuterRef('pk'), id=request.user.id))
         book = book.annotate(is_owners=is_owners)
     book = book.get(slug=slug)
     context['book'] = book
     context['range'] = range(1, 6)
     context['form'] = CommentForm()
     return render(request, "book_detail.html", context)
예제 #10
0
    def post(
        self,
        request,
        slug,
    ):
        if request.user.is_authenticated:
            com = CommentForm(data=request.POST)
            comment = com.save(commit=False)
            comment.book_id = slug
            comment.save()
            # com.save_m2m ()
            comment.author_comment.add(request.user)
            CommentLikes.objects.get(user=request.user,
                                     comment_id=comment.id).delete()
            comment.save()

            return redirect('open-comment', slug=slug)
예제 #11
0
def talk_registration(request, sede_url, pk):
    errors = []
    error = False
    talk = None
    sede = Sede.objects.get(url__iexact=sede_url)

    # FIXME: Esto es lo que se llama una buena chanchada!
    post = None
    if request.POST:
        start_time = datetime.datetime.strptime(request.POST.get('start_date', None), '%H:%M')
        end_time = datetime.datetime.strptime(request.POST.get('end_date', None), '%H:%M')

        start_time_posta = datetime.datetime.combine(sede.date, start_time.time())
        end_time_posta = datetime.datetime.combine(sede.date, end_time.time())

        post = request.POST.copy()

        post['start_date'] = start_time_posta.strftime('%Y-%m-%d %H:%M:%S')
        post['end_date'] = end_time_posta.strftime('%Y-%m-%d %H:%M:%S')

    # Fin de la chanchada

    talk_form = TalkForm(sede_url, post)
    proposal = TalkProposal.objects.get(pk=pk)
    forms = [talk_form]
    if request.POST:
        if talk_form.is_valid() and room_available(request, talk_form.instance, sede_url):
            try:
                proposal.confirmed = True
                proposal.save()
                talk = talk_form.save()
                talk.talk_proposal = proposal
                talk.save()
                messages.success(request, _("The talk was registered successfully!"))
                return HttpResponseRedirect(reverse("talk_detail", args=[sede_url, talk.pk]))
            except Exception:
                if talk is not None:
                    Talk.delete(talk)
                if proposal.confirmed:
                    proposal.confirmed = False
                    proposal.save()
        errors = get_forms_errors(forms)
        error = True
        if errors:
            messages.error(request, _("The talk wasn't registered successfully (check form errors)"))
    comments = Comment.objects.filter(proposal=proposal)
    vote = Vote.objects.get_for_user(proposal, request.user)
    score = Vote.objects.get_score(proposal)
    render_dict = dict(comments=comments, comment_form=CommentForm(), user=request.user, proposal=proposal)
    if vote or score:
        render_dict.update({'vote': vote, 'score': score})

    render_dict.update({'multipart': False, 'errors': errors, 'form': talk_form, 'error': error})
    return render(request,
                  'talks/detail.html',
                  update_sede_info(sede_url, render_dict))
예제 #12
0
 def get(self, request, id):
     if request.user.is_authenticated:
         comment = Comment.objects.get(id=id)
         if request.user == comment.author:
             form = CommentForm(instance=comment)
             return render(request, "update_comment.html", {
                 "form": form,
                 "id": id
             })
     return redirect('book-detail', slug=comment.book.slug)
예제 #13
0
 def get(self, request, slug, id_comment):
     if request.user.is_authenticated:
         comment = Comment.objects.get(id=id_comment)
         if request.user == comment.author:
             form = CommentForm(instance=comment)
             return render(request, "update_comment.html", {
                 "form": form,
                 "slug": slug,
                 "id_comment": id_comment
             })
     return redirect("book-detail", slug=slug)
 def get(self, request, slug):
     comment_query = Comment.objects.annotate(
         count_like=Count("users_like")).select_related("author")
     comments = Prefetch("comments", comment_query)
     book = Book.objects.prefetch_related("authors",
                                          comments).get(slug=slug)
     return render(request, "book_detail.html", {
         "book": book,
         "rate": 2,
         'form': CommentForm()
     })
예제 #15
0
 def get(self, request, slug, comment_id):
     if request.user.is_authenticated:
         comment = Comment.objects.get(id=comment_id)
         if request.user == comment.author:
             form = CommentForm(instance=comment)
             return render(request, 'update_comment.html', {
                 'form': form,
                 'slug': slug,
                 'comment_id': comment_id
             })
         return redirect("book-detail", slug=slug)
예제 #16
0
def proposal_detail(request, sede_url, pk):
    proposal = TalkProposal.objects.get(pk=pk)
    comments = Comment.objects.filter(proposal=proposal)
    render_dict = dict(comments=comments, comment_form=CommentForm(), user=request.user, proposal=proposal)
    vote = Vote.objects.get_for_user(proposal, request.user)
    score = Vote.objects.get_score(proposal)
    if vote or score:
        render_dict.update({'vote': vote, 'score': score})
    if proposal.confirmed:
        talk = Talk.objects.get(talk_proposal=proposal)
        render_dict.update({'talk': talk})
    else:
        render_dict.update({'form': TalkForm(sede_url), 'errors': []})
    return render(request, 'talks/detail.html', update_sede_info(sede_url, render_dict))
예제 #17
0
def proposal_detail(request, event_slug, pk):
    proposal = TalkProposal.objects.get(pk=pk)
    comments = Comment.objects.filter(activity=proposal.activity)
    render_dict = dict(comments=comments, comment_form=CommentForm(), proposal=proposal)
    vote = Vote.objects.get_for_user(proposal, request.user)
    score = Vote.objects.get_score(proposal)
    if vote or score:
        render_dict.update({'vote': vote, 'score': score})
    if proposal.confirmed_talk:
        render_dict.update({'talk': proposal, 'form': TalkForm(event_slug, instance=proposal.activity),
                            'form_presentation': PresentationForm(instance=proposal), 'errors': []})
    else:
        render_dict.update({'form': TalkForm(event_slug, instance=proposal.activity), 'errors': []})
    return render(request, 'activities/talks/detail.html', update_event_info(event_slug, render_dict))
예제 #18
0
def talk_registration(request, event_slug, pk):
    errors = []
    error = False
    event = Event.objects.get(slug__iexact=event_slug)

    # FIXME: Esto es lo que se llama una buena chanchada!
    post = generate_datetime(request, event)

    # Fin de la chanchada

    talk_form = TalkForm(event_slug, post)
    proposal = TalkProposal.objects.get(pk=pk)
    forms = [talk_form]
    if request.POST:
        if talk_form.is_valid() and \
                Activity.room_available(request=request, instance=talk_form.instance, event_slug=event_slug):
            try:
                proposal.confirmed_talk = True
                activity = proposal.activity
                activity.start_date = post['start_date']
                activity.end_date = post['end_date']
                activity.room = Room.objects.get(pk=request.POST.get('room', None))
                activity.confirmed = True
                activity.save()
                proposal.save()
                messages.success(request, _("The talk was registered successfully!"))
                return HttpResponseRedirect(reverse("talk_detail", args=[event_slug, proposal.pk]))
            except Exception:
                if proposal.activity.confirmed:
                    proposal.activity.confirmed = False
                    proposal.activity.save()
                if proposal.confirmed_talk:
                    proposal.confirmed_talk = False
                    proposal.save()
        errors = get_forms_errors(forms)
        error = True
        if errors:
            messages.error(request, _("The talk couldn't be registered (check form errors)"))
    comments = Comment.objects.filter(activity=proposal.activity)
    vote = Vote.objects.get_for_user(proposal, request.user)
    score = Vote.objects.get_score(proposal)
    render_dict = dict(comments=comments, comment_form=CommentForm(), user=request.user, proposal=proposal)
    if vote or score:
        render_dict.update({'vote': vote, 'score': score})

    render_dict.update({'multipart': False, 'errors': errors, 'form': talk_form, 'error': error})
    return render(request,
                  'activities/talks/detail.html',
                  update_event_info(event_slug, render_dict))
예제 #19
0
 def get(self, request, slug, id):
     if request.user.is_authenticated:
         comment = Comment.objects.get(id=id)
         book = Books.objects.get(slug=slug)
         genre = Genre.objects.all()
         if request.user in comment.author_comment.all():
             form = CommentForm(instance=comment)
             context = {
                 'genre': genre,
                 'books': book,
                 'form': form,
                 'comment': comment,
             }
             return render(request,
                           'manager/update_comment.html',
                           context=context)
     return redirect('index-page')
예제 #20
0
 def get(self, request, slug):
     comment_query = Comment.objects.select_related("author")
     if request.user.is_authenticated:
         is_owner = Exists(
             User.objects.filter(comment=OuterRef("id"),
                                 id=request.user.id))
         is_liked = Exists(
             User.objects.filter(liked_comments=OuterRef("pk"),
                                 id=request.user.id))
         comment_query = comment_query.annotate(is_owner=is_owner,
                                                is_liked=is_liked)
     comments = Prefetch("comments", comment_query)
     book = Book.objects.prefetch_related("authors",
                                          comments).get(slug=slug)
     if request.user.is_authenticated:
         VisitPage.objects.get_or_create(user=request.user, book_id=slug)
     return render(request, "book_detail.html", {
         "book": book,
         "rate": [1, 2, 3, 4, 5],
         "form": CommentForm()
     })
예제 #21
0
    def get(
        self,
        request,
        slug,
    ):
        comment = Comment.objects.filter(book__slug=slug)
        book = Books.objects.filter(slug=slug)
        genre = Genre.objects.all()
        if request.user.is_authenticated:
            is_owner = Exists(
                User.objects.filter(comment_likers=OuterRef('pk'),
                                    id=request.user.id))
            comment = comment.annotate(is_owner=is_owner)

        context = {
            'genre': genre,
            'books': book,
            'form': CommentForm(),
            'comment': comment,
        }
        return render(request, 'manager/book_comment.html', context=context)
예제 #22
0
    def get(self, request, slug):
        comment_query = Comment.objects.select_related("author")
        if request.user.is_authenticated:
            is_owner = Exists(
                User.objects.filter(users_comments=OuterRef('pk'),
                                    id=request.user.id))
            is_liked = Exists(
                User.objects.filter(liked_comments=OuterRef('pk'),
                                    id=request.user.id))
            comment_query = comment_query.annotate(is_owner=is_owner,
                                                   is_liked=is_liked)
        comments = Prefetch("comments", comment_query)
        book = Book.objects.prefetch_related(
            "authors", comments).annotate(count_comment=Count("comments"))
        if request.user.is_authenticated:
            is_owner = Exists(
                User.objects.filter(books=OuterRef('pk'), id=request.user.id))
            is_liked = Exists(
                User.objects.filter(liked_books=OuterRef('pk'),
                                    id=request.user.id))
            book = book.annotate(is_owner=is_owner, is_liked=is_liked)
        book = book.get(slug=slug)

        if request.user.is_authenticated:
            users = User.objects.all()
            read_user = request.user
            if users.filter(username=read_user).exists():
                read_users_id = users.get(username=read_user).id
                book.read_users.add(read_users_id)
                book.save()

        return render(request, "book_detail.html", {
            "book": book,
            "range": range(1, 6),
            "form": CommentForm()
        })