Exemple #1
0
def get_your_score (request):
    user = user_auth(request)
    problem_id = request.GET['problem_id'] if 'problem_id' in request.GET and request.GET['problem_id'] != '' else None
    contest_id = request.GET['contest_id'] if 'contest_id' in request.GET and request.GET['contest_id'] != '' else None
    score_only = True if 'score_only' in request.GET else False
    
    if problem_id is None or contest_id is None or user is None:
        result = 'N/A'
    else:
        problem = get_object_or_None(Problem, id = problem_id)
        contest = get_object_or_None(Contest, id = contest_id)
        
        if problem is None or contest is None:
            result = 'N/A'
        elif contest.ended is False and contest.with_open_eval is False:
            result = 'N/A'
        else:
            jobs = Job.objects.filter(user = user, problem = problem, contest = contest).order_by('-id')
            if jobs:
                result = str(jobs[0].score) if score_only else "%d points" % jobs[0].score
            else:
                result = 'N/A'
    if result == 'N/A':
        result = '<span style="font-size: 0.8em; color: #808080;">N/A</span>'
    return HttpResponse(result)
def edit_entry(request, username, permalink):
    user = user_auth(request)
    username = get_object_or_404(UserProfile, username=username)
    blog_entry = get_object_or_404(BlogEntry, author=username, permalink=permalink)

    if user.has_perm("web_eval__core.edit_blogentry") is False and user != username:
        return redirect_to_index("You don't have permission to edit this blog entry.")

    if request.method == "POST":
        form = BlogEntryEditForm(request.POST, instance=blog_entry)

        if form.is_valid():
            form.save()

            tags = []
            for tag, value in request.POST.iteritems():
                if re.match("tag(?P<tag_name>\d+)input", tag):
                    tags.append(value)

            update_tags(blog_entry, tags)

            return HttpResponseRedirect(
                reverse(
                    "webEval.web_eval__core.blog__controller.display_entry",
                    kwargs={"username": username.username, "permalink": permalink},
                )
            )
    else:
        form = BlogEntryEditForm(blog_entry)

    return render_to_response(
        "blog/edit_entry.html",
        {"form": form, "blog_entry": blog_entry, "navigation": {"main": "blog", "other": "edit-entry"}},
        context_instance=RequestContext(request),
    )
def admin_page (request):
    user = user_auth(request)
    
    if user.is_superuser is False and user.is_staff is False:
        return redirect_to_index("You don't have permission to access this page")
    
    if request.method == 'POST':
        form = TicketMilestoneForm(request.POST)
        if form.is_valid():
            form.save()
    else:
        form = TicketMilestoneForm()
        
    last_users = UserProfile.objects.all().order_by('-id')[:20]
    last_logins = UserProfile.objects.all().order_by('-last_login')[:20]
    
    return render_to_response('grader/admin_page.html',
                              {
                                    'last_users' : last_users,
                                    'last_logins' : last_logins,
                                    'milestones' : TicketMilestone.objects.all().order_by('due'),
                                    'milestone_form' : form,
                                    'navigation': {
                                        'main' : 'admin',
                                        'other' : 'admin_page',
                                    }
                              },
                              context_instance = RequestContext(request)
                             )
def submit (request):
    user = user_auth(request)
        
    if request.method == 'POST':
        form = JobSubmitForm(request.POST)
        if form.is_valid() and 'solution' in request.FILES:
            job = form.save(commit=False)
            if job.contest.started() is False and user.is_staff is False:
                return redirect_to_index("You can't submit, contest dind't start yet.")
            if job.contest.ended() is True:
                return redirect_to_index("You can't submit, contest ended.")
            job.message, job.type, job.date, job.user, job.source_size, job.percent_completed, job.score = 'Waiting', 'O', datetime.datetime.now(), user, request.FILES['solution'].size, 0, 0
            if job.contest.started() is False or job.contest.code == 'none':
                job.private = True
            job.save()
            save_file(dest = os.path.join(JOBS_DIR, "job%d.%s" % (job.id, job.language)), file = request.FILES['solution'])
            
            return HttpResponseRedirect(reverse('webEval.web_eval__core.grader__controller.status') + '?problem=%s&user=%s' % (job.problem.code, user.username))
    else:
        form = JobSubmitForm()
    
    return render_to_response("grader/submit_form.html",
                             {'form' : form,
                              'compilers' : judge_settings.COMPILERS,
                              'problems' : Problem.objects.all(),
                              'navigation' : {
                                  'main' : 'judge',
                                  'other' : 'display-job',
                              }
                             },
                             context_instance=RequestContext(request))
