tastypie

Django + Tastypie - user_logged_in signal doesn't work

五迷三道 提交于 2019-12-08 04:03:52
问题 I have a Tastypie ModelResource defining various endpoints which work as expected. I've now configured this ModelResource to have BasicAuthentication : class Meta: authentication = BasicAuthentication() I've defined a couple of test users through the Django Admin Interface. As per the Django 1.7 Documentation, I've created a signals.py in which I register a couple of test signals: from django.core.signals import request_finished from django.contrib.auth.signals import user_logged_in from

How I acces to Backbone collection elements from Tastypie JSON?

廉价感情. 提交于 2019-12-08 02:23:58
问题 I've write a API with Tastypie-Django and I want to do a webpage using Backbone to do more simply access to model. I've created a Model and a collection like this in Backbone: var Abstract = Backbone.Model.extend({ defaults : { } }); var AbstractCollection = Backbone.Collection.extend({ model: Abstract, url : "http://192.168.0.195/api/v1/abstract/?format=json" }); The fetch method it's witten in the View and it's like this: var abs = new PocketsAbstractCollection(); abs.fetch({ success:

How to filter an object based on a DateTimeField range in Python (Django) using Tastypie

倾然丶 夕夏残阳落幕 提交于 2019-12-08 01:16:09
问题 How can one filter an object based on a datetime field range using Tastypie . I have a Post model : class Post(models.Model): title = models.CharField(max_length=40) postTime = models.DateTimeField(auto_now_add=True) description = models.CharField(max_length=140) The post objects are retrieved through Tastypie . The range of objects I would like to retrieve are all the objects created from today to all the objects created 3 days ago. So I tried filtering the objects from the queryset as

How to get authorized user object in django-tastypie

拟墨画扇 提交于 2019-12-07 17:27:53
问题 I need to get authorized user object in hydrate method, something like that: class SalepointResource(ModelResource): def hydrate(self, bundle): user = bundle.request.user But request here is empty HttpRequest object, and doesn't have user method, although user is authorized. Is there any way to get user object? 回答1: With TastyPie 0.9.15, I find this works: def hydrate_user(self, bundle): bundle.obj.user = bundle.request.user return bundle with no need for subclassing ModelResource . Here user

How to hydrate a resource_uri in django-tastypie?

梦想与她 提交于 2019-12-07 08:57:02
问题 I just have a Resource uri, like '/api/v1/myobjectresource/23/' , and I need to hydrate it. It means, I want to instantiate MyObject(pk=23) from its resource_uri . How should I do this? 回答1: Extracted from https://gist.github.com/794424 def get_resource_uri(self, bundle_or_obj): kwargs = { 'resource_name': self._meta.resource_name, } if isinstance(bundle_or_obj, Bundle): kwargs['pk'] = bundle_or_obj.obj.id # pk is referenced in ModelResource else: kwargs['pk'] = bundle_or_obj.id if self._meta

Unable to get ToMany to work in Tastypie

三世轮回 提交于 2019-12-07 08:18:36
问题 I'm following the Tastypie docs, and have found myself utterly stuck. I have the following: API: class ProjectResource(ModelResource): milestones = fields.ToManyField('ProjectTrackerServer.projects.api.MilestoneResource', 'projects', related_name='project', full=True) class Meta: queryset = Project.objects.all() resource_name = 'project' class MilestoneResource(ModelResource): project = fields.ToOneField('ProjectTrackerServer.projects.api.ProjectResource', 'project') class Meta: queryset =

Get model object from tastypie uri?

只愿长相守 提交于 2019-12-07 06:56:29
问题 How do you get the model object of a tastypie modelresource from it's uri? for example: if you were given the uri as a string in python, how do you get the model object of that string? 回答1: Tastypie's Resource class (which is the guy ModelResource is subclassing ) provides a method get_via_uri(uri, request). Be aware that his calls through to apply_authorization_limits(request, object_list) so if you don't receive the desired result make sure to edit your request in such a way that it passes

Mysterious ~1min delay in HTTP POST between browser and Nginx

谁说胖子不能爱 提交于 2019-12-07 06:29:42
问题 We've lately been experiencing a very strange but very consistent delay when POSTing from client-side javascript to our server. Here's our technology stack, from front to back: Custom javascript client code Backbone.js Custom Backbone.sync() implementation jQuery.ajax() (1.7.2) XmlHttpRequest Browser (verified on both Firefox and Chrome) Internet Nginx front-end Intranet (via Nginx http:// upstream) Nginx back-end Gunicorn (via Nginx unix:// upstream socket) Django 1.4 django-tastypie (Side

Django, TastyPie, Authentication, and custom middleware headache

…衆ロ難τιáo~ 提交于 2019-12-06 16:28:50
I have a Django web application which requires authentication across the whole site. I've accomplished that with custom middleware which basically test if request.user.is_anonymous and, if they are, redirects them to the login page. It looks like this: from django.contrib.auth.views import login from django.contrib.auth import authenticate from django.http import HttpResponseRedirect, HttpResponse from django.utils import simplejson from django.core import serializers class SiteLogin: "This middleware requires a login for every view" def process_request(self, request): if request.path != '

django-tastypie: linking a ModelResource to a Resource

喜夏-厌秋 提交于 2019-12-06 15:53:47
I'm currently trying django-tastypie to design a RESTful api. I'm facing a problem: # the RevisionObject retrieve commits info through pysvn # This Resource is fully functionnal (RevisionObject code is not here) class RevisionResource(Resource): id = fields.CharField(attribute='revision') description = fields.CharField(attribute='message') author = fields.CharField(attribute='author') changed_path = fields.ListField(attribute='changed_paths') class Meta: object_class = RevisionObject allowed_methods = ['get'] resource_name = 'revision' class RevisionToApplyResource(ModelResource): #### here's