Ejemplo n.º 1
0
def duplicate(request, profile_uuid):
    """ Handles POST requests to duplicate an existing profile """
    try:
        inp_prof = InputProfile.objects.get(uuid=profile_uuid)
        project_uuid = inp_prof.project_uuid
    except InputProfile.DoesNotExist:
        inp_prof = False
        project_uuid = False
        raise Http404
    proj_inp = ProjectInputs(project_uuid, request)
    if proj_inp.manifest is not False:
        if request.method == 'POST':
            if proj_inp.edit_permitted or request.user.is_superuser:
                m_inp_prof = ManageInputProfile()
                m_inp_prof.creator_uuid = str(request.user.id)
                m_inp_prof.project_uuid = project_uuid
                result = m_inp_prof.duplicate(request.POST,
                                              profile_uuid)
                result['errors'] = m_inp_prof.errors
                json_output = json.dumps(result,
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8')
            else:
                json_output = json.dumps({'error': 'edit permission required'},
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8',
                                    status=401)
        else:
            return HttpResponseForbidden
    else:
        raise Http404
Ejemplo n.º 2
0
def duplicate(request, profile_uuid):
    """ Handles POST requests to duplicate an existing profile """
    try:
        inp_prof = InputProfile.objects.get(uuid=profile_uuid)
        project_uuid = inp_prof.project_uuid
    except InputProfile.DoesNotExist:
        inp_prof = False
        project_uuid = False
        raise Http404
    proj_inp = ProjectInputs(project_uuid, request)
    if proj_inp.manifest is not False:
        if request.method == 'POST':
            if proj_inp.edit_permitted or request.user.is_superuser:
                m_inp_prof = ManageInputProfile()
                m_inp_prof.creator_uuid = str(request.user.id)
                m_inp_prof.project_uuid = project_uuid
                result = m_inp_prof.duplicate(request.POST, profile_uuid)
                result['errors'] = m_inp_prof.errors
                json_output = json.dumps(result, indent=4, ensure_ascii=False)
                return HttpResponse(
                    json_output, content_type='application/json; charset=utf8')
            else:
                json_output = json.dumps({'error': 'edit permission required'},
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(
                    json_output,
                    content_type='application/json; charset=utf8',
                    status=401)
        else:
            return HttpResponseForbidden
    else:
        raise Http404
Ejemplo n.º 3
0
 def make_json(self, uuid):
     """ makes JSON for the profile item """
     ok = self.check_exists(uuid)
     if ok:
         # makes mandatory fields if they don't exist
         mip = ManageInputProfile()
         mip.make_mandatory_fields(self.project_uuid, self.inp_prof.uuid,
                                   self.inp_prof.item_type)
         profile = LastUpdatedOrderedDict()
         profile['id'] = self.uuid
         profile['label'] = self.inp_prof.label
         profile['note'] = self.inp_prof.note
         profile['updated'] = self.inp_prof.updated.date().isoformat()
         profile['item_type'] = self.inp_prof.item_type
         profile['project'] = LastUpdatedOrderedDict()
         profile['project']['uuid'] = self.project.uuid
         profile['project']['label'] = self.project.label
         profile['fgroups'] = self.get_field_groups_and_fields()
     else:
         profile = False
     return profile
Ejemplo n.º 4
0
 def make_json(self, uuid):
     """ makes JSON for the profile item """
     ok = self.check_exists(uuid)
     if ok:
         # makes mandatory fields if they don't exist
         mip = ManageInputProfile()
         mip.make_mandatory_fields(self.project_uuid,
                                   self.inp_prof.uuid,
                                   self.inp_prof.item_type)
         profile = LastUpdatedOrderedDict()
         profile['id'] = self.uuid
         profile['label'] = self.inp_prof.label
         profile['note'] = self.inp_prof.note
         profile['updated'] = self.inp_prof.updated.date().isoformat()
         profile['item_type'] = self.inp_prof.item_type
         profile['project'] = LastUpdatedOrderedDict()
         profile['project']['uuid'] = self.project.uuid
         profile['project']['label'] = self.project.label
         profile['fgroups'] = self.get_field_groups_and_fields()
     else:
         profile = False
     return profile