def edit_post (request, post_id):
    user = user_auth(request)
    post = get_object_or_404(ForumPost, id = post_id)
    
    if post.can_edit(user) is False:
        return redirect_to_index("You don't have permissions to edit this post.")
    
    if request.method == 'POST':
        form = ForumPostEditForm(request.POST, instance = post)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("webEval.web_eval__core.forum__controller.display_topic",
                                                kwargs={'topic_id' : post.topic.id }) + "#%d" % post.id)
    else:
        form = ForumPostEditForm(post)
        
    return render_to_response('forum/edit_post.html',
                              {'post' : post,
                               'form' : form,
                               'navigation' : 
                                {
                                    'main' : 'forum', 
                                    'other' : 'edit-post'
                                }
                              },
                              context_instance = RequestContext(request)
                             )
def display_ticket (request, ticket_id):
    ticket = get_object_or_404(Ticket, id = ticket_id)
    user = user_auth(request)
    
    if request.method == 'POST' and user is not None:
        form = TicketCommentForm(request.POST)
        if form.is_valid():
            if 'comment_id' in request.POST:
                if request.POST['comment_id'] != "":
                    comment = get_object_or_None(TicketComment, id=request.POST['comment_id'])
                    if comment is None or comment.autogenerated or (user.is_staff is False and user != comment.author) or comment.can_be_edited() is False:
                        return redirect_to_index("You can't edit this comment.")
                    form = TicketCommentForm(request.POST, instance = comment)
                    if form.is_valid():
                        form.save()
                else:
                    comment = form.save(commit = False)
                    comment.ticket, comment.author, comment.date_posted = ticket, user, datetime.datetime.now()
                    comment.save()
            else:
                form = TicketCommentForm()
    else:
        form = TicketCommentForm()
    
    return render_to_response('utils/display_ticket.html',
                              {
                                    'ticket' : ticket,
                                    'form' : form,
                                    'navigation' : {
                                        'main' : 'judge',
                                        'other' : 'display-ticket',
                                    }
                              },
                              context_instance = RequestContext(request)
                             )
def new_ticket (request):
    user = user_auth(request)
    
    if request.method == 'POST':
        form = TicketForm(request.POST)
        
        if form.is_valid():
            ticket = form.save(commit = False)
            ticket.severity = 'normal'
            ticket.status = 'open'
            ticket.author = user
            ticket.date_posted = datetime.datetime.now()
            ticket.save()
            return HttpResponseRedirect(reverse('webEval.web_eval__core.utils__controller.tickets'))
    else:
        form = TicketForm()
        
    return render_to_response('utils/new_ticket.html',
                              {
                                    'form' : form,
                                    'ticket_types' : TICKET_TYPES,
                                    'navigation' : {
                                        'main' : 'judge',
                                        'other' : 'new-ticket',
                                    }
                              },
                              context_instance = RequestContext(request)
                             )
Exemple #8
0
def create_contest_wiki_page (contest, request):
    user = user_auth(request)
    
    w = WikiPage()
    w.url = reverse('webEval.web_eval__core.grader__controller.display_contest',
                    kwargs = {'contest_code' : contest.code }).rstrip('/').lstrip('/')
    w.author = user
    w.save()
    
    r = WikiRevision()
    r.revision_id = 1
    r.content = """ 
=== Contest %s ==
Write here about contest %s...
                """ % (contest.code, contest.code)
    r.date = datetime.datetime.now()
    r.ip = get_ip_from_request(request)
    r.wiki_page = w
    r.title = "Contest %s" % contest.code
    r.markup_type = 'C'
    r.security = 'Private'
    r.author = user
    r.save()
    
    w.last_revision = r
    w.save()
    
    return w
