Project

General

Profile

« Previous | Next » 

Revision 706c6be7

Added by Benjamin Dauvergne over 11 years ago

personnes: add a unicode method to Holiday model

View differences:

calebasse/personnes/models.py
5 5
from django.db import models
6 6
from django.contrib.auth.models import User
7 7
from django.core.exceptions import ValidationError
8
from django.template.defaultfilters import date as date_filter
8 9

  
9 10
from calebasse.ressources.models import WorkerType, Service
10 11
from calebasse.models import WeekdayField, BaseModelMixin
......
117 118
                   .filter(end_date__gte=date.today())
118 119

  
119 120

  
121
def time2french(time):
122
    if time.minute:
123
        return '{0}h{1}'.format(time.hour, time.minute)
124
    return '{0}h'.format(time.hour)
125

  
120 126
class Holiday(BaseModelMixin, models.Model):
121 127
    objects = HolidayManager()
122 128

  
......
137 143
    def clean(self):
138 144
        if not self.worker and not self.service:
139 145
            raise ValidationError('at least one of worker or service must be set')
146
    def __unicode__(self):
147
        ret = ''
148
        if self.start_date == self.end_date:
149
            ret = u'le {0}'.format(date_filter(self.start_date, 'j F Y'))
150
            if self.start_time and self.end_time:
151
                ret += u', de {0} à {1}'.format(time2french(self.start_time),
152
                time2french(self.end_time))
153
        else:
154
            ret = u'du {0} au {1}'.format(
155
                    date_filter(self.start_date, 'j F'),
156
                    date_filter(self.end_date, 'j F Y'))
157
        return ret
158

  

Also available in: Unified diff