Skip to content

Instantly share code, notes, and snippets.

View byroot's full-sized avatar

Jean Boussier byroot

View GitHub Profile
# -*- coding: utf-8 -*-
class Profile(models.Model):
foo = models.CharField()
user = models.ForeignKey(User)
@property
def first_name(self):
return self.user.first_name
def formation(request):
if request.method == 'POST':
form = ConsultFormationForm(request.POST)
if form.is_valid():
theme_choisi = form.cleaned_data['theme']
duree_min_choisie = form.cleaned_data['duree_min']
duree_max_choisie = form.cleaned_data['duree_max']
if theme_choisi is not None:
if duree_min_choisie != 'no' and duree_max_choisie !='no':
import ho.pisa as pisa
from django.template import loader
from django.http import HttpResponse
def render_to_pdf(*args, **kwargs):
response = HttpResponse('', mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s' % kwargs.pop('filename', 'something.pdf')
document = loader.render_to_string(*args, **kwargs)
print document
def workday?(date)
1 <= date.wday <= 5
end
workday_count_between(start_date, end_date)
(start_date..end_date).count{ |d| workday?(d)}
end
class Recette < AR::Base
include Feeds::ModelMixin
end
class Article < AR::Base
include Feeds::ModelMixin
end
module Feeds
class FormDeclaration(models.Model):
form_fields = JSONField()
f = FormDeclaration()
f.form_fields = [
{'name': 'foo', 'type': 'TextField'}
]
diff --git a/parltrack/current_meps_json_2_sql.py b/parltrack/current_meps_json_2_sql.py
index 1690f46..9053972 100644
--- a/parltrack/current_meps_json_2_sql.py
+++ b/parltrack/current_meps_json_2_sql.py
@@ -174,8 +174,8 @@ def add_addrs(mep, addrs):
name=bxl["Address"]["Building"],
street=bxl["Address"]["Street"],
postcode=bxl["Address"]["Zip"])
- mep.bxl_floor = bxl["Address"]["Office"][:3]
- mep.bxl_office_number = bxl["Address"]["Office"][3:]
#!/usr/bin/env python
import threading
import subprocess
results = []
def launch_job(arg):
results.append(subprocess.Popen(['/bin/echo %s' % arg], shell=True, stdout=subprocess.PIPE).communicate()[0])
MEP.objects.filter(countrymep__end__gt=d, countrymep__begin__lt=d).extra(select={'current_country_id': 'meps_countrymep.country_id'})
GET /votes/ACTA_resolution/693/abstention/
avant: 272 -> 84ms
après 116 -> 69ms
\o/