本文整理汇总了Python中mig_main.utility.Permissions.can_process_project_reports方法的典型用法代码示例。如果您正苦于以下问题:Python Permissions.can_process_project_reports方法的具体用法?Python Permissions.can_process_project_reports怎么用?Python Permissions.can_process_project_reports使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig_main.utility.Permissions
的用法示例。
在下文中一共展示了Permissions.can_process_project_reports方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_permissions
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def get_permissions(user):
permission_dict={
'can_post':Permissions.can_post_web_article(user),
'can_edit':Permissions.can_approve_web_article(user),
'post_button':Permissions.can_upload_articles(user),
'is_member':hasattr(user,'userprofile') and user.userprofile.is_member(),
'can_process_project_reports': Permissions.can_process_project_reports(user),
}
return permission_dict
示例2: compile_project_reports
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def compile_project_reports(request, prh_id):
""" Runs the actual compilation of the project reports. Generates a pdf.
"""
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
prh = get_object_or_404(ProjectReportHeader, id=prh_id)
errors = prh.write_tex_files()
if errors:
error_message = 'The following reports had the following error codes:'
for error in errors:
error_message = (error_message + '\n' +
error['report'] + ': %d' % (error['error_code']))
request.session['error_message'] = unicode(errors)
return redirect('history:process_project_report_compilation')
示例3: process_project_reports
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def process_project_reports(request,prh_id,pr_id):
# double check permissions
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
pr_header = get_object_or_404(ProjectReportHeader,id=prh_id)
reports = pr_header.get_project_reports().order_by('target_audience','planning_start_date')
#
if int(pr_id) == 0:
# get started
pr=reports[0]
next_index = 1
else:
#process the current report
pr = get_object_or_404(ProjectReport,id=pr_id)
for index,item in enumerate(reports):
if item==pr:
next_index =index+1
break
if request.method=='POST':
form = ProjectDescriptionForm(request.POST)
if form.is_valid():
request.session['success_message'] = 'Descriptions updated'
pr.set_description(form.cleaned_data['description'])
if next_index< reports.count():
pr_header.last_processed=reports[next_index].id
pr_header.save()
return redirect('history:process_project_reports',pr_header.id,reports[next_index].id)
else:
pr_header.finished_processing=True
pr_header.save()
return redirect('history:process_project_report_compilation')
else:
request.session['error_message']='Submission Error(s). Please correct'
else:
form = ProjectDescriptionForm(initial={'description':pr.get_descriptions()})
template = loader.get_template('generic_form.html')
context_dict = {
'form':form,
'subnav':'project_reports',
'has_files':False,
'submit_name':'Confirm Project Description: '+pr.name,
'form_title':'Create Project Reports: Project Descriptions',
'help_text':'This is step 2 of 4. Please make updates to the project descriptions as necessary. A suggested description based on project leader submissions is pre-loaded below for:\nProject Name: %s\nTerm: %s\nCategory: %s\nPlanning Start: %s\nProject %d out of %d'%(pr.name,unicode(pr.term),pr.get_target_audience_display(),pr.planning_start_date,next_index,reports.count()),
'base':'history/base_history.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例4: process_project_report_compilation
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def process_project_report_compilation(request):
""" Starts or resumes the process of compiling project reports.
Basically the landing page for further action.
"""
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
current_term = AcademicTerm.get_current_term()
if current_term.semester_type.name == 'Summer':
# Likely the whole one
winter_term = current_term.get_previous_full_term()
fall_term = None
elif current_term.semester_type.name == 'Fall':
# either because summer term may be skipped to ease book keeping
winter_term = current_term.get_previous_full_term()
fall_term = current_term
else:
# could conceivably be either
winter_term = current_term
fall_term = current_term.get_previous_full_term()
pr_fall = None
pr_winter = None
if fall_term:
prs = ProjectReportHeader.objects.filter(terms=fall_term).distinct()
if prs.exists():
pr_fall = prs[0]
if winter_term:
prs = ProjectReportHeader.objects.filter(terms=winter_term).distinct()
if prs.exists():
pr_winter = prs[0]
template = loader.get_template(
'history/project_report_compilation_manager.html'
)
context_dict = {
'fall_term': fall_term,
'winter_term': winter_term,
'pr_fall': pr_fall,
'pr_winter': pr_winter,
'subnav': 'project_reports',
'base': 'history/base_history.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例5: start_project_report_compilation
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def start_project_report_compilation(request, term_id):
""" The page visited once the button is clicked to start compiling
the reports.
"""
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
term = get_object_or_404(AcademicTerm, id=term_id)
ProjectForm = modelform_factory(
ProjectReportHeader,
form=BaseProjectReportHeaderForm
)
prs = ProjectReportHeader.objects.filter(terms=term).distinct()
if prs.exists():
pr = prs[0]
else:
pr = ProjectReportHeader()
form = ProjectForm(request.POST or None, instance=pr)
if request.method == 'POST':
if form.is_valid():
instance = form.save()
request.session['success_message'] = ('Project report metadata/'
'header created/updated')
return redirect('history:process_project_report_compilation')
else:
request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
template = loader.get_template('generic_form.html')
context_dict = {
'form': form,
'subnav': 'project_reports',
'has_files': False,
'submit_name': 'Confirm Meta Data',
'form_title': 'Create Project Reports',
'help_text': ('This will begin the process of assembling the '
'project reports.'),
'base': 'history/base_history.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例6: start_project_report_compilation
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def start_project_report_compilation(request,term_id):
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
term = get_object_or_404(AcademicTerm,id=term_id)
ProjectForm =modelform_factory(ProjectReportHeader,form=BaseProjectReportHeaderForm)
pr = ProjectReportHeader.objects.filter(terms=term).distinct()
if request.method=='POST':
if pr.exists():
form = ProjectForm(request.POST,instance=pr.all()[0])
else:
form = ProjectForm(request.POST)
if form.is_valid():
instance=form.save()
request.session['success_message'] = 'Project report metadata/header created/updates'
return redirect('history:process_project_report_compilation')
else:
request.session['error_message']='There were errors in your submission. Please correct'
else:
if pr.exists():
form = ProjectForm(instance=pr.all()[0])
else:
form = ProjectForm()
template = loader.get_template('generic_form.html')
context_dict = {
'form':form,
'subnav':'project_reports',
'has_files':False,
'submit_name':'Confirm Meta Data',
'form_title':'Create Project Reports',
'help_text':'This will begin the process of assembling the project reports.',
'base':'history/base_history.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例7: process_project_report_photos
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def process_project_report_photos(request, prh_id, pr_id):
""" Processing the project report photos given by pr_id.
If pr_id is zero then this starts at the beginning (a very fine place
to start). This pulls all the photos for events associated with the
project report (or the report itself) and has the user select which ones
to ultimately include in the report.
"""
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
pr_header = get_object_or_404(ProjectReportHeader, id=prh_id)
reports = pr_header.get_project_reports().order_by(
'target_audience',
'planning_start_date',
'id',
)
if int(pr_id) == 0:
# get started
pr = reports[0]
next_index = 1
else:
# process the current report
pr = get_object_or_404(ProjectReport, id=pr_id)
for index, item in enumerate(reports):
if item == pr:
next_index = index+1
break
photo_query = EventPhoto.objects.filter(
(Q(event__project_report=pr) & Q(project_report=None)) |
Q(project_report=pr)
)
needs_redirect = False
# some reports will not have photos. If they do not, skip to the next
# one that does
while not photo_query.exists():
needs_redirect = True
if next_index < reports.count():
pr = reports[next_index]
next_index += 1
photo_query = EventPhoto.objects.filter(
(Q(event__project_report=pr) & Q(project_report=None)) |
Q(project_report=pr)
)
else:
# if there are no more reports, move on to the next thing
pr_header.finished_photos = True
pr_header.save()
return redirect('history:process_project_report_compilation')
if needs_redirect:
# jump to the next report which has photos
pr_header.last_photo = pr.id
pr_header.save()
return redirect('history:process_project_report_photos',
pr_header.id,
pr.id)
formset = ProjectPhotoFormset(
request.POST or None,
request.FILES or None,
queryset=photo_query
)
if request.method == 'POST':
if formset.is_valid():
formset.save()
request.session['success_message'] = 'Photos updated'
if next_index < reports.count():
pr_header.last_photo = reports[next_index].id
pr_header.save()
return redirect('history:process_project_report_photos',
pr_header.id,
reports[next_index].id)
else:
pr_header.finished_photos = True
pr_header.save()
return redirect('history:process_project_report_compilation')
else:
request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
template = loader.get_template('generic_formset.html')
help_text = ('This is step 3 of 4. Please make updates to the project '
'descriptions as necessary. A suggested description based on '
'project leader submissions is pre-loaded below '
'for:\nProject Name: %s\nTerm: %s\nCategory: %s\nPlanning '
'Start: %s\nProject %d out of %d') % (
pr.name,
unicode(pr.term),
pr.get_target_audience_display(),
pr.planning_start_date,
next_index,
reports.count()
)
context_dict = {
'formset': formset,
'subnav': 'project_reports',
'has_files': True,
'submit_name': 'Confirm Photos: ' + pr.name,
'can_add': True,
'form_title': 'Create Project Reports: Project Photos',
'help_text': help_text,
#.........这里部分代码省略.........
示例8: process_project_reports
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def process_project_reports(request, prh_id, pr_id):
""" Processing the project report given by pr_id.
If pr_id is zero then this starts at the beginning (a very fine place
to start). This pulls all the descriptions for events or non-even-projects
associated with the project report and has the user consolidate them into
one.
"""
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
pr_header = get_object_or_404(ProjectReportHeader, id=prh_id)
reports = pr_header.get_project_reports().order_by(
'target_audience',
'planning_start_date',
'id',
)
if int(pr_id) == 0:
# get started
pr = reports[0]
next_index = 1
else:
# process the current report
pr = get_object_or_404(ProjectReport, id=pr_id)
for index, item in enumerate(reports):
# Do not move this; next_index is
# needed by the help text
if item == pr:
next_index = index+1
break
form = ProjectDescriptionForm(
request.POST or None,
initial={'description': pr.get_descriptions()},
)
if request.method == 'POST':
if form.is_valid():
request.session['success_message'] = 'Descriptions updated'
pr.set_description(form.cleaned_data['description'])
# determine which report would be the next one to process
# (for redirection sake)
if next_index < reports.count():
pr_header.last_processed = reports[next_index].id
pr_header.save()
return redirect('history:process_project_reports',
pr_header.id,
reports[next_index].id)
else:
pr_header.finished_processing = True
pr_header.save()
return redirect('history:process_project_report_compilation')
else:
request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
template = loader.get_template('generic_form.html')
help_text = ('This is step 2 of 4. Please make updates to the '
'project descriptions as necessary. A suggested '
'description based on project leader submissions is '
'pre-loaded below for:\nProject Name: %s\nTerm: '
'%s\nCategory: %s\nPlanning Start: %s\nProject %d out '
'of %d') % (pr.name,
unicode(pr.term),
pr.get_target_audience_display(),
pr.planning_start_date,
next_index,
reports.count())
context_dict = {
'form': form,
'subnav': 'project_reports',
'has_files': False,
'submit_name': 'Confirm Project Description: '+pr.name,
'form_title': 'Create Project Reports: Project Descriptions',
'help_text': help_text,
'base': 'history/base_history.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
return HttpResponse(template.render(context_dict, request))
示例9: compile_project_reports
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def compile_project_reports(request,prh_id):
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
prh = get_object_or_404(ProjectReportHeader,id=prh_id)
prh.write_tex_files()
return redirect('history:process_project_report_compilation')
示例10: process_project_report_photos
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_process_project_reports [as 别名]
def process_project_report_photos(request,prh_id,pr_id):
# double check permissions
if not Permissions.can_process_project_reports(request.user):
raise PermissionDenied()
pr_header = get_object_or_404(ProjectReportHeader,id=prh_id)
reports = pr_header.get_project_reports().order_by('target_audience','planning_start_date')
#
if int(pr_id) == 0:
# get started
pr=reports[0]
next_index = 1
else:
#process the current report
pr = get_object_or_404(ProjectReport,id=pr_id)
for index,item in enumerate(reports):
if item==pr:
next_index =index+1
break
photo_query = EventPhoto.objects.filter((Q(event__project_report = pr)&Q(project_report=None))|Q(project_report=pr))
needs_redirect = False
while not photo_query.exists():
needs_redirect=True
if next_index< reports.count():
pr = reports[next_index]
next_index +=1
photo_query = EventPhoto.objects.filter((Q(event__project_report = pr)&Q(project_report=None))|Q(project_report=pr))
else:
pr_header.finished_photos=True
pr_header.save()
return redirect('history:process_project_report_compilation')
if needs_redirect:
pr_header.last_photo=pr.id
pr_header.save()
return redirect('history:process_project_report_photos',pr_header.id,pr.id)
if request.method=='POST':
formset = ProjectPhotoFormset(request.POST,request.FILES,queryset=photo_query)
if formset.is_valid():
formset.save()
request.session['success_message'] = 'Photos updated'
if next_index< reports.count():
pr_header.last_photo=reports[next_index].id
pr_header.save()
return redirect('history:process_project_report_photos',pr_header.id,reports[next_index].id)
else:
pr_header.finished_photos=True
pr_header.save()
return redirect('history:process_project_report_compilation')
else:
request.session['error_message']='Submission Error(s). Please correct'
else:
formset = ProjectPhotoFormset(queryset=photo_query)
template = loader.get_template('generic_formset.html')
context_dict = {
'formset':formset,
'subnav':'project_reports',
'has_files':True,
'submit_name':'Confirm Photos: '+pr.name,
'can_add':True,
'form_title':'Create Project Reports: Project Photos',
'help_text':'This is step 3 of 4. Please make updates to the project descriptions as necessary. A suggested description based on project leader submissions is pre-loaded below for:\nProject Name: %s\nTerm: %s\nCategory: %s\nPlanning Start: %s\nProject %d out of %d'%(pr.name,unicode(pr.term),pr.get_target_audience_display(),pr.planning_start_date,next_index,reports.count()),
'base':'history/base_history.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))