def new_entry(request):
    user = user_auth(request)

    if request.method == "POST":
        form = BlogEntryCreateForm(request.POST)
        if form.is_valid():
            blog_entry = form.save(commit=False)
            blog_entry.author = user
            blog_entry.date = datetime.datetime.now()
            blog_entry.permalink = hashlib.md5(str(datetime.datetime.now())).hexdigest()
            blog_entry.save()

            blog_entry.permalink = blog_entry.get_permalink()
            blog_entry.save()
            return HttpResponseRedirect(
                reverse(
                    "webEval.web_eval__core.blog__controller.display_entry",
                    kwargs={"username": blog_entry.author.username, "permalink": blog_entry.permalink},
                )
            )
    else:
        form = BlogEntryCreateForm()
    return render_to_response(
        "blog/new_entry.html",
        {"form": form, "navigation": {"main": "blog", "other": "create-blog-post"}},
        context_instance=RequestContext(request),
    )
def create_problem (request):
    user = user_auth(request)
    
    if not user.has_perm('web_eval__core.add_problem'):
        return redirect_to_index("You don't have permission to add problems.")
        
    if request.method == 'POST':
        form = ProblemCreateForm(request.POST)
        if form.is_valid():
            contest = Contest.objects.get(code = 'none')
            
            problem = form.save(commit = False)
            
            problem.name = problem.code
            problem.owner = user
            problem.resource = contest
            
            try:
                problem.author = Author.objects.get(name = '%s %s' % (user.first_name, user.last_name))
            except:
                author = Author(name = '%s %s' % (user.first_name, user.last_name),
                       code = '%s_%s' % (user.first_name, user.last_name))
                author.save()
                problem.author = author
            
            problem.time_limit = judge_settings.DEFAULT_TIME_LIMIT
            problem.memory_limit = judge_settings.DEFAULT_MEMORY_LIMIT
            problem.source_limit = judge_settings.DEFAULT_SOURCE_LIMIT
            
            problem.forum_topic = None
            problem.wiki_page = create_problem_wiki_page(problem, request)
            problem.type = 'Normal'
            
            problem.save()
            
            contest.problems.add(problem)
            contest.save()
            
            os.system("mkdir %s" % os.path.join(TESTS_DIR, problem.code))
            os.system("touch %s" % os.path.join(TESTS_DIR, problem.code, 'tests.txt'))
            os.system("svn add %s" % os.path.join(TESTS_DIR, problem.code))
            
            return HttpResponseRedirect(reverse('webEval.web_eval__core.grader__controller.configure_problem',
                                                kwargs={'problem_code' : problem.code}
                                               )
                                       )
    else:
        form = ProblemCreateForm()
        
    return render_to_response("grader/create_problem.html",
                             {
                                'form' : form,
                                'navigation' : 
                                {
                                    'main' : 'admin', 
                                    'other' : 'create-problem'
                                }
                             },
                             context_instance=RequestContext(request))
def delete_entry(request, username, permalink):
    user = user_auth(request)

    if user.has_perm("web_eval__core.blogentry_delete") is False:
        return redirect_to_index("You don't have permission to delete blog entries.")

    username = get_object_or_404(UserProfile, username=username)
    blog_entry = get_object_or_404(BlogEntry, author=username, permalink=permalink)
    blog_entry.delete()

    return HttpResponseRedirect(reverse("webEval.web_eval__core.blog__controller.index"))
def display_contest (request, contest_code):
    user = user_auth (request)
    contest = get_object_or_404 (Contest, code = contest_code)
    
    return display_revision(revision = contest.wiki_page.last_revision,
                            user = user,
                            widgets = {
                                            'is_contest' : True,
                                            'contest' : contest,
                                      },
                            context_instance = RequestContext(request),
                           )
