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 ContentTypeRestrictedFileField(models.FileField): | |
""" | |
Tomado de http://nemesisdesign.net/blog/coding/django-filefield-content-type-size-validation/ | |
Same as FileField, but you can specify: | |
* content_types - list containing allowed content_types. Example: ['application/pdf', 'image/jpeg'] | |
* max_upload_size - a number indicating the maximum file size allowed for upload. | |
2.5MB - 2621440 | |
5MB - 5242880 | |
10MB - 10485760 | |
20MB - 20971520 |
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 urlparse | |
import re | |
from django.db import models | |
from django import forms | |
def validate_youtube_url(value): | |
'''El patron lo saque de http://stackoverflow.com/questions/2964678/jquery-youtube-url-validation-with-regex''' | |
pattern = r'^http:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=\w+)(?:\S+)?$' |
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 TranslatableModelMixin(models.Model): | |
''' | |
Adapted from http://snippets.dzone.com/posts/show/2979 | |
''' | |
language = models.CharField(max_length=2, choices=settings.LANGUAGES, db_index=True) | |
translation_of = models.ForeignKey( | |
to='self', | |
related_name='translation_set', | |
limit_choices_to={'language' : settings.DEFAULT_LANGUAGE}, | |
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
class GoogleMapMarker(object): | |
def __init__(self, latitude, longitude): | |
self.latitude = latitude | |
self.longitude = longitude | |
def __unicode__(self): | |
return '%f,%f'%(self.latitude, self.longitude) | |
def __len__(self): | |
return len(self.__unicode__()) |
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 bash | |
set -euo pipefail | |
set -o xtrace | |
if [ ! -f "dialogflow_key.json" ] && [ "${DIALOGFLOW_KEY:-}" ]; then | |
echo "$DIALOGFLOW_KEY" >dialogflow_key.json | |
fi | |
if [ -f "dialogflow_key.json" ]; then | |
gcloud auth activate-service-account --key-file=dialogflow_key.json |
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 bash | |
set -euo pipefail | |
# set -o xtrace | |
if [ ! -d "$HOME/.ask" ]; then | |
# Create the .ask directory | |
mkdir ~/.ask | |
# Create ASK config | |
sed -e s/ASK_ACCESS_TOKEN/"${ASK_ACCESS_TOKEN}"/g -e \ |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 ProductAdmin(admin.ModelAdmin): | |
list_display = ('name','thumb') | |
def thumb(self, obj): | |
return render_to_string('thumb.html',{ | |
'image': obj.image | |
}) | |
thumb.allow_tags = 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 functools | |
import random | |
import math | |
from concurrent import futures | |
def map_d(c): | |
return math.hypot(random.random(), random.random()) | |
NewerOlder