class StartEndTime(dd.Model): class Meta: abstract = True start_time = dd.TimeField(blank=True, null=True, verbose_name=_("Start Time")) end_time = dd.TimeField(blank=True, null=True, verbose_name=_("End Time"))
class Started(CombinedDateTime): """ Adds two fields :attr:`start_date` and :attr:`start_time`. .. attribute:: start_date .. attribute:: start_time """ class Meta: abstract = True start_date = models.DateField(blank=True, null=True, verbose_name=_("Start date")) # iCal:DTSTART start_time = dd.TimeField(blank=True, null=True, verbose_name=_("Start time")) # iCal:DTSTART #~ start = dd.FieldSet(_("Start"),'start_date start_time') def save(self, *args, **kw): """ Fills default value "today" to start_date """ if not self.start_date: self.start_date = settings.SITE.today() super(Started, self).save(*args, **kw)
class DailyPlannerRow(BabelDesignated, Sequenced, Plannable): class Meta: app_label = 'calview' abstract = dd.is_abstract_model(__name__, 'PlannerRow') verbose_name = _("Planner row") verbose_name_plural = _("Planner rows") ordering = ['start_time','-seqno'] start_time = dd.TimeField( blank=True, null=True, verbose_name=_("Start time")) end_time = dd.TimeField( blank=True, null=True, verbose_name=_("End time")) # def get_weekly_chunks(obj, ar, qs, today): # if obj.start_time: # qs = qs.filter(start_time__gte=obj.start_time, # start_time__isnull=False) # if obj.end_time: # qs = qs.filter(start_time__lt=obj.end_time, # start_time__isnull=False) # return [e.obj2href(ar, ar.actor.get_calview_div(e, ar)) for e in qs] # @classmethod def get_plannable_entries(cls, obj, qs, ar): # qs = rt.models.cal.Event.objects.all() if obj is cls.HEADER_ROW: return qs.filter(start_time__isnull=True) if obj.start_time: return qs.filter(start_time__gte=obj.start_time, start_time__isnull=False) if obj.end_time: return qs.filter(start_time__lt=obj.end_time, start_time__isnull=False) return qs
class DailyPlannerRow(BabelDesignated, Sequenced, Plannable): class Meta: app_label = 'calview' abstract = dd.is_abstract_model(__name__, 'PlannerRow') verbose_name = _("Planner row") verbose_name_plural = _("Planner rows") ordering = ['start_time','-seqno'] start_time = dd.TimeField( blank=True, null=True, verbose_name=_("Start time")) end_time = dd.TimeField( blank=True, null=True, verbose_name=_("End time")) def get_weekly_chunks(obj, ar, qs, current_week_day): if obj.start_time: qs = qs.filter(start_time__gte=obj.start_time, start_time__isnull=False) if obj.end_time: qs = qs.filter(start_time__lt=obj.end_time, start_time__isnull=False) if not obj.start_time and not obj.end_time: qs = qs.filter(start_time__isnull=True) link = str(current_week_day.day) \ if current_week_day != dd.today() \ else E.b(str(current_week_day.day)) link = E.p(*gen_insert_button( ar.actor, [link], rt.models.cal.Event, ar, current_week_day), align="center") else: link = '' chunks = [e.obj2href(ar, e.colored_calendar_fmt(ar.param_values)) for e in qs] return [link] + chunks
class Task(Component): class Meta: app_label = 'cal' verbose_name = _("Task") verbose_name_plural = _("Tasks") abstract = dd.is_abstract_model(__name__, 'Task') due_date = models.DateField( blank=True, null=True, verbose_name=_("Due date")) due_time = dd.TimeField( blank=True, null=True, verbose_name=_("Due time")) percent = models.IntegerField(_("Duration value"), null=True, blank=True) state = TaskStates.field(default=TaskStates.as_callable('todo')) @classmethod def get_simple_parameters(cls): for p in super(Task, cls).get_simple_parameters(): yield p yield 'state' @classmethod def get_request_queryset(cls, ar, **filter): qs = super(Task, cls).get_request_queryset(ar, **filter) pv = ar.param_values if pv.start_date: qs = qs.filter(start_date__gte=pv.start_date) if pv.end_date: qs = qs.filter(start_date__lte=pv.end_date) return qs @classmethod def on_analyze(cls, lino): # lino.TASK_AUTO_FIELDS = dd.fields_list(cls, cls.DISABLED_AUTO_FIELDS = dd.fields_list( cls, """start_date start_time summary""") super(Task, cls).on_analyze(lino) def __str__(self): return "#" + str(self.pk) def is_user_modified(self): return self.state != TaskStates.todo
class Entry(UserAuthored, Controllable, CombinedDateTime, Previewable, Publishable): """A blog entry is a short article with a title, published on a given date and time by a given user. """ class Meta: app_label = 'blogs' verbose_name = _("Blog Entry") verbose_name_plural = _("Blog Entries") title = models.CharField(_("Heading"), max_length=200, blank=True) pub_date = models.DateField( _("Publication date"), blank=True, null=True) pub_time = dd.TimeField( _("Publication time"), blank=True, null=True) entry_type = dd.ForeignKey('blogs.EntryType', blank=True, null=True) language = dd.LanguageField() def __str__(self): if self.pub_date: return _("{} by {}").format(self.pub_date, self.user) return u'%s #%s' % (self._meta.verbose_name, self.pk) def on_create(self, ar): """ Sets the :attr:`pub_date` and :attr:`pub_time` to now. """ if not settings.SITE.loading_from_dump: self.set_datetime('pub', timezone.now()) self.language = ar.get_user().language super(Entry, self).on_create(ar) add_interest = AddInterestField() @classmethod def get_dashboard_items(cls, user): qs = cls.objects.filter(Q(pub_date__isnull=False)).order_by("-pub_date") return qs[:5]
class Ended(CombinedDateTime): """ Mixin for models with two fields :attr:`end_date` and :attr:`end_time`. .. attribute:: end_date .. attribute:: end_time """ class Meta: abstract = True end_date = models.DateField( blank=True, null=True, verbose_name=_("End Date")) end_time = dd.TimeField( blank=True, null=True, verbose_name=_("End Time")) def get_duration(self): """Return the duration in hours.""" if not self.start_date: return None if not self.start_time: return None if not self.end_time: return None ed = self.end_date or self.start_date st = datetime.datetime.combine(self.start_date, self.start_time) et = datetime.datetime.combine(ed, self.end_time) if et < st: return None # negative duration not supported # print 20151127, repr(et), repr(st) return Duration(et - st) @dd.virtualfield(dd.QuantityField(_("Duration"))) def duration(self, ar): return self.get_duration()
class Task(Component): class Meta: app_label = 'cal' verbose_name = _("Task") verbose_name_plural = _("Tasks") abstract = dd.is_abstract_model(__name__, 'Task') due_date = models.DateField(blank=True, null=True, verbose_name=_("Due date")) due_time = dd.TimeField(blank=True, null=True, verbose_name=_("Due time")) # ~ done = models.BooleanField(_("Done"),default=False) # iCal:COMPLETED # iCal:PERCENT percent = models.IntegerField(_("Duration value"), null=True, blank=True) state = TaskStates.field( default=TaskStates.as_callable('todo')) # iCal:STATUS # def before_ui_save(self, ar, **kw): # if self.state == TaskStates.todo: # self.state = TaskStates.started # return super(Task, self).before_ui_save(ar, **kw) # def on_user_change(self,request): # if not self.state: # self.state = TaskState.todo # self.user_modified = True def is_user_modified(self): return self.state != TaskStates.todo @classmethod def on_analyze(cls, lino): # lino.TASK_AUTO_FIELDS = dd.fields_list(cls, cls.DISABLED_AUTO_FIELDS = dd.fields_list( cls, """start_date start_time summary""") super(Task, cls).on_analyze(lino)
class Note(TypedPrintable, UserAuthored, Controllable, Feasible, ContactRelated, mixins.ProjectRelated, ChangeNotifier, UploadController, Mailable): manager_roles_required = dd.login_required(OfficeStaff) class Meta: app_label = 'notes' abstract = dd.is_abstract_model(__name__, 'Note') verbose_name = _("Note") verbose_name_plural = _("Notes") date = models.DateField( verbose_name=_('Date'), default=dd.today) time = dd.TimeField( blank=True, null=True, verbose_name=_("Time"), default=timezone.now) type = dd.ForeignKey( 'notes.NoteType', blank=True, null=True, verbose_name=_('Note Type (Content)')) event_type = dd.ForeignKey( 'notes.EventType', blank=True, null=True, verbose_name=_('Event Type (Form)')) subject = models.CharField(_("Subject"), max_length=200, blank=True) body = dd.RichTextField(_("Body"), blank=True, format='html') language = dd.LanguageField() def __str__(self): if self.event_type_id: return u'%s #%s' % (self.event_type, self.pk) return u'%s #%s' % (self._meta.verbose_name, self.pk) def summary_row(self, ar, **kw): #~ s = super(Note,self).summary_row(ui,rr) s = super(Note, self).summary_row(ar) #~ s = contacts.ContactDocument.summary_row(self,ui,rr) if self.subject: s += [' ', self.subject] return s def get_mailable_type(self): return self.type def get_print_language(self): return self.language def get_change_owner(self): return self.project # def get_change_observers(self, ar=None): # # in lino_welfare the project is pcsw.Client # prj = self.project # if isinstance(prj, ChangeNotifier): # for u in prj.get_change_observers(ar): # yield u def get_change_info(self, ar, cw): yield E.p( gettext("Subject"), ': ', self.subject, E.br(), gettext("Client"), ': ', ar.obj2memo(self.project))