This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Recette < AR::Base | |
has_many :ingredients | |
end | |
class Ingredient < AR::Base | |
belongs_to :recette | |
has_one :ingedient_type | |
end | |
class IngredientType < AR::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A: | |
def open(self): | |
# code avant | |
self._open(self) | |
# code après | |
class B(A): | |
def _open(self): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Profile(models.Model): | |
foo = models.CharField() | |
user = models.ForeignKey(User) | |
@property | |
def first_name(self): | |
return self.user.first_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def workday?(date) | |
1 <= date.wday <= 5 | |
end | |
workday_count_between(start_date, end_date) | |
(start_date..end_date).count{ |d| workday?(d)} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Recette < AR::Base | |
include Feeds::ModelMixin | |
end | |
class Article < AR::Base | |
include Feeds::ModelMixin | |
end | |
module Feeds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FormDeclaration(models.Model): | |
form_fields = JSONField() | |
f = FormDeclaration() | |
f.form_fields = [ | |
{'name': 'foo', 'type': 'TextField'} | |
] |
OlderNewer