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 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 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 submitFormsGet(self, request, params, template, context, entity): if lists.isJsonRequest(request): url = blobstore.create_upload_url(gci_redirects.getSubmitFormsRedirect(entity, params)) return responses.jsonResponse(request, url) def setForm(param_name, blob_info): add_form, edit_form = params[param_name] if blob_info: form = edit_form( initial={ "name": '<a href="%(url)s">%(name)s</a>' % { "name": blob_info.filename, "url": redirects.getDownloadBlobRedirectWithGet( blob_info, params, scope_path=entity.key().id_or_name(), type=param_name ), }, "size": defaultfilters.filesizeformat(blob_info.size), "uploaded": blob_info.creation.strftime(self.DATETIME_FORMAT), } ) else: form = add_form() context[param_name] = form setForm("consent_form_upload_form", entity.consent_form) setForm("consent_form_two_upload_form", entity.consent_form_two) setForm("student_id_form_upload_form", entity.student_id_form) return responses.respond(request, template, context)
def getData(self, request, page_name=None, params=None): """Returns a JSON object containing information regarding models, properties and supported data providers. """ contents = {} contents['models'] = seeder_models_logic.getModelsData() contents['providers'] = seeder_providers_logic.getProvidersData() # TODO(sttwister): Remove the indent on deployment json = simplejson.dumps(contents, indent=2) return responses.jsonResponse(request, json)
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 json(self, request, data, to_json=True): """Returns data as a json object. Args: request: the standard Django HTTP request object data: the data to be sent as a json object to_json: determines if the data should be converted to a json object """ if to_json: json = simplejson.dumps({'data': data}) else: json = data return responses.jsonResponse(request, json)
def getResponse(request, contents): """Returns a response appropriate for the request type. """ from soc.views.helper import responses if isJsonRequest(request): json = simplejson.dumps(contents) return responses.jsonResponse(request, json) if isNonEmptyRequest(request): return contents # TODO(SRabbelier): this is probably the best way to handle this return contents
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 submitFormsGet(self, request, params, template, context, entity): if lists.isJsonRequest(request): url = blobstore.create_upload_url( gci_redirects.getSubmitFormsRedirect(entity, params)) return responses.jsonResponse(request, url) def setForm(param_name, blob_info): add_form, edit_form = params[param_name] if blob_info: form = edit_form( initial={ 'name': '<a href="%(url)s">%(name)s</a>' % { 'name': blob_info.filename, 'url': redirects.getDownloadBlobRedirectWithGet( blob_info, params, scope_path=entity.key().id_or_name(), type=param_name) }, 'size': defaultfilters.filesizeformat(blob_info.size), 'uploaded': blob_info.creation.strftime(self.DATETIME_FORMAT), }) else: form = add_form() context[param_name] = form setForm('consent_form_upload_form', entity.consent_form) setForm('consent_form_two_upload_form', entity.consent_form_two) setForm('student_id_form_upload_form', entity.student_id_form) return responses.respond(request, template, context)
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 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)
""" 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!') else: return HttpResponseForbidden() response = simplejson.dumps({'result': 'success', 'id': id}) return responses.jsonResponse(request, response) @view_decorators.merge_params def echo(self, request, page_name=None, params=None, **kwargs): """Echoes the JSON configuration sheet back to the browser. """ json = request.POST.get('data', None) if json: try: data = simplejson.loads(json) except ValueError: return HttpResponse('Invalid JSON!') response = HttpResponse(json, mimetype='application/json') response[ 'Content-Disposition'] = 'attachment; filename=configuration.json'
"""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!') else: return HttpResponseForbidden() response = simplejson.dumps({'result': 'success', 'id': id}) return responses.jsonResponse(request, response) @view_decorators.merge_params def echo(self, request, page_name=None, params=None, **kwargs): """Echoes the JSON configuration sheet back to the browser. """ json = request.POST.get('data', None) if json: try: data = simplejson.loads(json) except ValueError: return HttpResponse('Invalid JSON!') response = HttpResponse(json, mimetype='application/json') response['Content-Disposition'] = 'attachment; filename=configuration.json' return response