def read(self, request, task_id, *args, **kwargs): try: task = Task.objects.get(pk=task_id) except Task.DoesNotExist: return rc.NOT_FOUND if not request.user.get_profile().has_permission(task, mode='x'): return rc.FORBIDDEN if not task.is_being_done_by(request.user.get_profile()): task_time_slot = TaskTimeSlot(task=task, time_from=datetime.now(), user=request.user.get_profile()) task_time_slot.save() task_time_slot.set_user_from_request(request) return task_time_slot return ("The task isn't in progress", 401)
def create_instance(self, request, *args, **kwargs): return TaskTimeSlot(task=request.task, time_to=datetime.now(), user=request.user.get_profile())
def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects self.group, created = Group.objects.get_or_create(name='test') duser, created = DjangoUser.objects.get_or_create( username=self.username) duser.set_password(self.password) duser.save() self.user, created = User.objects.get_or_create(user=duser) self.user.save() perspective, created = Perspective.objects.get_or_create( name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.project = Project(name='test', manager=self.contact, client=self.contact) self.project.set_default_user() self.project.save() self.status = TaskStatus(name='test') self.status.set_default_user() self.status.save() self.milestone = Milestone(name='test', project=self.project, status=self.status) self.milestone.set_default_user() self.milestone.save() self.task = Task(name='test', project=self.project, status=self.status, priority=3) self.task.set_default_user() self.task.save() self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user) self.time_slot.set_default_user() self.time_slot.save() self.parent = Project(name='test') self.parent.set_default_user() self.parent.save() self.parent_task = Task(name='test', project=self.project, status=self.status, priority=3) self.parent_task.set_default_user() self.parent_task.save() self.client = Client() self.prepared = True
def setUp(self): "Initial Setup" if not self.prepared: # Clean up first Object.objects.all().delete() User.objects.all().delete() # Create objects try: self.group = Group.objects.get(name='test') except Group.DoesNotExist: Group.objects.all().delete() self.group = Group(name='test') self.group.save() try: self.user = DjangoUser.objects.get(username=self.username) self.user.set_password(self.password) try: self.profile = self.user.get_profile() except Exception: User.objects.all().delete() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() except DjangoUser.DoesNotExist: User.objects.all().delete() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() try: perspective = Perspective.objects.get(name='default') except Perspective.DoesNotExist: Perspective.objects.all().delete() perspective = Perspective(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.project = Project(name='test', manager=self.contact, client=self.contact) self.project.set_default_user() self.project.save() self.status = TaskStatus(name='test') self.status.set_default_user() self.status.save() self.milestone = Milestone(name='test', project=self.project, status=self.status) self.milestone.set_default_user() self.milestone.save() self.task = Task(name='test', project=self.project, status=self.status, priority=3) self.task.set_default_user() self.task.save() self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user.get_profile()) self.time_slot.set_default_user() self.time_slot.save() self.parent = Project(name='test') self.parent.set_default_user() self.parent.save() self.parent_task = Task(name='test', project=self.project, status=self.status, priority=3) self.parent_task.set_default_user() self.parent_task.save() self.client = Client() self.prepared = True