예제 #1
0
 def form_valid(self, form):
     ticket = Ticket(user=self.request.user.profile,
                     title=form.cleaned_data['title'])
     ticket.linked_item = self.object
     ticket.save()
     message = TicketMessage(ticket=ticket,
                             user=ticket.user,
                             body=form.cleaned_data['body'])
     message.save()
     ticket.assignees.set(self.get_assignees())
     link_url = reverse('ticket', args=[ticket.id])
     new_notifications(
         [u.user.username
          for u in self.get_assignees()], ('%s: <a href=\"%s\">%s</a>') %
         (_('New ticket was registered'), link_url, ticket.title),
         'success')
     if event.real:
         event.post(
             'tickets', {
                 'type':
                 'new-ticket',
                 'id':
                 ticket.id,
                 'message':
                 message.id,
                 'user':
                 ticket.user_id,
                 'assignees':
                 list(ticket.assignees.values_list('id', flat=True)),
             })
     return HttpResponseRedirect(link_url)
예제 #2
0
 def form_valid(self, form):
     ticket = Ticket(user=self.request.user.profile,
                     title=form.cleaned_data['title'])
     ticket.linked_item = self.object
     ticket.save()
     message = TicketMessage(ticket=ticket,
                             user=ticket.user,
                             body=form.cleaned_data['body'])
     message.save()
     ticket.assignees.set(self.get_assignees())
     if event.real:
         event.post(
             'tickets', {
                 'type':
                 'new-ticket',
                 'id':
                 ticket.id,
                 'message':
                 message.id,
                 'user':
                 ticket.user_id,
                 'assignees':
                 list(ticket.assignees.values_list('id', flat=True)),
             })
     return HttpResponseRedirect(reverse('ticket', args=[ticket.id]))
예제 #3
0
    def get_context_data(self, **kwargs):
        context = super(PostList, self).get_context_data(**kwargs)
        context['title'] = self.title or _(
            'Page %d of Posts') % context['page_obj'].number
        context['first_page_href'] = reverse('home')
        context['page_prefix'] = reverse('blog_post_list')
        context['comments'] = Comment.most_recent(self.request.user, 10)
        context['new_problems'] = Problem.objects.filter(
            is_public=True,
            is_organization_private=False).order_by('-date', '-id')[:7]
        context['page_titles'] = CacheDict(
            lambda page: Comment.get_page_title(page))

        context['has_clarifications'] = False
        if self.request.user.is_authenticated:
            participation = self.request.profile.current_contest
            if participation:
                clarifications = ProblemClarification.objects.filter(
                    problem__in=participation.contest.problems.all())
                context['has_clarifications'] = clarifications.count() > 0
                context['clarifications'] = clarifications.order_by('-date')

        context['user_count'] = lazy(Profile.objects.count, int, long)
        context['problem_count'] = lazy(
            Problem.objects.filter(is_public=True).count, int, long)
        context['submission_count'] = lazy(Submission.objects.count, int, long)
        context['language_count'] = lazy(Language.objects.count, int, long)

        context['post_comment_counts'] = {
            int(page[2:]): count
            for page, count in Comment.objects.filter(
                page__in=['b:%d' % post.id for post in context['posts']],
                hidden=False).values_list('page').annotate(
                    count=Count('page')).order_by()
        }

        now = timezone.now()

        visible_contests = Contest.contests_list(
            self.request.user).order_by('start_time')

        context['current_contests'] = visible_contests.filter(
            start_time__lte=now, end_time__gt=now)
        context['future_contests'] = visible_contests.filter(
            start_time__gt=now)

        if self.request.user.is_authenticated:
            context['own_open_tickets'] = Ticket.tickets_list(
                self.request.user, author=self.request.user)
        else:
            context['own_open_tickets'] = []

        # Superusers better be staffs, not the spell-casting kind either.
        if self.request.user.is_staff:
            context['open_tickets'] = Ticket.tickets_list(
                self.request.user)[:10]
        else:
            context['open_tickets'] = []
        return context
