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 rest_framework import serializers | |
from core.serializers import ListWrapperSerializer | |
from .models import Band | |
class BandListSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Band |
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 fabric.api import * | |
from fabvenv import virtualenv, make_virtualenv | |
import server_config | |
env.roledefs = { | |
'django': server_config.DJANGO_HOSTS, | |
'django_provision': server_config.PROVISION_DJANGO_HOSTS, | |
} |
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
var successCallback = function(result) { | |
console.log('audio callback ' + JSON.stringify(result)); | |
if (result.type==='progress') { | |
console.log('progress/duration/available - ' + result.progress + '/' + result.duration + '/' + result.available); // available not currently supported | |
} else if (result.type==='state') { | |
console.log('status - ' + result.state + '/' + result.description); | |
} else if (result.type==='error') { | |
console.log('error - ' + result.reason); | |
} else if (result.type==='current') { | |
console.log('current audio ' + JSON.stringify(result.audio)); |
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 tapioca.exceptions import ClientError, ServerError | |
from my_wrapper import MyWrapper | |
api = MyWrapper() | |
try: | |
r = api.my_resource().post(data={'test': 'data'}) | |
except ClientError as e: | |
print('This is a client error with status code %s' % e.client().response().status_code) | |
except ServerError as e: |
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
# executando algo antes da criação | |
class MeuTipo(type): | |
def __new__(cls, name, parents, dct): | |
print 'aqui!' | |
return super(MeuTipo, cls).__new__(cls, name, parents, dct) | |
class MinhaClasse(object): | |
__metaclass__ = MeuTipo | |
# trocando o nome da class |
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
url(r'^example/$', 'account.views.example_view', name='user_info'), |
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 rest_framework import permissions | |
class CustomViewPermission(permissions.BasePermission): | |
def has_permission(self, request, view): | |
if hasattr(view, 'custom_permission'): | |
return view.custom_permission(request) | |
return True |
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 categorize(lst, attrs): | |
""" | |
Generate a dictionary of lists where the keys are generated from | |
some specified attribute of the items in the list | |
""" | |
def dive_in(obj, attrs, index=0): | |
if not obj or index >= len(attrs): | |
return obj | |
new_obj = getattr(obj, attrs[index]) | |
if len(attrs) > 0: |
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 Bike(models.Model): | |
COLOR_OPTIONS = (('yellow', 'Yellow'), ('red', 'Red'), ('black', 'Black')) | |
color = models.CharField(max_length=255, null=True, blank=True, | |
choices=COLOR_OPTIONS) | |
size = models.DecimalField(max_digits=4, decimal_places=2, null=True, blank=True) |
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
import mock | |
from django.test import TestCase | |
from django.contrib.auth.models import User | |
class EmailTests(TestCase): | |
def setUp(self): | |
self.user = User.objects.create( | |
username='theusername', email='the@email.com', | |
first_name='Filipe', last_name='Ximenes', |
OlderNewer