def __unicode__(self): return _('%(start_time)s ~ %(end_time)s on %(date)s of %(user)s') % { 'start_time': field_to_string(self._meta.get_field_by_name('start_time')[0], self), 'end_time': field_to_string(self._meta.get_field_by_name('end_time')[0], self), 'date': field_to_string(self.timesheet._meta.get_field_by_name('date')[0], self.timesheet), 'user': self.timesheet.user }
def __setattr__(self, name, value): try: if self.pk and name in self.__field_cache: field = self.__field_cache[name] label = u"%s" % field.verbose_name if name not in self.__change_exclude: old_value = field_to_string(field, self) if label in self.__changes: old_value = self.__changes[label][0] super(Observable, self).__setattr__(name, value) value = field_to_string(field, self) if value != old_value: self.__changes[label] = (u"%s" % old_value, u"%s" % value) return except AttributeError: pass super(Observable, self).__setattr__(name, value)
def field_template(name, field, form_or_model, attrs={}, suffix=""): label = "" value = "" output = "" td_attrs = {} if isinstance(field, models.Field): label = u'%s' % field.verbose_name value = field_to_string(field, form_or_model) elif isinstance(field, forms.Field): bf = BoundField(form_or_model, field, name) label = u'%s' % bf.label_tag() value = u'%s' % bf if bf.help_text: value += '<br/>\n<span class="help_text">%s</span>' % ( u'%s' % bf.help_text) if bf._errors(): value += '<br/>\n<ul class="errorlist">\n' for error in bf._errors(): value += '\t<li>%s</li>\n' % error value += '</ul>\n' css_classes = bf.css_classes() if css_classes: td_attrs['class'] = css_classes else: name = _(pretty_name(name).lower()) label = u'%s' % name.capitalize() if callable(field): value = value_to_string(field()) else: value = value_to_string(field) td_attrs.update(attrs) if label and value: output += ("\t\t<th>%s</th>\n" % (label[0].capitalize() + label[1:])) output += "\t\t<td%s>\n" % flatatt(td_attrs) output += "\t\t\t%s%s\n" % (value, suffix) output += "\t\t</td>\n" return output
def field_template(name, field, form_or_model, attrs={}, suffix=""): label = "" value = "" output = "" td_attrs = {} if isinstance(field, models.Field): label = u'%s' % field.verbose_name value = field_to_string(field, form_or_model) elif isinstance(field, forms.Field): bf = BoundField(form_or_model, field, name) label = u'%s' % bf.label_tag() value = u'%s' % bf if bf.help_text: value += '<br/>\n<span class="help_text">%s</span>' % (u'%s' % bf.help_text) if bf._errors(): value += '<br/>\n<ul class="errorlist">\n' for error in bf._errors(): value += '\t<li>%s</li>\n' % error value += '</ul>\n' css_classes = bf.css_classes() if css_classes: td_attrs['class'] = css_classes else: name = _(pretty_name(name).lower()) label = u'%s' % name.capitalize() if callable(field): value = value_to_string(field()) else: value = value_to_string(field) td_attrs.update(attrs) if label and value: output += ("\t\t<th>%s</th>\n" % (label[0].capitalize() + label[1:])) output += "\t\t<td%s>\n" % flatatt(td_attrs) output += "\t\t\t%s%s\n" % (value, suffix) output += "\t\t</td>\n" return output
def __unicode__(self): return _('%(type)s ~ %(amount)s on %(date)s') % { 'type': field_to_string(self._meta.get_field_by_name('type')[0], self), 'amount': field_to_string(self._meta.get_field_by_name('amount')[0], self), 'date': field_to_string(self._meta.get_field_by_name('date')[0], self), }