Skip to content

Instantly share code, notes, and snippets.

View edgabaldi's full-sized avatar
🏠
Working from home

Edgar Gabaldi edgabaldi

🏠
Working from home
View GitHub Profile
@edgabaldi
edgabaldi / example.py
Created October 24, 2015 20:57
Download photo with requests and saving in Django ImageField
import requests
from StringIO import StringIO
from product.models import Product, Photo
from django.core.files.base import ContentFile
response = requests.get('http://photo-url/image.jpg')
file = StringIO(response.content)
file_content = ContentFile(file.read())
@edgabaldi
edgabaldi / randomize.py
Created October 22, 2015 02:39
Generate Randon valid CPF (unfinished)
class Randomize(object):
def _get_multiplier(self):
if not hasattr(self, 'multiplier') or \
self.multiplier == None:
self.multiplier = 2
else:
if self.multiplier == 9:
@edgabaldi
edgabaldi / example.py
Last active September 3, 2015 20:05
Annotate example
class Company(models.Model):
name = models.CharField(max_length=100)
class Product(models.Model):
name = models.CharField(max_length=100)
class Quotation(models.Model):
product = models.ForeignKey('app.Product', related_name=quotations)
company = models.ForeignKey('app.Company')
price = models.DecimalField(...)
@edgabaldi
edgabaldi / book_reco.ipynb
Last active August 31, 2015 22:57 — forked from mickaellegal/book_reco.ipynb
iPython Notebook: Blog book recommendation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@edgabaldi
edgabaldi / index.html
Created August 18, 2015 19:02
Manually render an angular template from ng-template inside directive
<!DOCTYPE html>
<html ng-app="fooBar">
<head>
<script data-require="angular.js@*" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script type="text/ng-template" id="tpl.html">
<h1>{{message}}</h1>
</script>
<script src="script.js"></script>
@edgabaldi
edgabaldi / TODO.txt
Last active August 29, 2015 14:26
easy way to write xls files with a dict/tuple
* easy way to set style of a sheet
* totalization ?
* Use more that one "table" by sheet.
- Maybe use cursors. (self.cursor_row, self.cursor_line)
@edgabaldi
edgabaldi / __init__.py
Last active August 29, 2015 14:25
post migrate signal that create new permissions
#coding:utf-8
from south.signals import post_migrate
def update_permission_after_migration(app, **kwargs):
"""
your_project.__init__.py is a nice place to stay
Update app permission just after every migration.
This is based on app djando_extensions update_permissions management command.
"""
@edgabaldi
edgabaldi / readonly.py
Created July 16, 2015 02:31
ReadOnlyFieldsMixin
from django.utils import six
from django.utils.encoding import force_str
class ReadOnlyFieldsMixin(object):
readonly_fields = ()
def __init__(self, *args, **kwargs):
super(ReadOnlyFieldsMixin, self).__init__(*args, **kwargs)
self.define_readonly_fields(self.fields)
@edgabaldi
edgabaldi / round_decimal.py
Last active August 29, 2015 14:23
Round Decimal
>>> from decimal import Decimal
>>> Decimal('2.14999').quantize(Decimal('0.00'))
Decimal('2.15')
@edgabaldi
edgabaldi / capacidadecategoria_form.html
Created June 23, 2015 18:18
Custom template example of ModelFormSetView (django-extra-views)
{% extends 'agendamento/base_comitente.html' %}
{% load bootstrap %}
{% block extra_css %}
<style>
.form-actions{
padding:10px;
background-color:#EEE;
border-top:1px solid #CCC;
}