예제 #1
0
def add(request, page_info):
    if request.method=="POST":
        form = GlobalSubpageEditForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            fid = data['fid']
            subpage = Subpage.create_global(SubpageStruct(is_announcement=False,
                                                               content='',
                                                               name=data['name'],
                                                               is_public=data['is_public']))
            rightfield.roles = [Security.anonymous(),Security.authenticated(),None]
            rightfield.objects = [subpage,subpage,None]
            rightfield.rights = ['VIEW','VIEW','']
            rightfield.set(data['visibility'])
            for ufile in glob.glob(os.path.join(fid, '*')):
                subpage.content_files_set_blob_path(os.path.basename(ufile), ufile)
            try:
                subpage.content = data["content"]
            except SphinxException as sphinxException:
                subpage.delete()
                form._errors['content'] = form.error_class([sphinxException])
                return render_to_response('subpage_add.html', { 'fid' : fid,
                                                                'form' : form, 
                                                                'page_info' : page_info })
            except e:
                subpage.delete()
                raise e
            return HttpResponseRedirect(reverse('subpage',args=[subpage.id]))
    else:
        #TODO(kalq): Create a hash instead of full pathname
        fid = mkdtemp()
        form = GlobalSubpageEditForm(initial={ 'fid' : fid })
    return render_to_response('subpage_add.html', { 'fid' : fid,
                                                    'form' : form,
                                                    'page_info' : page_info })
예제 #2
0
파일: news.py 프로젝트: zielmicha/satori
def add(request, page_info):
    if request.method=="POST":
        form = ContestNewsEditForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            fid = data['fid']
            message = Subpage.create_for_contest(SubpageStruct(is_announcement=True,
                                                               contest=page_info.contest,
                                                               name=data['name'],
                                                               content='',
                                                               is_sticky=data['is_sticky'],
                                                               is_public=data['is_public']))
            Privilege.grant(Security.anonymous(),message,'VIEW')
            for ufile in glob.glob(os.path.join(fid, '*')):
                message.content_files_set_blob_path(os.path.basename(ufile), ufile)
            try:
                message.content = data['content']
            except SphinxException as sphinxException:
                message.delete()
                form._errors['content'] = form.error_class([sphinxException])
                return render_to_response('news_add.html', { 'form' : form,
                                                             'fid' : fid,
                                                             'page_info' : page_info })
            except e:
                message.delete()
                raise e
            return HttpResponseRedirect(reverse('contest_news',args=[page_info.contest.id]))
    else:
        #TODO(kalq): Create a hash instead of full pathname
        fid = mkdtemp()
        form = ContestNewsEditForm(initial={ 'fid' : fid })
    return render_to_response('news_add.html', { 'page_info' : page_info, 
                                                 'fid' : fid,
                                                 'form' : form })
예제 #3
0
파일: problem.py 프로젝트: zielmicha/satori
def add(request, page_info, id):

    problem = Problem(int(id))
    suites = TestSuite.filter(TestSuiteStruct(problem=problem))

    if request.method == "POST":
        form = ProblemAddForm(data=request.POST,
                              files=request.FILES,
                              suites=suites)
        if form.is_valid():
            data = form.cleaned_data
            fid = data['fid']
            suite = filter(lambda s: s.id == int(data["suite"]), suites)[0]
            mapping = ProblemMapping.create(
                ProblemMappingStruct(contest=page_info.contest,
                                     problem=problem,
                                     code=data['code'],
                                     title=data['title'],
                                     group=data['group'],
                                     statement='',
                                     description=data['description'],
                                     default_test_suite=suite))
            pdf = form.cleaned_data.get('pdf', None)
            if pdf:
                writer = Blob.create(pdf.size)
                writer.write(pdf.read())
                phash = writer.close()
                mapping.statement_files_set_blob_hash('pdf', phash)

            for ufile in glob.glob(os.path.join(fid, '*')):
                mapping.statement_files_set_blob_path(os.path.basename(ufile),
                                                      ufile)
            try:
                mapping.statement = data['statement']
            except SphinxException as sphinxException:
                form._errors['statement'] = form.error_class([sphinxException])
                return render_to_response('problems_add.html', {
                    'fid': fid,
                    'form': form,
                    'page_info': page_info
                })
            return HttpResponseRedirect(
                reverse('contest_problems', args=[page_info.contest.id]))
        return render_to_response('problems_add.html', {
            'form': form,
            'page_info': page_info,
            'base': problem
        })

    else:
        #TODO(kalq): Create a hash instead of full pathname
        fid = mkdtemp()
        form = ProblemAddForm(suites=suites, initial={'fid': fid})
        return render_to_response('problems_add.html', {
            'page_info': page_info,
            'fid': fid,
            'form': form,
            'base': problem
        })
