def _editRecordGet(self, request, params, context, template, record_entity): """Handles the GET request for editing a GradingRecord. Args: request: a Django Request object params: the params for this view context: the context for the webpage template: the location of the template used for this view record_entity: a GradingRecord entity """ survey_group_logic = params['logic'] record_logic = survey_group_logic.getRecordLogic() get_dict = request.GET if get_dict.get('update'): # try to update this record properties = record_logic.getFieldsForGradingRecord( record_entity.project, record_entity.grading_survey_group, record_entity) record_logic.updateEntityProperties(record_entity, properties) form = params['record_edit_form'](instance=record_entity) context['form'] = form return responses.respond(request, template, context)
def _editRecordGet(self, request, params, context, template, record_entity): """Handles the GET request for editing a GradingRecord. Args: request: a Django Request object params: the params for this view context: the context for the webpage template: the location of the template used for this view record_entity: a GradingRecord entity """ survey_group_logic = params['logic'] record_logic = survey_group_logic.getRecordLogic() get_dict = request.GET if get_dict.get('update'): # try to update this record properties = record_logic.getFieldsForGradingRecord( record_entity.project, record_entity.grading_survey_group, record_entity) record_logic.updateEntityProperties(record_entity, properties) form = params['record_edit_form'](instance=record_entity) context['form'] = form return responses.respond(request, template, context)
def editRecord(self, request, access_type, page_name=None, params=None, **kwargs): """View in which a GradingRecord can be edited. For args see base.View.public(). """ survey_group_logic = params['logic'] record_logic = survey_group_logic.getRecordLogic() get_dict = request.GET record_id = get_dict.get('id') if not (record_id and record_id.isdigit()): # no valid record_id specified showing the list of GradingRecords return self._showEditRecordList(request, params, page_name, **kwargs) # retrieve the wanted GradingRecord try: record_entity = record_logic.getFromIDOr404(int(record_id)) except out_of_band.Error, error: return responses.errorResponse(error, request, template=params['error_public'])
def _showEditRecordList(self, request, params, page_name, **kwargs): """Returns a list containing GradingRecords that can be edited. For args see base.View.public(). """ survey_group_logic = params['logic'] record_logic = survey_group_logic.getRecordLogic() try: survey_group = survey_group_logic.getFromKeyFieldsOr404(kwargs) except out_of_band.Error, error: return responses.errorResponse( error, request, template=params['error_public'])
def _showEditRecordList(self, request, params, page_name, **kwargs): """Returns a list containing GradingRecords that can be edited. For args see base.View.public(). """ survey_group_logic = params['logic'] record_logic = survey_group_logic.getRecordLogic() try: survey_group = survey_group_logic.getFromKeyFieldsOr404(kwargs) except out_of_band.Error, error: return responses.errorResponse(error, request, template=params['error_public'])
def viewRecords(self, request, access_type, page_name=None, params=None, **kwargs): """View which shows all collected records for a given GradingSurveyGroup. For args see base.View.public(). """ from google.appengine.api import taskqueue from soc.logic import lists as lists_logic survey_group_logic = params['logic'] record_logic = survey_group_logic.getRecordLogic() try: entity = survey_group_logic.getFromKeyFieldsOr404(kwargs) except out_of_band.Error, error: return responses.errorResponse( error, request, template=params['error_public'])
def editRecord(self, request, access_type, page_name=None, params=None, **kwargs): """View in which a GradingRecord can be edited. For args see base.View.public(). """ survey_group_logic = params['logic'] record_logic = survey_group_logic.getRecordLogic() get_dict = request.GET record_id = get_dict.get('id') if not (record_id and record_id.isdigit()): # no valid record_id specified showing the list of GradingRecords return self._showEditRecordList(request, params, page_name, **kwargs) # retrieve the wanted GradingRecord try: record_entity = record_logic.getFromIDOr404(int(record_id)) except out_of_band.Error, error: return responses.errorResponse( error, request, template=params['error_public'])
def viewRecords(self, request, access_type, page_name=None, params=None, **kwargs): """View which shows all collected records for a given GradingSurveyGroup. For args see base.View.public(). """ from google.appengine.api.labs import taskqueue from soc.logic import lists as lists_logic survey_group_logic = params['logic'] record_logic = survey_group_logic.getRecordLogic() try: entity = survey_group_logic.getFromKeyFieldsOr404(kwargs) except out_of_band.Error, error: return responses.errorResponse(error, request, template=params['error_public'])
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.GSoCChecker(params) rights['create'] = [('checkIsHostForProgramInScope', program_logic)] rights['edit'] = [('checkIsHostForProgramInScope', program_logic)] rights['delete'] = ['checkIsDeveloper'] rights['show'] = [('checkIsHostForProgramInScope', program_logic)] rights['list'] = [('checkIsHostForProgramInScope', program_logic)] rights['records'] = [('checkIsHostForProgramInScope', program_logic)] rights['edit_record'] = [('checkIsHostForProgramInScope', program_logic)] new_params = {} new_params['logic'] = survey_group_logic new_params['rights'] = rights new_params['name'] = "Grading Survey Group" new_params['url_name'] = 'gsoc/grading_survey_group' new_params['module_package'] = 'soc.modules.gsoc.views.models' new_params['sidebar_grouping'] = "Surveys" new_params['scope_view'] = program_view new_params['scope_redirect'] = redirects.getCreateRedirect new_params['no_admin'] = True new_params['no_create_with_key_fields'] = True new_params['create_extra_dynaproperties'] = { 'grading_survey': djangoforms.ModelChoiceField( GradingProjectSurvey, required=True), 'student_survey': djangoforms.ModelChoiceField(ProjectSurvey, required=False), } new_params['extra_dynaexclude'] = ['link_id', 'scope', 'scope_path', 'last_update_started', 'last_update_complete'] new_params['edit_extra_dynaproperties'] = { 'link_id': forms.CharField(widget=forms.HiddenInput), } # remove the raw list and add the one without the link_id new_params['no_list_raw'] = True new_params['sans_link_id_list'] = True # redefine the developer sidebar so that the list_raw is not shown new_params['sidebar_developer'] = [ # TODO(SRabbelier): remove create once new list code is in ('/%s/create', 'New %(name)s', 'create') ] patterns = [ (r'^%(url_name)s/(?P<access_type>records)/%(key_fields)s$', '%(module_package)s.%(module_name)s.view_records', 'Overview of GradingRecords'), (r'^%(url_name)s/(?P<access_type>edit_record)/%(key_fields)s$', '%(module_package)s.%(module_name)s.edit_record', 'Edit a GradingRecord'), ] new_params['extra_django_patterns'] = patterns new_params['edit_template'] = 'soc/grading_survey_group/edit.html' new_params['view_records_template'] = 'soc/grading_survey_group/records.html' new_params['record_edit_template'] = 'soc/grading_record/edit.html' # create the form that will be used to edit a GradingRecord record_logic = survey_group_logic.getRecordLogic() record_edit_form = dynaform.newDynaForm( dynabase=soc.views.helper.forms.BaseForm, dynamodel=record_logic.getModel(), dynaexclude=['grading_survey_group', 'mentor_record', 'student_record', 'project'], ) new_params['record_edit_form'] = record_edit_form new_params['public_field_keys'] = ["name", "last_update_started", "last_update_completed"] new_params['public_field_names'] = ["Name", "Last update started", "Last update completed"] new_params['records_field_prefetch'] = [ 'project', 'mentor_record', 'student_record', # TODO(SRabbelier): Enable when we support multi-level prefetching # 'project.student', 'project.scope', 'project.mentor', ] new_params['records_field_extra'] = lambda entity: { "project_title": entity.project.title, "student_name": entity.project.student.link_id, "student_email": entity.project.student.email, "organization": entity.project.scope.name, "mentor_name": entity.project.mentor.link_id, "mentor_email": entity.project.mentor.email, "final_grade": entity.grade_decision.capitalize(), "mentor_grade": ("Pass" if entity.mentor_record.grade else "Fail") if entity.mentor_record else "Not Available", "student_eval": "Yes" if entity.student_record else "Not Available", } new_params['records_field_keys'] = [ "project_title", "student_name", "student_email", "organization", "mentor_name", "mentor_email", "final_grade", "mentor_grade", "student_eval", "locked", "grade_decision", ] new_params['records_field_names'] = [ "Project Name", "Student link_id", "Student email", "Organization", "Mentor link_id", "Mentor email", "Final Grade", "Mentor Grade", "Student Eval", "Locked", "Grade", ] new_params['records_row_extra'] = lambda entity: { "link": redirects.getEditRedirect(entity, params), } params = dicts.merge(params, new_params) super(View, self).__init__(params=params)
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.GSoCChecker(params) rights['create'] = [('checkIsHostForProgramInScope', program_logic)] rights['edit'] = [('checkIsHostForProgramInScope', program_logic)] rights['delete'] = ['checkIsDeveloper'] rights['show'] = [('checkIsHostForProgramInScope', program_logic)] rights['list'] = ['checkIsDeveloper'] rights['records'] = [('checkIsHostForProgramInScope', program_logic)] rights['edit_record'] = [('checkIsHostForProgramInScope', program_logic)] new_params = {} new_params['logic'] = survey_group_logic new_params['rights'] = rights new_params['name'] = "Grading Survey Group" new_params['url_name'] = 'gsoc/grading_survey_group' new_params['module_package'] = 'soc.modules.gsoc.views.models' new_params['sidebar_grouping'] = "Surveys" new_params['scope_view'] = program_view new_params['scope_redirect'] = redirects.getCreateRedirect new_params['no_admin'] = True new_params['no_create_with_key_fields'] = True new_params['create_extra_dynaproperties'] = { 'grading_survey': djangoforms.ModelChoiceField(GradingProjectSurvey, required=True), 'student_survey': djangoforms.ModelChoiceField(ProjectSurvey, required=False), } new_params['extra_dynaexclude'] = [ 'link_id', 'scope', 'scope_path', 'last_update_started', 'last_update_complete' ] new_params['edit_extra_dynaproperties'] = { 'link_id': forms.CharField(widget=forms.HiddenInput), } patterns = [ (r'^%(url_name)s/(?P<access_type>records)/%(key_fields)s$', '%(module_package)s.%(module_name)s.view_records', 'Overview of GradingRecords'), (r'^%(url_name)s/(?P<access_type>edit_record)/%(key_fields)s$', '%(module_package)s.%(module_name)s.edit_record', 'Edit a GradingRecord'), ] new_params['extra_django_patterns'] = patterns new_params[ 'view_records_template'] = 'soc/grading_survey_group/records.html' new_params[ 'records_heading_template'] = 'soc/grading_record/list/heading.html' new_params['records_row_template'] = 'soc/grading_record/list/row.html' new_params['record_edit_template'] = 'soc/grading_record/edit.html' # create the form that will be used to edit a GradingRecord record_logic = survey_group_logic.getRecordLogic() record_edit_form = dynaform.newDynaForm( dynabase=soc.views.helper.forms.BaseForm, dynamodel=record_logic.getModel(), dynaexclude=[ 'grading_survey_group', 'mentor_record', 'student_record', 'project' ], ) new_params['record_edit_form'] = record_edit_form new_params['public_field_keys'] = [ "name", "last_update_started", "last_update_completed" ] new_params['public_field_names'] = [ "Name", "Last update started", "Last update completed" ] new_params['records_field_extra'] = lambda entity: { "project_title": entity.project.title, "student_name": "%s (%s)" % (entity.project.student.name, entity.project.student.link_id), "organization": entity.project.name, "mentor_name": "%s (%s)" % (entity.project.mentor.name, entity.project.mentor.link_id), "final_grade": entity.grade_decision.capitalize(), "mentor_grade": ("Pass" if entity.mentor_record.grade else "Fail") if entity.mentor_record else "Not Available", "student_eval": "Yes" if entity.student_record else "Not Available", } new_params['records_field_keys'] = [ "project_title", "student_name", "organization", "mentor_name", "final_grade", "mentor_grade", "student_eval", "locked" ] new_params['records_field_names'] = [ "Project Name", "Student (link id)", "Organization", "Mentor (link id)", "Final Grade", "Mentor Grade", "Student Eval", "Locked" ] params = dicts.merge(params, new_params) super(View, self).__init__(params=params)