def edit_page (request, page_url, widgets = {}):
    user = user_auth(request)
    page = get_object_or_404(WikiPage, url=page_url)    
    revisions_list = WikiRevision.objects.filter(wiki_page=page)

    if not page.last_revision.can_edit(user):
        return redirect_to_index("You don't have enough rights to edit this page, i will redirect you...")
    
    if request.method == 'POST':    # we have some POST data.
        form = WikiRevisionEditForm(request.POST)
        if form.is_valid():
            revision = form.save(commit = False)
            revision.revision_id = page.last_revision.revision_id + 1
            revision.date = datetime.datetime.now()
            revision.ip = get_ip_from_request(request)
            revision.wiki_page = page
            revision.author = user
            revision.save()
            
            page.last_revision = revision
            page.save()
            if 'is_problem' in widgets:
                return HttpResponseRedirect(reverse('webEval.web_eval__core.grader__controller.display_problem',
                                                    kwargs = {'problem_code' : widgets['problem'].code }))
                
            return HttpResponseRedirect(reverse('webEval.web_eval__core.wiki__controller.display_page',
                                                    kwargs = {'page_url' : page.url }))
        else:
            print form.errors
    else:    
        form = WikiRevisionEditForm(page.last_revision)
        
    can_attach = page.last_revision.wiki_page.can_attach_files(user)
    can_edit = page.last_revision.can_edit(user)
    can_view = page.last_revision.can_view(user)
    
    return render_to_response('wiki_edit_revision.html', 
                              {'revision' : page.last_revision,
                               'page' : page,
                               'form' : form,
                               'edit' : True,
                               'widgets' : widgets,
                               'can_view' : can_view,
                               'can_edit' : can_edit,
                               'can_attach' : can_attach,
                               'navigation' : {
                                    'main' : 'wiki',
                                    'other' : 'edit-page',
                               }
                              },
                              context_instance = RequestContext(request)
                             )
def delete_attachment (request, page_url, hash):
    user = user_auth(request)
    wiki_page = get_object_or_404(WikiPage, url = page_url)
    attachment = get_object_or_404(WikiAttachment, wiki_page = wiki_page, hash = hash)
    
    if attachment.can_delete(user) is False:
        return redirect_to_index("You don't have enough permissions to delete this attachment.")
    
    os.remove(os.path.join(ATTACHMENTS_DIR, "attachment%d-%s" % (attachment.id, attachment.name)))
    attachment.delete()
    
    return HttpResponseRedirect(reverse('webEval.web_eval__core.wiki__controller.attachments',
                                        kwargs={'page_url' : wiki_page.url }))
def toogle_contest_registration (request, contest_code):
    user = user_auth(request)
    contest = get_object_or_404(Contest, code = contest_code)
    
    if contest.registration_started is True or contest.registration_ended is False:
        if contest.registered_users.filter(username=user.username):
            contest.registered_users.remove(user)
        else:
            contest.registered_users.add(user)
    return HttpResponseRedirect(reverse('webEval.web_eval__core.grader__controller.display_contest',
                                       kwargs = {'contest_code' : contest.code }
                                      )
                               )
def display_problem (request, problem_code):
    user = user_auth (request)
    problem = get_object_or_404 (Problem, code = problem_code)
    
    return display_revision(revision = problem.wiki_page.last_revision,
                            user = user,
                            widgets = {
                                            'is_problem' : True,
                                            'problem' : problem,
                                            'submit_form' : JobSubmitForm(),
                                            'compilers' : judge_settings.COMPILERS,
                                      },
                            context_instance = RequestContext(request),
                           )