예제 #4
0
파일: subpage.py 프로젝트: zielmicha/satori
def edit(request, page_info,id):

    contest = page_info.contest
    subpage = Subpage.filter(SubpageStruct(id=int(id)))[0]
    rights.roles = [Security.anonymous(),contest.contestant_role,None]
    rights.objects = [subpage,subpage,None]
    rights.check()
    
    class ContestSubpageEditForm(forms.Form):
        name = forms.CharField(label="Subpage name")
        visibility = rights.field()
        fid = SatoriSignedField(required=True) # (temporary) folder id
        content = forms.CharField(required=False, widget=forms.Textarea, label="Content")
    
    if request.method=="POST":
        form = ContestSubpageEditForm(request.POST)
        if form.is_valid():
            if 'delete' in request.POST.keys():
                subpage.delete()
                return HttpResponseRedirect(reverse('contest_manage',args=[contest.id]))
            data = form.cleaned_data
            fid = data['fid']
            for rfile in request.POST:
                if rfile.startswith('rfile'):
                    subpage.content_files_delete(request.POST[rfile])
            for ufile in glob.glob(os.path.join(fid, '*')):
                subpage.content_files_set_blob_path(os.path.basename(ufile), ufile)
            try:
                subpage.modify(SubpageStruct(name=data['name'],
                                             content=data['content']))
                vis = data['visibility']
                rights.set(vis)


            except SphinxException as sphinxException:
                attachments = valid_attachments(subpage.content_files_get_list())
                form._errors['content'] = form.error_class([sphinxException])
                return render_to_response('subpage_edit.html', { 'attachments' : attachments,
                                                                 'fid' : fid,
                                                                 'form' : form,
                                                                 'page_info' : page_info,
                                                                 'subpage' : subpage })
            return HttpResponseRedirect(reverse('contest_subpage', args=[page_info.contest.id, subpage.id]))
    else:
        vis = unicode(rights.current)
        fid = mkdtemp()
        form = ContestSubpageEditForm(initial={ 'name' : subpage.name,
                                                'content' : subpage.content,
                                                'fid' : fid,
                                                'visibility' : vis
                                                })
    attachments = valid_attachments(subpage.content_files_get_list())
    return render_to_response('subpage_edit.html', { 'attachments' : attachments, 
                                                     'fid' : fid,
                                                     'form' : form,
                                                     'page_info' : page_info,
                                                     'subpage' : subpage })
