This file contains hidden or 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
| import os | |
| from flask import Flask | |
| from websocket import handle_websocket | |
| app = Flask(__name__) | |
| app.secret_key = os.urandom(24) | |
| app.debug = True | |
| def my_app(environ, start_response): |
This file contains hidden or 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
| flask | |
| gevent | |
| gevent-websocket |
This file contains hidden or 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
| . | |
| ├── runserver.py | |
| ├── requirements.txt | |
| └── app | |
| ├── __init__.py | |
| ├── views.py | |
| ├── websocket.py | |
| ├── static | |
| │ └── ... | |
| └── templates |
This file contains hidden or 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
| sudo apt-get remove unity-lens-shopping | |
| sudo apt-get remove unity-scope-video-remote | |
| sudo apt-get remove unity-scope-musicstores | |
| sudo su - | |
| echo 'OFFERS_URI="https://localhost:0/"' >> /etc/environment |
This file contains hidden or 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 restless.dj import DjangoResource | |
| from restless.preparers import FieldsPreparer | |
| from .mixins import APIPaginatorMixin | |
| class CountryResource(APIPaginatorMixin, DjangoResource): | |
| preparer = FieldsPreparer(fields={ | |
| 'id': 'id', | |
| 'name': 'name'}) | |
| def get_queryset(self): |
This file contains hidden or 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.core.paginator import Paginator | |
| class APIPaginatorMixin: | |
| per_page = 25 | |
| def get_queryset(self): | |
| raise NotImplementedError() | |
| def wrap_list_response(self, data): | |
| return { |
This file contains hidden or 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
| [...] | |
| url(r'^api/countries/', include(CountryResource.urls())), | |
| url(r'^api/pizzas/', include(PizzaResource.urls())), | |
| [...] |
This file contains hidden or 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 restless.dj import DjangoResource | |
| from restless.preparers import FieldsPreparer | |
| class CountryResource(DjangoResource): | |
| preparer = FieldsPreparer(fields={ | |
| 'id': 'id', | |
| 'name': 'name'}) | |
| class PizzaResource(DjangoResource): | |
| preparer = FieldsPreparer(fields={ |
This file contains hidden or 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 Country(models.Model): | |
| name = models.CharField(max_length=2) | |
| class Pizza(models.Model): | |
| name = models.CharField(max_length=255) | |
| country = models.ForeignKey(Country) |
This file contains hidden or 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 APIOrderingMixin: | |
| allowed_fields_ordering = [] | |
| ordering_field = 'order_by' | |
| def ordering(self, queryset): | |
| order_by = self.request.GET.get(self.ordering_field) | |
| if not order_by: | |
| return queryset | |
| if order_by.split('-')[-1] in self.allowed_fields_ordering: |