def seed(self, request, page_name=None, params=None, **kwargs): """Starts a seeding operation using the supplied JSON data. """ if request.is_ajax(): data = request.POST.get('data', None) if data: try: id = seeder_logic.seedFromJSON(data) except Error, ex: return responses.jsonErrorResponse(request, ex.args[0]) else: return responses.jsonErrorResponse(request, 'No data supplied!')
def getRolesListData(self, request): """Returns the list data for roles. """ user = user_logic.getForCurrentAccount() # only select the roles for the current user # pylint: disable-msg=E1103 fields = {'link_id': user.link_id, 'status': ['active', 'inactive']} keys = role_view.ROLE_VIEWS.keys() keys.sort() idx = request.GET.get('idx', '') idx = int(idx) if idx.isdigit() else -1 if not 0 <= idx < len(keys): return responses.jsonErrorResponse(request, "idx not valid") idx = int(idx) key = keys[idx] list_params = role_view.ROLE_VIEWS[key].getParams() contents = helper.lists.getListData(request, list_params, fields) json = simplejson.dumps(contents) return responses.jsonResponse(request, json)
def getWithdrawData(self, request, ap_params, wp_params, program_kwargs): """Return data for withdraw. """ program = program_logic.getFromKeyFieldsOr404(program_kwargs) fields = { 'program': program, } idx = request.GET.get('idx', '') idx = int(idx) if idx.isdigit() else -1 if idx == 0: fields['status'] = ['accepted', 'completed'] params = ap_params elif idx == 1: fields['status'] = ['withdrawn'] params = wp_params else: return responses.jsonErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields, 'public') json = simplejson.dumps(contents) return responses.jsonResponse(request, json)
def getListSelfData(self, request, uh_params, ar_params): """Returns the list data for getListSelf. """ idx = request.GET.get('idx', '') idx = int(idx) if idx.isdigit() else -1 # get the current user user_entity = user_logic.logic.getForCurrentAccount() # only select the Invites for this user that haven't been handled yet # pylint: disable-msg=E1103 filter = {'user': user_entity} if idx == 0: filter['status'] = 'group_accepted' params = uh_params elif idx == 1: filter['status'] = 'new' params = ar_params else: return responses.jsonErrorResponse(request, "idx not valid") contents = helper.lists.getListData(request, params, filter, 'public') json = simplejson.dumps(contents) return responses.jsonResponse(request, json)
def testProvider(self, request, page_name=None, params=None, **kwargs): """Tests a parameter configuration for a data provider and return a sample value or an error message as JSON data. """ if request.is_ajax(): json = request.POST.get('data', None) if json: try: data = simplejson.loads(json) except ValueError: return responses.jsonErrorResponse(request, 'Invalid JSON!') try: value = seeder_logic.testProvider(data) except Error, e: return responses.jsonErrorResponse(request, e.args[0]) else: return responses.jsonErrorResponse(request, 'No data supplied!')
def validateConfigurationSheet(self, request, page_name=None, params=None, **kwargs): """Tests a configuration sheet for validity and report any errors as JSON data. """ if request.is_ajax(): json = request.POST.get('data', None) if json: try: data = simplejson.loads(json) except ValueError: return responses.jsonErrorResponse(request, 'Invalid JSON!') try: seeder_logic.validateConfiguration(data) except Error, e: return responses.jsonErrorResponse(request, e.args[0]) else: return responses.jsonErrorResponse(request, 'No data supplied!')
def getErrorResponse(request, msg): """Returns an error appropriate for the request type. """ from soc.views.helper import responses if isJsonRequest(request): return responses.jsonErrorResponse(request, msg) raise Exception(msg)
def getManageOverviewData(self, request, mo_params, org_entity): """Returns the manageOverview data. """ args = [] fields = {} idx = request.GET.get('idx', '') idx = int(idx) if idx.isdigit() else -1 if idx == 0: from soc.modules.gsoc.logic.models.survey import grading_logic as \ grading_survey_logic from soc.modules.gsoc.logic.models.survey import project_logic as \ project_survey_logic from soc.modules.gsoc.logic.models.survey_record import grading_logic from soc.modules.gsoc.logic.models.survey_record import project_logic program_entity = org_entity.scope fields = {'scope_path': program_entity.key().id_or_name()} # count the number of have been active ProjectSurveys project_surveys = project_survey_logic.getForFields(fields) project_survey_count = len(project_surveys) for project_survey in project_surveys: if not project_survey_logic.hasRecord(project_survey): project_survey_count = project_survey_count - 1 # count the number of have been active GradingProjectSurveys grading_surveys = grading_survey_logic.getForFields(fields) grading_survey_count = len(grading_surveys) for grading_survey in grading_surveys: if not grading_survey_logic.hasRecord(grading_survey): grading_survey_count = grading_survey_count - 1 fields = {'scope': org_entity} params = mo_params args = [project_surveys, project_survey_count, grading_surveys, grading_survey_count] else: return responses.jsonErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields, 'public', args=args) json = simplejson.dumps(contents) return responses.jsonResponse(request, json)
def delete(self, request, access_type, page_name=None, params=None, **kwargs): """Shows the delete page for the entity specified by **kwargs. Args: request: the standard Django HTTP request object access_type : the name of the access type which should be checked page_name: the page name displayed in templates as page and header title params: a dict with params for this View kwargs: The Key Fields for the specified entity Params usage: rights: The rights dictionary is used to check if the user has the required rights to delete the specified entity. See checkAccess for more details on how the rights dictionary is used to check access rights. name: used in the same way as in edit(), see it's docstring for a more detailed explanation on how it is used. missing_redirect: see name error_edit: see name delete_redirect: The delete_redirect value is used as the url to redirect to after having successfully deleted the entity. """ logic = params['logic'] try: entity = logic.getFromKeyFieldsOr404(kwargs) except out_of_band.Error, error: error.message_fmt = ( error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { 'entity_type_lower': params['name'].lower(), 'entity_type': params['name'], 'create': params['missing_redirect'] }) return responses.jsonErrorResponse(request, "No such %s" % params['name'])
def getListRolesData(self, request, list_params, group_entity): """Returns the list data for listRoles. """ idx = request.GET.get('idx', '') idx = int(idx) if idx.isdigit() else -1 if not 0 <= idx < len(list_params): return responses.jsonErrorResponse(request, "idx not valid") # create the filter fields= { 'scope' : group_entity, 'status': 'active' } params = list_params[idx] contents = list_helper.getListData(request, params, fields) json = simplejson.dumps(contents) return responses.jsonResponse(request, json)
def getListSelfData(self, request, list_params, ip_params, scope_path): """Returns the listSelf data. """ student_entity = student_logic.logic.getFromKeyName(scope_path) fields = {'scope': student_entity} idx = request.GET.get('idx', '') idx = int(idx) if idx.isdigit() else -1 if idx == 0: fields['status'] = ['new', 'pending', 'accepted', 'rejected'] params = list_params elif idx == 1: fields['status'] = 'invalid' params = ip_params else: return responses.jsonErrorResponse(request, "idx not valid") contents = lists.getListData(request, params, fields, 'public') json = simplejson.dumps(contents) return responses.jsonResponse(request, json)
def list(self, request, access_type, page_name=None, params=None, filter=None, order=None, prefetch=None, visibility=None, context=None, **kwargs): """Displays the list page for the entity type. Args: request: the standard Django HTTP request object access_type : the name of the access type which should be checked page_name: the page name displayed in templates as page and header title params: a dict with params for this View filter: a dict for the properties that the entities should have prefetch: the fields of the data that should be pre-fetched Params usage: The params dictionary is passed as argument to getListContent in the soc.views.helper.list module. See the docstring for getListContent on how it uses it. The params dictionary is also passed as argument to the _list method. See the docstring for _list on how it uses it. """ get_args = request.GET fmt = get_args.get('fmt') idx = get_args.get('idx', '') if fmt == 'json': if not (idx.isdigit() and int(idx) == 0): return responses.jsonErrorResponse(request, "idx not valid") contents = helper.lists.getListData(request, params, filter, visibility) json = simplejson.dumps(contents) return responses.jsonResponse(request, json) content = helper.lists.getListGenerator(request, params, idx=0) contents = [content] return self._list(request, params, contents, page_name, context=context)
def delete(self, request, access_type, page_name=None, params=None, **kwargs): """Shows the delete page for the entity specified by **kwargs. Args: request: the standard Django HTTP request object access_type : the name of the access type which should be checked page_name: the page name displayed in templates as page and header title params: a dict with params for this View kwargs: The Key Fields for the specified entity Params usage: rights: The rights dictionary is used to check if the user has the required rights to delete the specified entity. See checkAccess for more details on how the rights dictionary is used to check access rights. name: used in the same way as in edit(), see it's docstring for a more detailed explanation on how it is used. missing_redirect: see name error_edit: see name delete_redirect: The delete_redirect value is used as the url to redirect to after having successfully deleted the entity. """ logic = params['logic'] try: entity = logic.getFromKeyFieldsOr404(kwargs) except out_of_band.Error, error: error.message_fmt = ( error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { 'entity_type_lower' : params['name'].lower(), 'entity_type' : params['name'], 'create' : params['missing_redirect']}) return responses.jsonErrorResponse( request, "No such %s" % params['name'])
error.message_fmt = ( error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { 'entity_type_lower' : params['name'].lower(), 'entity_type' : params['name'], 'create' : params['missing_redirect']}) return responses.jsonErrorResponse( request, "No such %s" % params['name']) if not logic.isDeletable(entity): page_params = params['cannot_delete_params'] params['suffix'] = entity.key().id_or_name() request.path = params['edit_redirect'] % params # redirect to the edit page # display notice that entity could not be deleted return responses.jsonErrorResponse( request, "That %s cannot be deleted" % params['name']) logic.delete(entity) redirect = params['delete_redirect'] data = simplejson.dumps(dict(new_location=redirect)) return helper.responses.jsonResponse(request, data) def select(self, request, view, redirect, page_name=None, params=None, filter=None): """Displays a list page allowing the user to select an entity. After having selected the Scope, the user is redirected to the 'create a new entity' page with the scope_path set appropriately.
error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { 'entity_type_lower': params['name'].lower(), 'entity_type': params['name'], 'create': params['missing_redirect'] }) return responses.jsonErrorResponse(request, "No such %s" % params['name']) if not logic.isDeletable(entity): page_params = params['cannot_delete_params'] params['suffix'] = entity.key().id_or_name() request.path = params['edit_redirect'] % params # redirect to the edit page # display notice that entity could not be deleted return responses.jsonErrorResponse( request, "That %s cannot be deleted" % params['name']) logic.delete(entity) redirect = params['delete_redirect'] data = simplejson.dumps(dict(new_location=redirect)) return helper.responses.jsonResponse(request, data) def select(self, request, view, redirect, page_name=None, params=None, filter=None):
def getListProposalsData(self, request, rp_params, mp_params, p_params, org_entity): """Returns the list data for listProposals. """ from soc.modules.gsoc.logic.models.ranker_root import logic \ as ranker_root_logic from soc.modules.gsoc.logic.models.student_proposal import logic \ as sp_logic from soc.modules.gsoc.models import student_proposal from soc.modules.gsoc.views.helper import list_info as list_info_helper from soc.modules.gsoc.views.models import student_proposal \ as student_proposal_view idx = request.GET.get('idx', '') idx = int(idx) if idx.isdigit() else -1 args = order = [] if idx == 0: # retrieve the ranker fields = { 'link_id': student_proposal.DEF_RANKER_NAME, 'scope': org_entity } ranker_root = ranker_root_logic.getForFields(fields, unique=True) ranker = ranker_root_logic.getRootFromEntity(ranker_root) keys = [] # only when the program allows allocations # to be seen we should color the list if org_entity.scope.allocations_visible: proposals = sp_logic.getProposalsToBeAcceptedForOrg(org_entity) keys = [i.key() for i in proposals] # show the amount of slots assigned on the webpage context['slots_visible'] = True # TODO(ljvderijk) once sorting with IN operator is fixed, # make this list show more filter = {'org': org_entity, 'status': 'pending'} params = rp_params # order by descending score order = ['-score'] args = [ranker, keys] elif idx == 1: # check if the current user is a mentor user_entity = user_logic.getForCurrentAccount() fields = { 'user': user_entity, 'scope': org_entity, } mentor_entity = mentor_logic.getForFields(fields, unique=True) filter = { 'org': org_entity, 'mentor': mentor_entity, 'status': 'pending' } params = mp_params elif idx == 2: filter = {'org': org_entity} params = p_params else: return responses.jsonErrorResponse(request, "idx not valid") contents = helper.lists.getListData(request, params, filter, 'public', order=order, args=args) json = simplejson.dumps(contents) return responses.jsonResponse(request, json)