Example #1
0
    def __setattr__(self, key, val):
        if key in self.user_fields:
            val = User.getUser(val, create=True)
        elif key in self.date_fields:
            val = self.getDateTime(val)

        # print "__setattr__ [%s] [%s] (%s)" % (key, val, type(val))
        return models.Model.__setattr__(self, key, val)
Example #2
0
    def __init__(self, *args, **kwargs):
        fields = [x.name for x in self._meta.fields]

        for f in self.user_fields:
            if f in kwargs and kwargs[f]:
                kwargs[f] = User.getUser(kwargs[f], create=True)

        for f in self.date_fields:
            if f in kwargs and kwargs[f]:
                kwargs[f] = self.getDateTime(kwargs[f])

        models.Model.__init__(self, *args, **kwargs)
Example #3
0
    def create(self, request):
        """
        Creates a resource with attributes given by POST, then
        redirects to the resource URI.

        Unlike the base Collection create() it does not require every
        since field to be specified.
        """
        data = self.receiver.get_post_data(request)
        print "ok here's the data: %s" % (data)

        new_model = self.queryset.model()
        print "ok just made new_model %s" % (new_model.__class__.__name__)

        self._pre_init(request, new_model, data)

        # seed with POST data
        for (key, val) in data.items():
            if new_model.__class__.__name__ == 'Note' and key == 'assigned_to' and val:
                val = User.getUser(val) 
            print "going to set [%s] with [%s]" % (key, val)
            new_model.__setattr__(key, val)

        # set created|modified by
        for key in ('created_by', 'modified_by'):
            if key in [f.name for f in new_model._meta.fields]:
                if key not in data:
                    print "NOT SET: going to set [%s] with [%s]" % (key, request.user)
                    new_model.__setattr__(key, request.user)

        print "now going to save"
        self._pre_save(request, new_model)

        # If the data contains no errors, save the model,
        # return a "201 Created" response with the model's
        # URI in the location header and a representation
        # of the model in the response body.
        new_model.save()

        model_entry = self.entry_class(self, new_model)
        response = model_entry.read(request)
        response.status_code = 201
        print "the model entry is: %s, type %s" % (model_entry, type(model_entry))
        response.headers['Location'] = model_entry.get_url()
        print "the location is: %s" % (response.headers['Location'])
        return response