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
#!/bin/bash | |
celery inspect ping -A project -d celery@$HOSTNAME | |
if [ $? -eq 0 ]; then \ | |
echo "OK"; \ | |
exit 0; \ | |
else \ | |
exit 1; \ | |
fi |
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: required | |
language: bash | |
script: | |
- make $SCRIPT | |
jobs: | |
fast_finish: true | |
include: | |
- stage: conflicts | |
env: | |
- TEST_SUITE=backend |
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
MIGRATION_CONFLICTS=$(shell find . -name "*.py" | grep -o ".*migrations/[0-9]\+" | sort | uniq -c | awk '$$1 > 1 {print $$0}') | |
migration-conflicts: | |
@if [ "${MIGRATION_CONFLICTS}" = "" ]; then \ | |
echo "No migration conflicts found."; \ | |
else \ | |
echo "The following migration conflicts found:" && \ | |
echo "${MIGRATION_CONFLICTS}" && exit 1; \ | |
fi | |
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
{ | |
"id": 1, | |
"thumbnails": { | |
"small": "https://example.com/image_small.jpg", | |
"medium": "https://example.com/image_medium.jpg", | |
"large": "https://example.com/image_large.jpg" | |
} | |
} |
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 Photo(models.Model): | |
thumbnail = models.ImageField(...) | |
... | |
def get_small_thumbnail(self): | |
return get_thumbnail(size='small') | |
def get_medium_thumbnail(self): | |
return get_thumbnail(size='medium') |
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 DynamicMethodField(serializers.Field): | |
"""Field that accepts instance methods and method kwargs.""" | |
def __init__(self, *args, **kwargs): | |
"""Extend DynamicMethodCharField.__init__. | |
Args: | |
method (str): Method on the instance to call. | |
method_args (list): List of arguments to pass to the | |
instance method. |
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 Photo(models.Model): | |
thumbnail = models.ImageField(...) | |
def get_thumbnail(self, size='medium'): | |
"""Get an appropriate size thumbnail. | |
https://example.com/image.jpg would now be | |
https://example.com/image_medium.jpg | |
""" | |
url_parts = self.thumbnail.url.rsplit('.') |
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
body { | |
background-color: transparent; | |
margin: 0px auto; | |
overflow: hidden; | |
} | |
._4-u2 { | |
border: none; | |
} |
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 MyModel(models.Model): | |
can_connect_twitter = models.BooleanField(default=False) | |
can_connect_facebook = models.BooleanField(default=False) | |
class PermissionSerializer(serializers.ModelSerializer): | |
class Meta: | |
fields = ('can_connect_twitter', 'can_connect_facebook',) | |
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 SerializerMethodKwargField(serializers.SerializerMethodField): | |
def __init__(self, *args, **kwargs): | |
default_args = [ | |
'read_only', 'write_only', 'required', 'default', 'initial', 'source', 'label', | |
'help_text', 'style', 'error_messages', 'validators', 'allow_null'] | |
kwargs_to_del = [] | |
self.method_kwargs = {} | |
for kwarg in kwargs: | |
if kwarg not in default_args: |