Skip to content

Instantly share code, notes, and snippets.

View felipe-prenholato's full-sized avatar

Felipe Prenholato felipe-prenholato

View GitHub Profile
@felipe-prenholato
felipe-prenholato / gist:5208763
Created March 20, 2013 21:43
just a concept
def save_name(fvalue, row):
# save name on auth.User, user row['email'] as key
return
def save_graduation(fvalue, row):
# save graduation on accounts.UserProfile, user row['email'] to get user and than get_profile()
return
function_dict = {'name': save_name,
{% spaceless %}
{# this is included in form.html and is loaded via ajax #}
{% load bootstrap_toolkit %}
{% if success %}
{# msg in form instead in next request #}
<div class="alert success alert-success">
<a class="close" data-dismiss="alert">×</a>
{{ success|safe }}
</div>
{% endif %}
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, unicode_literals)
def flat_list(l):
result = []
for i, e in enumerate(l):
if type(e) is list:
result += e
else:
@felipe-prenholato
felipe-prenholato / test_selectable.html
Last active December 11, 2015 13:59
selectable crazy enter bug (or autocomplete, but lets see...)
<!DOCTYPE html>{% load staticfiles %}
<html lang="en">
<head>
<meta charset="utf-8">
<title>Html5</title>
<link rel="stylesheet" href="{% static 'js/jquery-ui/css/smoothness/jquery-ui-1.9.1.css' %}" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
{{ form.media }}
{% comment %}
@felipe-prenholato
felipe-prenholato / pega_cep.py
Created January 11, 2013 17:54
rascunhos para uma app em cima do cepbr
def get_cep(cep):
# cache = django cache
# CepCache = model para cachear os ceps
cached = cache.get(cep)
if not cached:
try:
dbcep = CepCache.objects.get(cep=cep)
except CepCache.DoesNotExist:
from cepbr import Cep
dbcep = CepCache.objects.create(**Cep(cep))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import codecs
from django.utils.datastructures import SortedDict
linhas = SortedDict() # um sorted dict é uma boa
with codecs.open('bacula_log.log', 'rb', 'utf8') as f:
class LockedTask(Task):
# based on http://celery.readthedocs.org/en/latest/tutorials/task-cookbook.html#ensuring-a-task-is-only-executed-one-at-a-time
abstract = True
lock_expire = 5 # 5 minutes
def __init__(self, *a, **kw):
super(LockedTask, self).__init__(*a, **kw)
self.logger = self.get_logger()
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from django.db import models
class Product(models.Model):
""" Store products """
name = models.CharField(max_length=50)
from sentry.conf.server import *
import os.path
CONF_ROOT = os.path.dirname(__file__)
DATABASES = {
'default': {
# You can swap out the engine for MySQL easily by changing this value
# to ``django.db.backends.mysql`` or to PostgreSQL with
# ``django.db.backends.postgresql_psycopg2``
(0.000) SELECT `sentry_filterkey`.`id`, `sentry_filterkey`.`project_id`, `sentry_filterkey`.`key` FROM `sentry_filterkey` WHERE (`sentry_filterkey`.`project_id` = 1 AND `sentry_filterkey`.`key` = 'logger' ); args=(1, 'logger')
Traceback (most recent call last):
File "/home/sistemas/virtualenvs/sentry/local/lib/python2.7/site-packages/raven/handlers/logging.py", line 56, in emit
return self._emit(record)
File "/home/sistemas/virtualenvs/sentry/local/lib/python2.7/site-packages/raven/contrib/django/handlers.py", line 32, in _emit
return super(SentryHandler, self)._emit(record, request=request)
File "/home/sistemas/virtualenvs/sentry/local/lib/python2.7/site-packages/raven/handlers/logging.py", line 136, in _emit
date=date, **kwargs)
File "/home/sistemas/virtualenvs/sentry/local/lib/python2.7/site-packages/raven/contrib/django/client.py", line 97, in capture
result = super(DjangoClient, self).capture(event_type, **kwargs)