Ejemplo n.º 1
0
    def test_is_tracking_active_record(self):
        record = TimeRecord(project=self.subject, user=self.user)
        record.start_time = datetime.now(tz=timezone.utc) - timedelta(hours=1)
        record.save()

        self.subject.timerecord_set.add(record)
        self.subject.save()

        self.assertIs(True, self.subject.is_tracking(self.user))
Ejemplo n.º 2
0
    def test_last_updated_only_start(self):
        record = TimeRecord(project=self.subject, user=self.user)
        record.start_time = datetime.now(tz=timezone.utc) - timedelta(hours=1)
        record.save()

        self.subject.timerecord_set.add(record)
        self.subject.save()

        self.assertEqual('Never updated', self.subject.last_updated())
Ejemplo n.º 3
0
    def test_last_updated(self):
        record = TimeRecord(project=self.subject, user=self.user)
        record.start_time = datetime.now(tz=timezone.utc) - timedelta(hours=1)
        record.end_time = datetime.now(tz=timezone.utc)
        record.save()

        self.subject.timerecord_set.add(record)
        self.subject.save()

        self.assertEqual('Last updated a moment ago', self.subject.last_updated())
Ejemplo n.º 4
0
def start(request, organization, project_id):
    project = get_object_or_404(Project, id=project_id)
    setting, _ = Setting.objects.get_or_create(user=request.user)

    if not project.is_member(request.user):
        return HttpResponseForbidden()

    if request.user.is_tracking() and not setting.allow_parallel_tracking:
        for entry in request.user.get_tracking_records():
            entry.end_time = datetime.now().replace(second=0, microsecond=0)
            entry.save()

    entry = TimeRecord(project_id=project_id, user=request.user)
    entry.start_time = datetime.now().replace(second=0, microsecond=0)
    entry.save()

    target = request.GET.get('from', 'tracker:project/timetable')
    return redirect(target, organization, project_id)
Ejemplo n.º 5
0
def split(request, organization, project_id, record_id):
    entry = get_object_or_404(TimeRecord, id=record_id)

    if not entry.user == request.user:
        return HttpResponseForbidden()

    entry2 = TimeRecord(user=entry.user, project=entry.project)
    entry2.end_time = entry.end_time

    duration = (entry.end_time - entry.start_time) // 2
    entry.end_time = entry.end_time - duration
    entry.end_time.replace(second=0)
    entry2.start_time = entry.end_time

    entry.save()
    entry2.save()
    return redirect('tracker:project/timetable',
                    organization=organization,
                    project_id=project_id)
Ejemplo n.º 6
0
def create(request, organization, project_id):
    organization = get_object_or_404(Organization, name=organization)
    project = get_object_or_404(Project, id=project_id)

    setting, _ = Setting.objects.get_or_create(user=request.user)
    timezone = pytz.timezone(str(setting.timezone))

    if not project.is_member(request.user):
        return HttpResponseForbidden()

    entry = TimeRecord(project=project, user=request.user)
    form = TimeRecordForm(request.POST)

    start_time = datetime.strptime(form.data['start_time'], "%Y-%m-%dT%H:%M")
    entry.start_time = timezone.localize(start_time, is_dst=None)

    if form.data['end_time']:
        end_time = datetime.strptime(form.data['end_time'], "%Y-%m-%dT%H:%M")
        entry.end_time = timezone.localize(end_time, is_dst=None)

    entry.save()
    return redirect('tracker:project/timetable',
                    organization=organization,
                    project_id=project_id)
Ejemplo n.º 7
0
    def test_duration(self):
        subject = TimeRecord()
        subject.start_time = datetime(2000, 1, 1, 8, 0, 0)
        subject.end_time = datetime(2000, 1, 1, 9, 0, 0)

        self.assertEqual(timedelta(hours=1), subject.duration())
Ejemplo n.º 8
0
    def test_duration_incomplete(self):
        subject = TimeRecord()
        subject.start_time = datetime(2000, 1, 1, 8, 0, 0)

        self.assertEqual(timedelta(0, 0), subject.duration())