예제 #5
0
파일: news.py 프로젝트: zielmicha/satori
def edit(request, page_info,id):
    message = Subpage.filter(SubpageStruct(id=int(id)))[0]
    if request.method=="POST":
        if 'delete' in request.POST.keys():
            message.delete()
            return HttpResponseRedirect(reverse('contest_news',args=[page_info.contest.id]))
        form = ContestNewsEditForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            fid = data['fid']
            for rfile in request.POST:
                if rfile.startswith('rfile'):
                    message.content_files_delete(request.POST[rfile])
            for ufile in glob.glob(os.path.join(fid, '*')):
                message.content_files_set_blob_path(os.path.basename(ufile), ufile)
            try:
                message.modify(SubpageStruct(name=data['name'],
                                             content=data['content'],
                                             is_sticky=data['is_sticky'],
                                             is_public=data['is_public']))
                if not data['is_public']:
                    Privilege.revoke(Security.anonymous(),message,'VIEW')
                    Privilege.grant(page_info.contest.contestant_role,message,'VIEW')
                else:
                    Privilege.revoke(page_info.contest.contestant_role,message,'VIEW')
                    Privilege.grant(Security.anonymous(),message,'VIEW')
            except SphinxException as sphinxException:
                attachments = valid_attachments(message.content_files_get_list())
                form._errors['content'] = form.error_class([sphinxException])
                return render_to_response('news_edit.html', { 'attachments' : attachments,
                                                              'fid' : fid,
                                                              'form' : form,
                                                              'message' : message, 
                                                              'page_info' : page_info })
            return HttpResponseRedirect(reverse('contest_news',args=[page_info.contest.id]))
    else:
        fid = mkdtemp()
        form = ContestNewsEditForm(initial={ 'name' : message.name,
                                             'content' : message.content,
                                             'fid' : fid,
                                             'is_public' : message.is_public,
                                             'is_sticky' : message.is_sticky})
    attachments = valid_attachments(message.content_files_get_list())
    return render_to_response('news_edit.html', { 'attachments' : attachments,
                                                  'fid' : fid,
                                                  'form' : form,
                                                  'message' : message,
                                                  'page_info' : page_info })
예제 #6
0
def edit(request, page_info, id):
    subpage = Subpage.filter(SubpageStruct(id=int(id)))[0]
    rightfield.roles = [Security.anonymous(),Security.authenticated(),None]
    rightfield.objects = [subpage,subpage,None]
    rightfield.rights = ['VIEW','VIEW','']
    rightfield.check()
    if request.method=="POST":
        if 'delete' in request.POST.keys():
            subpage.delete()
            return HttpResponseRedirect(reverse('news'))
        form = GlobalSubpageEditForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            fid = data['fid']
            for rfile in request.POST:
                if rfile.startswith('rfile'):
                    subpage.content_files_delete(request.POST[rfile])
            for ufile in glob.glob(os.path.join(fid, '*')):
                subpage.content_files_set_blob_path(os.path.basename(ufile), ufile)
            try:
                subpage.modify(SubpageStruct(name=data['name'],
                                             content=data['content'],
                                             is_public=data['is_public']))
                rightfield.set(data['visibility'])
            except SphinxException as sphinxException:
                attachments = valid_attachments(subpage.content_files_get_list())
                form._errors['content'] = form.error_class([sphinxException])
                return render_to_response('subpage_edit.html', { 'attachments' : attachments,
                                                                 'fid' : fid,
                                                                 'form' : form,
                                                                 'page_info' : page_info,
                                                                 'subpage' : subpage })
            return HttpResponseRedirect(reverse('subpage',args=[subpage.id]))
    else:
        fid = mkdtemp()
        form = GlobalSubpageEditForm(initial={ 'name' : subpage.name,
                                               'content' : subpage.content,
                                               'visibility' : unicode(rightfield.current),
                                               'fid' : fid,
                                               'is_public' : subpage.is_public })
    attachments = valid_attachments(subpage.content_files_get_list())
    return render_to_response('subpage_edit.html', { 'attachments' : attachments, 
                                                     'fid' : fid,
                                                     'form' : form,
                                                     'page_info' : page_info,
                                                     'subpage' : subpage })
예제 #7
0
파일: news.py 프로젝트: zielmicha/satori
def add(request, page_info):
    if request.method == "POST":
        form = ContestNewsEditForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            fid = data['fid']
            message = Subpage.create_for_contest(
                SubpageStruct(is_announcement=True,
                              contest=page_info.contest,
                              name=data['name'],
                              content='',
                              is_sticky=data['is_sticky'],
                              is_public=data['is_public']))
            Privilege.grant(Security.anonymous(), message, 'VIEW')
            for ufile in glob.glob(os.path.join(fid, '*')):
                message.content_files_set_blob_path(os.path.basename(ufile),
                                                    ufile)
            try:
                message.content = data['content']
            except SphinxException as sphinxException:
                message.delete()
                form._errors['content'] = form.error_class([sphinxException])
                return render_to_response('news_add.html', {
                    'form': form,
                    'fid': fid,
                    'page_info': page_info
                })
            except e:
                message.delete()
                raise e
            return HttpResponseRedirect(
                reverse('contest_news', args=[page_info.contest.id]))
    else:
        #TODO(kalq): Create a hash instead of full pathname
        fid = mkdtemp()
        form = ContestNewsEditForm(initial={'fid': fid})
    return render_to_response('news_add.html', {
        'page_info': page_info,
        'fid': fid,
        'form': form
    })