def toogle_dashboard(request, username, permalink):
    user = user_auth(request)
    username = get_object_or_404(UserProfile, username=username)
    blog_entry = get_object_or_404(BlogEntry, author=username, permalink=permalink)

    if user.has_perm("web_eval__core_add_dashboardentry") is False:
        return redirect_to_index("You don't have permission to modify dashboard.")

    if DashboardEntry.objects.filter(blog_entry=blog_entry):
        DashboardEntry.objects.filter(blog_entry=blog_entry).delete()
    else:
        DashboardEntry(blog_entry=blog_entry).save()

    return HttpResponseRedirect(reverse("webEval.web_eval__core.wiki__controller.dashboard"))
def new_topic (request, board_id):
    board = get_object_or_404(ForumBoard, id=board_id)
    user = user_auth(request)
    
    if request.method == 'POST':
        form = ForumTopicCreateForm(request.POST)
        if form.is_valid():
            topic = ForumTopic(board=board, author=user)
            topic.save()
            
            post = ForumPost()
            post.topic = topic
            post.author = user
            post.title = form.data['title']
            post.content = form.data['content']
            post.date = datetime.datetime.now()
            post.save()
            
            topic.first_post = post
            topic.last_post = post
            topic.save()
            
            board_it = topic.board
            while board_it is not None:
                board_it.topics += 1
                board_it.last_post = post
                board_it.save()
                board_it = board_it.parent_board
            
            
            user.forum_posts += 1
            user.save()
            
            return HttpResponseRedirect(reverse('webEval.web_eval__core.forum__controller.display_topic',
                                                kwargs={'topic_id' : topic.id}))
    else:
        form = ForumTopicCreateForm()

    return render_to_response('forum/new_topic.html',
                              {'board' : board,
                               'form' : form,
                               'stack' : get_parents(board),
                               'navigation' : 
                                {
                                    'main' : 'forum', 
                                    'other' : 'new-topic'
                                }
                              },
                              context_instance = RequestContext(request)
                             )
def display_problems_by_author (request, author_code):
    user = user_auth(request)
    author = get_object_or_404(Author, code = author_code)
    problems = Problem.objects.filter(author = author)
    
    return render_to_response('grader/display_problems_by_author.html',
                              {
                                    'author' : author,
                                    'problems' : problems,
                                    'navigation' : {
                                        'main' : 'judge',
                                        'other' : 'display-problems-by-author'
                                    }
                              },
                              context_instance = RequestContext(request))
def attach (request, page_url):
    user = user_auth(request)
    page = get_object_or_404(WikiPage, url = page_url)
    
    if page.can_attach_files(user) is False:
        return redirect_to_index("You don't have permissions to attach files to this page.")
    
    message = None

    if request.method == 'POST':
        if 'file_name' in request.FILES:
            attachment = WikiAttachment()
            attachment.name = request.FILES['file_name'].name
            attachment.wiki_page = page
            attachment.ip = get_ip_from_request(request)
            attachment.size = request.FILES['file_name'].size
            attachment.date = datetime.datetime.now()
            attachment.author = user
            attachment.security = 'Public'
            attachment.hash = ''
            attachment.save()
            
            attachment.hash = hashlib.md5(str(attachment.id)).hexdigest()
            attachment.save()
            
            save_file(dest = os.path.join(ATTACHMENTS_DIR, "attachment%d-%s" % (attachment.id, attachment.name)), file = request.FILES['file_name'])
            
            message = 'File uploaded successfully.'
        
    can_attach = page.last_revision.wiki_page.can_attach_files(user)
    can_edit = page.last_revision.can_edit(user)
    can_view = page.last_revision.can_view(user)
        
    return render_to_response('wiki/attach.html',
                              {
                               'page' : page,
                               'message' : message if message is not None else '',
                               'can_view' : can_view,
                               'can_edit' : can_edit,
                               'can_attach' : can_attach,
                               'navigation' : {
                                    'main' : 'wiki',
                                    'other' : 'attach',
                               }
                              },
                              context_instance = RequestContext(request),
                             )
