Project

General

Profile

Download (1.34 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / models.py @ e01a19ba

1
# -*- coding: utf-8 -*-
2

    
3
from django.db import models
4
from django.contrib.localflavor.fr.forms import FRPhoneNumberField, FRZipCodeField
5

    
6
WEEKDAYS = (u'lundi', u'mardi', u'mercredi', u'jeudi', u'vendredi')
7

    
8
class BaseModelMixin(object):
9
    def __repr__(self):
10
        return '<%s %s %r>' % (self.__class__.__name__, self.id, unicode(self))
11

    
12

    
13
class PhoneNumberField(models.CharField):
14
    def __init__(self, *args, **kwargs):
15
        kwargs['max_length'] = 20
16
        super(PhoneNumberField, self).__init__(*args,**kwargs)
17

    
18
    def formfield(self, **kwargs):
19
        default = { 'form_class': FRPhoneNumberField }
20
        default.update(kwargs)
21
        return super(PhoneNumberField, self).formfield(**kwargs)
22

    
23

    
24
class ZipCodeField(models.CharField):
25
    def __init__(self, **kwargs):
26
        kwargs['max_length'] = 5
27
        super(ZipCodeField, self).__init__(**kwargs)
28

    
29
    def formfield(self, **kwargs):
30
        default = { 'form_class': FRZipCodeField }
31
        default.update(kwargs)
32
        return super(ZipCodeField, self).formfield(**kwargs)
33

    
34

    
35

    
36
class WeekdayField(models.CharField):
37
    WEEKDAYS_CHOICE = ((None, u'Aucun'),) \
38
            + tuple(zip(WEEKDAYS, map(unicode.title, WEEKDAYS)))
39

    
40
    def __init__(self, **kwargs):
41
        kwargs['max_length'] = 16
42
        kwargs['choices'] = self.WEEKDAYS_CHOICE
43
        super(WeekdayField, self).__init__(**kwargs)
44

    
(6-6/10)