예제 #8
0
파일: subpage.py 프로젝트: zielmicha/satori
def edit(request, page_info, id):

    contest = page_info.contest
    subpage = Subpage.filter(SubpageStruct(id=int(id)))[0]
    rights.roles = [Security.anonymous(), contest.contestant_role, None]
    rights.objects = [subpage, subpage, None]
    rights.check()

    class ContestSubpageEditForm(forms.Form):
        name = forms.CharField(label="Subpage name")
        visibility = rights.field()
        fid = SatoriSignedField(required=True)  # (temporary) folder id
        content = forms.CharField(required=False,
                                  widget=forms.Textarea,
                                  label="Content")

    if request.method == "POST":
        form = ContestSubpageEditForm(request.POST)
        if form.is_valid():
            if 'delete' in request.POST.keys():
                subpage.delete()
                return HttpResponseRedirect(
                    reverse('contest_manage', args=[contest.id]))
            data = form.cleaned_data
            fid = data['fid']
            for rfile in request.POST:
                if rfile.startswith('rfile'):
                    subpage.content_files_delete(request.POST[rfile])
            for ufile in glob.glob(os.path.join(fid, '*')):
                subpage.content_files_set_blob_path(os.path.basename(ufile),
                                                    ufile)
            try:
                subpage.modify(
                    SubpageStruct(name=data['name'], content=data['content']))
                vis = data['visibility']
                rights.set(vis)

            except SphinxException as sphinxException:
                attachments = valid_attachments(
                    subpage.content_files_get_list())
                form._errors['content'] = form.error_class([sphinxException])
                return render_to_response(
                    'subpage_edit.html', {
                        'attachments': attachments,
                        'fid': fid,
                        'form': form,
                        'page_info': page_info,
                        'subpage': subpage
                    })
            return HttpResponseRedirect(
                reverse('contest_subpage',
                        args=[page_info.contest.id, subpage.id]))
    else:
        vis = unicode(rights.current)
        fid = mkdtemp()
        form = ContestSubpageEditForm(
            initial={
                'name': subpage.name,
                'content': subpage.content,
                'fid': fid,
                'visibility': vis
            })
    attachments = valid_attachments(subpage.content_files_get_list())
    return render_to_response(
        'subpage_edit.html', {
            'attachments': attachments,
            'fid': fid,
            'form': form,
            'page_info': page_info,
            'subpage': subpage
        })
예제 #9
0
파일: news.py 프로젝트: zielmicha/satori
def edit(request, page_info, id):
    message = Subpage.filter(SubpageStruct(id=int(id)))[0]
    if request.method == "POST":
        if 'delete' in request.POST.keys():
            message.delete()
            return HttpResponseRedirect(
                reverse('contest_news', args=[page_info.contest.id]))
        form = ContestNewsEditForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            fid = data['fid']
            for rfile in request.POST:
                if rfile.startswith('rfile'):
                    message.content_files_delete(request.POST[rfile])
            for ufile in glob.glob(os.path.join(fid, '*')):
                message.content_files_set_blob_path(os.path.basename(ufile),
                                                    ufile)
            try:
                message.modify(
                    SubpageStruct(name=data['name'],
                                  content=data['content'],
                                  is_sticky=data['is_sticky'],
                                  is_public=data['is_public']))
                if not data['is_public']:
                    Privilege.revoke(Security.anonymous(), message, 'VIEW')
                    Privilege.grant(page_info.contest.contestant_role, message,
                                    'VIEW')
                else:
                    Privilege.revoke(page_info.contest.contestant_role,
                                     message, 'VIEW')
                    Privilege.grant(Security.anonymous(), message, 'VIEW')
            except SphinxException as sphinxException:
                attachments = valid_attachments(
                    message.content_files_get_list())
                form._errors['content'] = form.error_class([sphinxException])
                return render_to_response(
                    'news_edit.html', {
                        'attachments': attachments,
                        'fid': fid,
                        'form': form,
                        'message': message,
                        'page_info': page_info
                    })
            return HttpResponseRedirect(
                reverse('contest_news', args=[page_info.contest.id]))
    else:
        fid = mkdtemp()
        form = ContestNewsEditForm(
            initial={
                'name': message.name,
                'content': message.content,
                'fid': fid,
                'is_public': message.is_public,
                'is_sticky': message.is_sticky
            })
    attachments = valid_attachments(message.content_files_get_list())
    return render_to_response(
        'news_edit.html', {
            'attachments': attachments,
            'fid': fid,
            'form': form,
            'message': message,
            'page_info': page_info
        })