def edit_problem_tags (request, problem_code):
    user = user_auth(request)
    
    if user is None or user.has_perm('web_eval__core.edit_problem') is False:
        return redirect_to_index("You don't have permission to edit problems.")
    
    problem = get_object_or_404(Problem, code = problem_code)
    return render_to_response('grader/edit_problem_tags.html',
                              {
                                    'problem' : problem,
                                    'navigation' : {
                                        'main' : 'judge',
                                        'other' : 'edit-problem-tags',
                                    }
                              },
                              context_instance = RequestContext(request)
                             )
def reply (request, topic_id):
    user = user_auth(request)
    topic = get_object_or_404(ForumTopic, id = topic_id)
    board = topic.board
    
    if request.method == 'POST':
        form = ForumPostReplyForm(request.POST)
        if form.is_valid():
            post = form.save(commit = False)
            post.topic = topic
            post.author = user
            post.date = datetime.datetime.now()
            post.save()
            
            post.topic.posts += 1
            post.topic.last_post = post
            post.topic.save()
            
            board_it = post.topic.board
            while board_it is not None:
                board_it.posts += 1
                board_it.last_post = post
                board_it.save()
                board_it = board_it.parent_board
            
            user.forum_posts += 1
            user.save()
            
            return HttpResponseRedirect(reverse('webEval.web_eval__core.forum__controller.display_topic',
                                                kwargs={'topic_id' : topic.id}))
    else:
        form = ForumPostReplyForm()

    return render_to_response('forum/reply.html',
                              {'topic' : topic,
                               'form' : form,
                               'stack' : get_parents(board),
                               'navigation' : 
                                {
                                    'main' : 'forum', 
                                    'other' : 'reply'
                                }
                              },
                              context_instance = RequestContext(request)
                             )
    
def display_attachment (request, page_url, hash):
    user = user_auth(request)
    wiki_page = get_object_or_404(WikiPage, url = page_url)
    attachment = get_object_or_404(WikiAttachment, wiki_page = wiki_page, hash = hash)
    
    if attachment.can_view(user) is False:
        return redirect_to_index("You don't have enough permissions to view this attachment.")
    
    filename = os.path.join(ATTACHMENTS_DIR, "attachment%d-%s" % (attachment.id, attachment.name))
    try:
      wrapper = FileWrapper(file(filename))
    except IOError:
      raise Http404
    response = HttpResponse(wrapper, content_type='text/plain')
    response['Content-Length'] = os.path.getsize(filename)
    response['Content-Disposition'] = 'attachment; filename="%s"' % attachment.name.replace('"', '')
    return response
def display_job (request, job_id):
    user = user_auth (request)
    job = get_object_or_404(Job, id=job_id)
    
    if job.can_view(user) is False:
        return redirect_to_index("You don't have permission to view this job")
        
    return render_to_response("grader/display_job.html",
                              {
                                    'job' : job,
                                    'tests' : Test.objects.filter(job=job).order_by('no'),
                                    'navigation' : {
                                        'main' : 'judge',
                                        'other' : 'display-job',
                                    }
                              },
                              context_instance = RequestContext(request))
Exemple #25
0
def create_eval (request):
    user = user_auth(request)
    
    if user.has_perm('api.add_eval') is False:
        return redirect_to_index('You don\'t have permission to add evals.')
    
    if request.method == 'POST':
        form = CreateEvalForm(request)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('')
    else:
        form = CreateEvalForm()
        
    return render_to_response('api/create_eval.html',
                              {'form' : form },
                              context_instance = RequestContext(request)
                             )
def display_topic (request, topic_id):
    topic = get_object_or_404(ForumTopic, id = topic_id)
    user = user_auth(request)
    
    topic.views += 1
    topic.save()
    
    return render_to_response('forum/display_topic.html',
                              {'topic' : topic,
                               'stack' : get_parents(topic.board),
                               'posts' : ForumPost.objects.filter(topic=topic),
                               'navigation' : 
                                {
                                    'main' : 'forum', 
                                    'other' : 'display-topic'
                                }
                              },
                              context_instance = RequestContext(request)
                             )
