예제 #1
0
    def POST(self, request):
        json = uni2str(request.data.copy())

        if not any([x in json for x in ('type', 'operator')]):
            return http.BAD_REQUEST, 'Invalid data format'

        text = logictree.transform(json).text

        j = ''
        if text.has_key('type'):
            j = ' %s ' % text['type']

        return j.join(text['conditions'])
예제 #2
0
    def PUT(self, request, pk):
        """
        If the session's current ``perspective`` is not temporary, it will be
        copied and store off temporarily.
        """
        # if the request is relative to the session and not to a specific id,
        # it cannot be assumed that if the session is using a saved scope
        # for it, iself, to be updated, but rather the session representation.
        # therefore, if the session scope is not temporary, make it a
        # temporary object with the new parameters.
        obj = request.session['report'].perspective

        json = uni2str(request.data)

        # see if the json object is only the ``store``
        if json.has_key('columns') or json.has_key('ordering'):
            json = {'store': json}

        # assume the PUT request is only the store
        if pk != 'session':
            if pk != obj.id:
                obj = self.get(request, pk=pk)
                if not obj:
                    return http.NOT_FOUND

        store = json.pop('store', None)

        if store is not None:
            # TODO improve this method of adding a partial condition tree
            if not obj.is_valid(store):
                return http.BAD_REQUEST
            if not obj.has_permission(store, request.user):
                return http.UNAUTHORIZED

            partial = store.pop('partial', False)
            obj.write(store, partial=partial)

        for k, v in json.iteritems():
            setattr(obj, k, v)

        # only save existing objances that have been saved.
        # a POST is required to make the initial save
        if obj.id is not None:
            obj.save()

        request.session.modified = True

        return ''