예제 #10
0
파일: problem.py 프로젝트: zielmicha/satori
def edit(request, page_info, id):
    mapping = ProblemMapping(int(id))
    problem = mapping.problem
    suites = TestSuite.filter(TestSuiteStruct(problem=problem))
    pdf_file = mapping.statement_files_get("pdf")
    if request.method == "POST":
        form = ProblemAddForm(data=request.POST,
                              files=request.FILES,
                              suites=suites)
        if form.is_valid():
            data = form.cleaned_data
            fid = data['fid']
            if 'delete' in request.POST.keys():
                try:
                    mapping.delete()
                except:
                    return HttpResponseRedirect(
                        reverse('contest_problems_edit',
                                args=[page_info.contest.id, id]))
                return HttpResponseRedirect(
                    reverse('contest_problems', args=[page_info.contest.id]))
            if 'remove_pdf' in request.POST.keys():
                mapping.statement_files_delete('pdf')
                return HttpResponseRedirect(
                    reverse('contest_problems_edit',
                            args=[page_info.contest.id, id]))
            for rfile in request.POST:
                if rfile.startswith('rfile'):
                    mapping.statement_files_delete(request.POST[rfile])
            for ufile in glob.glob(os.path.join(fid, '*')):
                mapping.statement_files_set_blob_path(os.path.basename(ufile),
                                                      ufile)
            pdf = form.cleaned_data.get('pdf', None)
            if pdf:
                writer = Blob.create(pdf.size)
                writer.write(pdf.read())
                phash = writer.close()
                mapping.statement_files_set_blob_hash('pdf', phash)

            try:

                mapping.modify(
                    ProblemMappingStruct(code=data['code'],
                                         title=data['title'],
                                         statement=data['statement'],
                                         group=data['group'],
                                         description=data['description'],
                                         default_test_suite=TestSuite(
                                             int(data['suite']))))
            except SphinxException as sphinxException:
                attachments = valid_attachments(
                    mapping.statement_files_get_list())
                form._errors['statement'] = form.error_class([sphinxException])
                return render_to_response(
                    'problems_add.html', {
                        'attachments': attachments,
                        'fid': fid,
                        'form': form,
                        'page_info': page_info,
                        'base': problem,
                        'editing': mapping
                    })
            if mapping.statement:
                return HttpResponseRedirect(
                    reverse('contest_problems_view',
                            args=[page_info.contest.id, id]))
            else:
                return HttpResponseRedirect(
                    reverse('contest_problems', args=[page_info.contest.id]))
    else:
        fid = mkdtemp()
        form = ProblemAddForm(initial={
            'code': mapping.code,
            'title': mapping.title,
            'statement': mapping.statement,
            'description': mapping.description,
            'group': mapping.group,
            'fid': fid,
            'suite': mapping.default_test_suite.id
        },
                              suites=suites)
    attachments = valid_attachments(mapping.statement_files_get_list())
    return render_to_response(
        'problems_add.html', {
            'attachments': attachments,
            'page_info': page_info,
            'fid': fid,
            'form': form,
            'base': problem,
            'pdf_file': pdf_file,
            'editing': mapping
        })