message date in the Thread. Also when deleting the last post in the thread. The thread itself should be removed. """ t = self.thread try: latest_message = Message.objects.exclude(pk=self.id).filter(thread=t.pk).latest('created_at') latest_message_time = latest_message.created_at # Update the thread t.message_count = t.messages.exclude(pk=self.id).count() t.latest_message_time = latest_message_time t.save() except Message.DoesNotExist: # Remove empty thread t.delete() super(Message, self).delete() class Meta: ordering = ('created_at',) verbose_name = _('message') verbose_name_plural = _('messages') def __unicode__(self): return "%s" % self.id blactivity.register(Thread) blactivity.register(Message)
if object_id: ctype = ContentType.objects.get_for_model(Task) event = Event.objects.create( title=title, location=location, event_type=event_type, project=project, created_by=created_by, content_type=ctype, object_id=object_id, ) event.attending.add(created_by) if note is not None: event.notes.create(note=note) start_time = start_time or datetime.now().replace( minute=0, second=0, microsecond=0 ) end_time = end_time or start_time + agenda_settings.DEFAULT_OCCURRENCE_DURATION event.add_occurrences(start_time, end_time, **rrule_params) return event blactivity.register(Event)
def toggle(self): # Move the task correctly completed = not self.completed # Change itself self.completed = completed self.save() # Trickle down for d in self.get_descendants(): d.completed = completed d.save() # If it's a leaf check what the consequences are above ancestors = self.get_ancestors() if len(ancestors) > 0: if not completed: for a in ancestors: a.completed = completed a.save() else: for a in ancestors.reverse(): if len(a.get_children().filter(completed=False)) == 0: a.completed = True a.save() return True blactivity.register(Task) post_save.connect(Task.my_objects.task_is_event, sender=Task)
return total_value @property def latest_activity(self): """ Return latest activity """ from busylissy.blactivity.models import Activity act = Activity.objects.get_activities_for_project(self.slug) if act: return act[0].time else: date = datetime.datetime(self.date.year, self.date.month, self.date.day) return date @property def progress(self): """ Progress of project """ total = self.progress_value() progress = self.progress_value(completed=True) if total > 0: return progress / total * 100 else: return 0 blactivity.register(Project) post_save.connect(Project.objects.create_project_dir, sender=Project)
return total_value @property def latest_activity(self): """ Return latest activity """ from busylissy.blactivity.models import Activity act = Activity.objects.get_activities_for_project(self.slug) if act: return act[0].time else: date = datetime.datetime(self.date.year, self.date.month, self.date.day) return date @property def progress(self): """ Progress of project """ total = self.progress_value() progress = self.progress_value(completed=True) if total > 0: return progress/total*100 else: return 0 blactivity.register(Project) post_save.connect(Project.objects.create_project_dir, sender=Project)