Ejemplo n.º 1
0
def add(request):
    return render_to_response(
        'spacescout_admin/add.html',
        page_context(
            request,
            {'SPACE_FIELDS': SafeString(json.dumps(space_creation_fields()))}),
        context_instance=RequestContext(request))
Ejemplo n.º 2
0
    def POST(self, args, **kwargs):
        try:
            Permitted().can_create(self._request.user)
            schema = SpotSchema().get()
            space = Space(manager=self._request.user,
                          modified_by=self._request.user)
            spot = self._spacemap.pending_spot(space, schema)

            data = json.loads(self._request.read())

            fields, missing_fields = self._validate(spot, data)
            pending = {}
            for field in fields:
                if field == 'editors':
                    for username in fields[field].split(','):
                        editor = username.strip()
                        if len(editor):
                            space_editor = SpaceEditor(editor=username.strip(),
                                                       space=space)
                            space_editor.save()
                else:
                    pending[field] = fields[field]

            if len(missing_fields) > 0:
                space.is_complete = None
                pending['_missing_fields'] = missing_fields
            else:
                space.is_complete = True

            for field in space_creation_fields():
                if 'value' in field and 'key' in field['value']:
                    key = field['value']['key']
                    if 'required' in field and (key not in data
                                                or bool(data[key]) == False):
                        return self.error_response(400, "Bad Request")

            space.pending = json.dumps(pending) if len(pending) > 0 else None

            space.save()
            return self.json_response('{"id": "%s"}' % space.id)
        except PermittedException:
            return self.error_response(401, "Unauthorized")
Ejemplo n.º 3
0
    def POST(self, args, **kwargs):
        try:
            Permitted().can_create(self._request.user)
            schema = SpotSchema().get()
            space = Space(manager=self._request.user,
                          modified_by=self._request.user)
            spot = self._spacemap.pending_spot(space, schema)

            data = json.loads(self._request.read())

            fields, missing_fields = self._validate(spot, data)
            pending = {}
            for field in fields:
                if field == 'editors':
                    for username in fields[field].split(','):
                        editor = username.strip()
                        if len(editor):
                            space_editor = SpaceEditor(editor=username.strip(),space=space)
                            space_editor.save()
                else:
                    pending[field] = fields[field]

            if len(missing_fields) > 0:
                space.is_complete = None
                pending['_missing_fields'] = missing_fields
            else:
                space.is_complete = True

            for field in space_creation_fields():
                if 'value' in field and 'key' in field['value']:
                    key = field['value']['key']
                    if 'required' in field and (key not in data or bool(data[key]) == False):
                        return self.error_response(400, "Bad Request")

            space.pending = json.dumps(pending) if len(pending) > 0 else None


            space.save()
            return self.json_response('{"id": "%s"}' % space.id)
        except PermittedException:
            return self.error_response(401, "Unauthorized")
Ejemplo n.º 4
0
def add(request):
   return render_to_response('spacescout_admin/add.html',
                             page_context(request, {
                                 'SPACE_FIELDS' : SafeString(json.dumps(space_creation_fields()))
                             }),
                             context_instance=RequestContext(request))