def create_wiki_page (request, page_url = None):  
    user = user_auth(request)
    
    if user.has_perm('web_eval__core.add_wikipage') is False:
        return redirect_to_index("You don't have permission to add wiki pages.")
    
    if WikiPage.objects.filter(url = page_url):
        return redirect_to_index("Page already exists...")
    
    if request.method == 'POST':
        form = WikiRevisionEditForm(request.POST)
        
        if form.is_valid():
            page_url = request.POST['url']
            page = WikiPage()
            page.url = page_url
            page.author = user
            page.save()
            
            revision = form.save(commit = False)
            revision.revision_id = 1
            revision.date = datetime.datetime.now()
            revision.ip = get_ip_from_request(request)
            revision.wiki_page = page
            revision.author = user
            revision.save()
            
            page.last_revision = revision
            page.save()
            
            return HttpResponseRedirect(reverse('webEval.web_eval__core.wiki__controller.display_page',
                                            kwargs={'page_url' : page_url }))
    else:
        form = WikiRevisionEditForm()
    
    return render_to_response('wiki_edit_revision.html', 
                              {'revision' : 1,
                               'form' : form,
                               'edit' : False,
                               'page_url' : page_url,
                              },
                              context_instance = RequestContext(request)
                             )
def display_page (request, page_url, revision_id = None, widgets = {}):
    page = get_object_or_None(WikiPage, url = page_url)
    
    if page is None:
        return create_wiki_page(request, page_url)
        
    if revision_id is None:    # Viewing the last revision of page
        revision = page.last_revision
    else:   # Getting revision by revision_id or none
        revision = get_object_or_404(WikiRevision, wiki_page = page, revision_id = revision_id)
        
    # get the current user    
    user = user_auth(request)
    
    return display_revision(revision = revision, 
                            user = user,
                            widgets = widgets, 
                            context_instance = RequestContext(request),
                           )
def display_job_source_code (request, job_id):
    user = user_auth (request)
    job = get_object_or_404(Job, id=job_id)
    
    if job.can_view_source_code(user) is False:
        return redirect_to_index("You don't have permission to view this job's source code")
        
    lexer = get_lexer_by_name(pygments_standardize(job.language), stripall=True, tabsize=4)
    formatter = HtmlFormatter(linenos=True)
    source_code = highlight(''.join(open(os.path.join(JOBS_DIR, 'job%d.%s' % (job.id, job.language)), 'r').readlines()), lexer, formatter)

    return render_to_response("grader/display_job_source_code.html",
                              {
                                'job' : job,
                                'source_code' : source_code,
                                'navigation' : {
                                    'main' : 'judge',
                                    'other' : 'display-job-source',
                                }
                              },
                              context_instance = RequestContext(request))
def delete_post (request, post_id):
    user = user_auth(request)
    post = get_object_or_404(ForumPost, id = post_id)
    
    if post.can_delete(user) is False:
        return redirect_to_index("You don't have enough permissions to delete this post.")
    
    topic = post.topic
    topic.posts -= 1
    topic.save()
    
    if post == topic.last_post:
        topic.last_post = ForumPost.objects.filter(topic = topic).order_by('id').reverse()[1]
        topic.save()
    
    board_it = post.topic.board
    while board_it is not None:
        board_it.posts -= 1
        board_it.save()
        if board_it.last_post == post:
            fake_post = ForumPost(id=-1)
            
            for y in ForumTopic.objects.filter(board=board_it):
                if y.last_post is not None and y.last_post != post and y.last_post.id > fake_post.id:
                    fake_post = y.last_post
            for y in ForumBoard.objects.filter(parent_board=board_it):
                if y.last_post is not None and y.last_post != post and y.last_post.id > fake_post.id:
                    fake_post = y.last_post
            board_it.last_post = fake_post
            board_it.save()
        board_it = board_it.parent_board
    
    
    post.author.forum_posts -= 1
    post.author.save()
    
    post.delete()
    
    return HttpResponseRedirect(reverse("webEval.web_eval__core.forum__controller.display_topic",
                                                kwargs={'topic_id' : topic.id }))