コード例 #1
0
 def get_context_data(self, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     context = super(EditAnswerView, self).get_context_data(**kwargs)
     context.update({
         'form':
         AnswerForm(instance=Answers.objects.get(id=self.kwargs.get('pk'))),
     })
     return context
コード例 #2
0
 def get_context_data(self, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     context = super(UsersListView, self).get_context_data(**kwargs)
     context['users'] = User.objects.all()
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #3
0
 def post(self, request, *args, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     user = self.request.user
     Answer_form = AnswerForm(request.POST)
     if Answer_form.is_valid():
         Answer = Answer_form.save(commit=False)
         Answer.username = user
         Answer.question = get_object_or_404(Questions,
                                             pk=self.kwargs.get('pk'))
         Answer.save()
     return redirect('ForumsApp:answer', pk=self.kwargs.get('pk'))
コード例 #4
0
ファイル: comment.py プロジェクト: Rajesh5466/ForumsProject
 def post(self, request, *args, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     user = self.request.user
     Comment_form = CommentForm(request.POST)
     if Comment_form.is_valid():
         Comment = Comment_form.save(commit=False)
         Comment.username = user
         Comment.answer = get_object_or_404(Answers,
                                            pk=self.kwargs.get('pk1'))
         Comment.save()
     return redirect('ForumsApp:answer', pk=self.kwargs.get('pk'))
コード例 #5
0
 def get_context_data(self, *, object_list=None, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     key = self.kwargs.get('pk')
     context = super(UserAnswersListView, self).get_context_data(**kwargs)
     context['data'] = Answers.objects.values(
         'question_id__title', 'question_id',
         'username__username').filter(username_id=key)
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #6
0
 def get_context_data(self, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     context = super(QuestionListView, self).get_context_data(**kwargs)
     context['data'] = self.model.objects.all().values(
         'id', 'title', 'username__username',
         'tags').annotate(count=Count('answers__id'))
     context['datalen'] = len(context['data'])
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #7
0
 def get_context_data(self, *, object_list=None, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     key = self.kwargs.get('pk')
     context = super(UserQuestionsListView, self).get_context_data(**kwargs)
     context['questions'] = Questions.objects.all().values(
         'id', 'title', 'username__username').filter(
             username_id=key).annotate(count=Count('answers__id'))
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #8
0
 def get_context_data(self, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     context = super(QuestionTagsListView, self).get_context_data(**kwargs)
     tag = self.kwargs.get('tag')
     context['data'] = Questions.objects.filter(
         Q(tags__contains=tag + "#") | Q(tags__endswith=tag)).values(
             'id', 'title', 'username__username',
             'tags').annotate(count=Count('answers__id'))
     context['datalen'] = len(context['data'])
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #9
0
 def get_context_data(self, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     context = super(TagSearchView, self).get_context_data(**kwargs)
     queryset = Questions.objects.values('tags')
     tagsList = []
     for query in queryset:
         tagsList = tagsList + query['tags'].split("#")[1:]
     tagsSet = set(tagsList)
     context['tags'] = [(y, tagsList.count(y)) for y in tagsSet]
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #10
0
ファイル: comment.py プロジェクト: Rajesh5466/ForumsProject
 def get_context_data(self, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     key = self.kwargs.get('pk1')
     context = super(CommentListView, self).get_context_data(**kwargs)
     context['data'] = self.model.objects.values(
         'id', 'description', 'username__username',
         'username__id').filter(answer_id=key)
     context['datalen'] = len(context['data'])
     context['answerinfo'] = Answers.objects.values(
         'id', 'description', 'question_id',
         'username__username').get(pk=key)
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #11
0
 def get_context_data(self, *, object_list=None, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     key = self.kwargs.get('pk')
     context = super(UserDetailsView, self).get_context_data(**kwargs)
     context['questionsCount'] = len(
         Questions.objects.values().filter(username_id=key))
     context['answersCount'] = len(
         Answers.objects.values().filter(username_id=key))
     context['commentsCount'] = len(
         AnswersComments.objects.values().filter(username_id=key))
     context['userid'] = key
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #12
0
 def get_context_data(self, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     key = self.kwargs.get('pk')
     context = super(AnswerListView, self).get_context_data(**kwargs)
     context['data'] = self.model.objects.values(
         'id', 'description', 'username__username', 'username__id', 'likes',
         'dislikes').filter(question_id=key)
     context['questionid'] = key
     context['questionuser'] = Questions.objects.values(
         'username__username').get(pk=key)
     context['question'] = Questions.objects.values(
         'title', 'description').get(pk=key)
     context['datalen'] = len(context['data'])
     context.update({
         'user_permissions':
         self.request.user.get_all_permissions,
     })
     return context
コード例 #13
0
    def get(self, request, *args, **kwargs):
        UpdateLoginTimeView.updateTime(self.request)
        answerId = self.kwargs.get('pk1')
        userId = self.kwargs.get('pk2')
        vote_Value = int(self.kwargs.get('pk3'))
        Record = []
        try:
            Record = get_object_or_404(
                AnswerVotes,
                Q(answer_id=answerId) & Q(username_id=userId))
        except:
            pass
        answerRecord = Answers.objects.get(id=answerId)
        if Record:
            if not vote_Value == Record.vote:
                Record.vote = vote_Value
                Record.save()
                if vote_Value == 1:
                    answerRecord.likes = answerRecord.likes + 1
                    answerRecord.dislikes = answerRecord.dislikes - 1
                elif vote_Value == -1:
                    answerRecord.likes = answerRecord.likes - 1
                    answerRecord.dislikes = answerRecord.dislikes + 1
            else:
                Record.delete()
                if vote_Value == 1:
                    answerRecord.likes = answerRecord.likes - 1
                elif vote_Value == -1:
                    answerRecord.dislikes = answerRecord.dislikes - 1
        else:
            obj = AnswerVotes()
            obj.answer = get_object_or_404(Answers, pk=answerId)
            obj.username = get_object_or_404(User, pk=userId)
            obj.vote = vote_Value
            obj.save()
            if vote_Value == 1:
                answerRecord.likes = answerRecord.likes + 1
            elif vote_Value == -1:
                answerRecord.dislikes = answerRecord.dislikes + 1

        answerRecord.save()
        return redirect('ForumsApp:answer', pk=self.kwargs.get('pk'))
コード例 #14
0
def AboutView(request):
    UpdateLoginTimeView.updateTime(request)
    return render(request, 'about.html')
コード例 #15
0
 def get(self, request, *args, **kwargs):
     UpdateLoginTimeView.updateTime(self.request)
     return super().get(self, request, *args, **kwargs)