Skip to content

Instantly share code, notes, and snippets.

View byroot's full-sized avatar

Jean Boussier byroot

View GitHub Profile
class Recette < AR::Base
has_many :ingredients
end
class Ingredient < AR::Base
belongs_to :recette
has_one :ingedient_type
end
class IngredientType < AR::Base
class A:
def open(self):
# code avant
self._open(self)
# code après
class B(A):
def _open(self):
pass
require 'spec_helper'
describe User do
it{ should have_field(:email).of_type(String) }
it{ should have_field(:username).of_type(String) }
it{ should have_field(:password_hash).of_type(String) }
it{ should have_field(:password_salt).of_type(String) }
it{ should have_field(:activation_token).of_type(String) }
module Mongoid
module Mutation
def as(klass, extra_attributes={})
klass.new(attributes_for(klass, extra_attributes)).tap do |mutation|
mutation.new_record = new_record?
mutation.send(:modifications)['_type'] = [self._type, klass.name]
end
end
# -*- 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'}
]