This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl civic-voice.appspot.com/meeting/submit_input -d meetingId=t2 -d user=commandlineapi -d value="gist.github.com/370617" -d inputType=comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EntryResource(ModelResource): | |
user = fields.ForeignKey(UserResource, 'user') | |
class Meta: | |
queryset = Entry.objects.all() | |
resource_name = 'entry' | |
def dispatch(self, request_type, request, **kwargs): | |
username = kwargs.pop('username') | |
kwargs['user'] = get_object_or_404(User, username=username) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class DependentCharField(models.CharField): | |
description = "A Field that can be null or blank if other returns a truthy value" | |
def __init__(self, dependentName, *args, **kwargs): | |
kwargs['blank'] = True | |
kwargs['null'] = True | |
self.dependentName = dependentName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie.resources import ModelResource | |
class FlaggedResource(ModelResource): | |
def obj_update(self, bundle, request=None, **kwargs): | |
processFlag = bundle.obj and not bundle.obj.flagged | |
bundle = super(FlaggedResource, self).obj_update(bundle, request, **kwargs) | |
if processFlag: | |
bundle.obj.flagLogic() | |
return bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie.authentication import Authentication | |
class DjangoAuthentication(Authentication): | |
"""Authenticate based upon Django session""" | |
def is_authenticated(self, request, **kwargs): | |
return request.user.is_authenticated() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def post_list(self, request, **kwargs): | |
deserialized = self.deserialize(request, | |
request.raw_post_data, | |
format=request.META.get('CONTENT_TYPE', | |
'application/json')) | |
bundle = self.build_bundle(data=dict_strip_unicode_keys(deserialized)) | |
self.is_valid(bundle, request) | |
updated_bundle = self.obj_create(bundle, request=request) | |
resp = self.create_response(request, | |
self.full_dehydrate(updated_bundle.obj)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SiteResource(ModelResource): | |
""" Thing that are meant to be accessed with a cookie """ | |
def dispatch(self, request_type, request, **kwargs): | |
kwargs['site'] = Site.objects.get_current() | |
return super(SiteResource, self).dispatch(request_type, request, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Response(object): | |
def __init__(self, status=200): | |
self.status = status | |
class Client: | |
def get(self, path): | |
return Response(200) | |
def post(self, path): | |
return Response(405) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundle.data['max_responses'] -> None | |
bundle.obj.max_responses -> 22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import eventlet | |
import eventlet.debug | |
os.environ["EVENTLET_NOPATCH"] = 'True' | |
eventlet.monkey_patch() | |
eventlet.debug.hub_prevent_multiple_readers(False) | |
from django.core.management import execute_manager |
OlderNewer