Skip to content

Instantly share code, notes, and snippets.

View armonge's full-sized avatar
🏠

Andrés Reyes Monge armonge

🏠
View GitHub Profile
@armonge
armonge / Questions
Created June 22, 2011 03:08
Kiwi Pycon Give-away
GitHub username:armonge
Day job:Web Developer
Favorite open source project:Django
Open Source contributions (if any):
Stranded on an island, what 3 items do you take:Flashlight,matches, satellite phone
Tie-breaker, pick a number between 1 and 20,000:32433
@armonge
armonge / fields.py
Created July 18, 2011 14:41
A Django custom modelfield, formfield and formwidget to select and save a set of geographic coordinates using Google Maps
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__())
@armonge
armonge / fields.py
Created July 19, 2011 17:32
Django fields to validate file content type
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
@armonge
armonge / mixins.py
Created August 22, 2011 16:35
A model Mixin to use in translatable applications, to use inherit your models from this
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,
@armonge
armonge / gist:1163934
Created August 22, 2011 23:43 — forked from voodootikigod/gist:1155790
PyCodeConf Ticket Give-away
Day job: Web Developer in Nicaragua
Favorite Python project: Django
Favorite Conference: Haven't attended any yet :(
Python Experience Level: Intermediate
@armonge
armonge / Questions
Created September 6, 2011 00:49
GOTO Amsterdam
Day job: Web Developer
What is your language of choice: Python
Open Source contributions: No biggies here, just some patch in https://github.com/mozes/smpp.pdu
How do you use GitHub: Mostly i work for organizations that provide me some git repos here, but i also mantain some gists and template django projects i use regularly
@armonge
armonge / urls.py
Created November 10, 2011 20:56 — forked from mhulse/urls.py
Django: How to upgrade this old functional view to new class based view?
###### NEW:
from django.conf.urls.defaults import *
from sporty import views
urlpatterns = patterns('',
url(
# 30 characters or fewer. Letters, numbers and @/./+/-/_ characters:
r'^users/(?P<username>[a-zA-Z0-9@.+-_]+)/$',
@armonge
armonge / admin.py
Created January 13, 2012 04:13
Show an image in django admin list_display, using sorl-thumbnail
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
@armonge
armonge / video_list.py
Created March 15, 2012 00:16
Get a list of all the youtube download URL's for PyCon2012
from bs4 import BeautifulSoup
from urlparse import parse_qs, urlparse
from urlparse import unquote, urlparse, parse_qs
from concurrent.futures import ProcessPoolExecutor
import urllib
import sys
video_list = []
sys.setrecursionlimit(10000)
@armonge
armonge / gist:2830057
Created May 29, 2012 19:04
django youtube field
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+)?$'