예제 #4
0
파일: ticket.py 프로젝트: DMOJ/site
 def form_valid(self, form):
     ticket = Ticket(user=self.request.user.profile, title=form.cleaned_data['title'])
     ticket.linked_item = self.object
     ticket.save()
     message = TicketMessage(ticket=ticket, user=ticket.user, body=form.cleaned_data['body'])
     message.save()
     ticket.assignees.set(self.get_assignees())
     if event.real:
         event.post('tickets', {
             'type': 'new-ticket', 'id': ticket.id,
             'message': message.id, 'user': ticket.user_id,
             'assignees': list(ticket.assignees.values_list('id', flat=True)),
         })
     return HttpResponseRedirect(reverse('ticket', args=[ticket.id]))
예제 #5
0
    def get_context_data(self, **kwargs):
        context = super(PostList, self).get_context_data(**kwargs)
        context['title'] = self.title or _('Page %d of Posts') % context['page_obj'].number
        context['first_page_href'] = reverse('home')
        context['page_prefix'] = reverse('blog_post_list')
        context['new_problems'] = Problem.get_public_problems() \
                                         .order_by('-date', '-id')[:settings.DMOJ_BLOG_NEW_PROBLEM_COUNT]

        context['has_clarifications'] = False
        if self.request.user.is_authenticated:
            participation = self.request.profile.current_contest
            if participation:
                clarifications = ProblemClarification.objects.filter(problem__in=participation.contest.problems.all())
                context['has_clarifications'] = clarifications.count() > 0
                context['clarifications'] = clarifications.order_by('-date')

        context['user_count'] = lazy(Profile.objects.count, int, int)
        context['problem_count'] = lazy(Problem.get_public_problems().count, int, int)
        context['submission_count'] = lazy(Submission.objects.count, int, int)
        context['language_count'] = lazy(Language.objects.count, int, int)

        now = timezone.now()

        visible_contests = Contest.get_visible_contests(self.request.user).order_by('start_time')

        context['current_contests'] = visible_contests.filter(start_time__lte=now, end_time__gt=now)
        context['future_contests'] = visible_contests.filter(start_time__gt=now)

        if self.request.user.is_authenticated:
            context['own_open_tickets'] = Ticket.tickets_list(self.request.user).filter(user=self.request.profile)
        else:
            context['own_open_tickets'] = []

        # Superusers better be staffs, not the spell-casting kind either.
        if self.request.user.is_staff:
            context['open_tickets'] = Ticket.tickets_list(self.request.user)[:10]
        else:
            context['open_tickets'] = []
        return context
예제 #6
0
파일: ticket.py 프로젝트: VNOI-Admin/OJ
 def form_valid(self, form):
     ticket = Ticket(user=self.request.profile,
                     title=form.cleaned_data['title'])
     issue_object = GeneralIssue(issue_url=form.cleaned_data['issue_url'])
     issue_object.save()
     ticket.linked_item = issue_object
     ticket.save()
     message = TicketMessage(ticket=ticket,
                             user=ticket.user,
                             body=form.cleaned_data['body'])
     message.save()
     if event.real:
         event.post(
             'tickets', {
                 'type': 'new-ticket',
                 'id': ticket.id,
                 'message': message.id,
                 'user': ticket.user_id,
                 'assignees': [],
             })
     on_new_ticket.delay(ticket.pk, ticket.content_type.pk,
                         ticket.object_id, form.cleaned_data['body'])
     return HttpResponseRedirect(reverse('ticket', args=[ticket.id]))
예제 #7
0
    def get_context_data(self, **kwargs):
        if not self.request.user.is_authenticated:
            raise Http404()
        user = self.request.user
        profile = self.request.profile
        context = super(UserDashboard, self).get_context_data(**kwargs)
        context['recently_attempted_problems'] = (
            Submission.objects.filter(
                user=profile, problem__is_public=True).exclude(
                    problem_id__in=user_completed_ids(profile)).values_list(
                        'problem__code', 'problem__name',
                        'problem__points').annotate(
                            points=Max('points'),
                            latest=Max('date')).order_by('-latest')
            [:settings.DMOJ_BLOG_RECENTLY_ATTEMPTED_PROBLEMS_COUNT])
        context['own_tickets'] = Ticket.tickets_list(user).filter(
            user=profile)[:10]

        return context