Skip to content

Instantly share code, notes, and snippets.

View rochacbruno's full-sized avatar
🛠️
Working on Galaxy_ng and Dynaconf

Bruno Rocha rochacbruno

🛠️
Working on Galaxy_ng and Dynaconf
View GitHub Profile
@rochacbruno
rochacbruno / append_xmltodict.py
Last active August 29, 2015 13:56
append item to xml with xmltodict
import xmltodict
secundario = """<Pessoa>
<Nome>rayane</Nome>
<Idade>20</Idade>
<Endereco>avenida1</Endereco>
<Cidade>bh</Cidade>
<CPF>111.111.111-11</CPF>
<E-mail>email@email.com</E-mail>
</Pessoa>"""
from flask import Blueprint
from urls import url_rules
bp = Blueprint(__name__.split('.')[1], __name__, template_folder='templates')
for url_rule in url_rules:
url_regex, view_func = url_rule
bp.add_url_rule(url_regex, view_func=view_func, methods=['GET', 'POST'])
class MyInline(admin.TabularInline):
model = MyModel
extra = 0
template = 'admin/edit_inline/list.html'
def get_formset(self, request, obj=None, **kwargs):
FormSet = super(ActivationKeyInline, self).get_formset(request, obj, **kwargs)
class NewFormSet(FormSet):
def _construct_forms(self, *args, **kwargs):
qs = self.get_queryset()

Pre load boxes for performance and avoid content duplication.

Recommended to use OPPS_MULTISITE_FALLBACK = True and have in mind that boxes will return a list of ContainerBoxContainers instead of a list of Containers.

To preload all the container boxes of a given page and avoid duplication of content the load_boxes tag should be used, this tag will take a list of slugs and the order of slugs in that list will be the precedence to avoid repetitions.

In the base template the following block should be defined.

# templates/base.html
@rochacbruno
rochacbruno / getlat.py
Created February 27, 2014 14:57
get address from lat & long
from urllib2 import urlopen
import json
def getplace(lat, lon):
url = "http://maps.googleapis.com/maps/api/geocode/json?"
url += "latlng=%s,%s&sensor=false" % (lat, lon)
v = urlopen(url).read()
j = json.loads(v)
components = j['results'][0]['address_components']
country = town = None
for c in components:
# coding=utf-8
"""
**Implementa um Webcrawler para extracao de dados da pesquisa de media de precos realizada periodicamente pela ANP**
Desenvolvido por Fabio C. Barrioneuvo da Luz. - 2013
Simple crawler to ANP site
Copyright (C) 2013 Fabio C. Barrioneuvo da Luz.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
"""
Usage:
python jinja2web2py.py jinjatemplate.html > web2pytemplate.html
Disclaimer. It is not perfect. Some times minor manual tweaks may be necessary.
Notice the web2py template language was invented in 2007 and consists of pure Python code.
The opposite conversion is not possible because arbitrary Python code cannot be converted to a jinja template.
"""
import sys
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
from turtle import *
def drawPython():
begin_fill()
forward(90)
circle(50, 90)
forward(80)
circle(5, 90)
forward(140)
circle(5, 90)
import os
import gearman
from PIL import Image
MINI_SIZE = (50, 50)
THUMB_SIZE = (150, 150)
MOBILE_SIZE = (600, 600)
FULL_SIZE = (1024, 1024)