How to use the pendulum.models.Entry.objects.get function in pendulum

To help you get started, we’ve selected a few pendulum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codekoala / django-pendulum / pendulum / tests.py View on Github external
"""
        Try to update a good, closed entry to end in the future
        """
        id = 3
        now = datetime.now()
        values = {'project': 2,
                  'activity': 2,
                  'start_time': ffd(now + timedelta(hours=-2)),
                  'end_time': ffd(now + timedelta(hours=1)),
                  'comments': 'New comments'}

        response = self.post_response(id, values)
        self.assertEquals(response.status_code, 200)

        # make sure the information is still as in the fixture
        entry = Entry.objects.get(pk=id)
        self.assertNotEquals(entry.project.id, values['project'])
        self.assertNotEquals(entry.activity.id, values['activity'])
        self.assertNotEquals(ffd(entry.start_time), values['start_time'])
        self.assertNotEquals(ffd(entry.end_time), values['end_time'])
        self.assertNotEquals(entry.comments, values['comments'])
github codekoala / django-pendulum / pendulum / tests.py View on Github external
def performWithIdAndCodes(self, id, get, post):
        entry = Entry.objects.get(pk=id)
        self.assertEquals(self.get_response(id).status_code, get)
        self.assertEquals(self.post_response(id, {'key': entry.delete_key}).status_code, post)
github codekoala / django-pendulum / pendulum / tests.py View on Github external
self.assertEquals(response.status_code, 302)

        # try to close without posting any information
        response = self.post_response(id, {})
        self.assertEquals(response.status_code, 302)

        # try to close posting no activity
        response = self.post_response(id, {'comments': "closing the entry"})
        self.assertEquals(response.status_code, 302)

        # try to close posting minimal information
        response = self.post_response(id, {'activity': 1})
        self.assertEquals(response.status_code, 302)

        # make sure the entry is still open
        entry = Entry.objects.get(pk=id)
        self.assertFalse(entry.is_closed)
github codekoala / django-pendulum / pendulum / tests.py View on Github external
self.assertEquals(response.status_code, 302)

        # try to close without posting any information
        response = self.post_response(id, {})
        self.assertEquals(response.status_code, 302)

        # try to close posting no activity
        response = self.post_response(id, {'comments': "closing the entry"})
        self.assertEquals(response.status_code, 302)

        # try to close posting minimal information
        response = self.post_response(id, {'activity': 1})
        self.assertEquals(response.status_code, 302)

        # make sure the entry is still closed
        entry = Entry.objects.get(pk=id)
        self.assertTrue(entry.is_closed)
        self.assertFalse(entry.is_paused)
github caktus / django-timepiece / pendulum / tests.py View on Github external
def testClosePausedEntry(self):
        #--------------------------------------------------
        # 2. ENTRY THAT IS PAUSED
        id = 2

        # check to make sure that log entry isn't closed
        entry = Entry.objects.get(pk=id)
        self.assertTrue(entry.is_paused)
        self.assertFalse(entry.is_closed)

        # try closing an entry that is paused
        response = self.get_response(id)
        self.assertEquals(response.status_code, 200)

        # try to close without posting any information
        response = self.post_response(id, {})
        self.assertEquals(response.status_code, 302)

        # try to close posting no activity
        response = self.post_response(id, {'comments': "closing the entry"})
        self.assertEquals(response.status_code, 302)

        # try to close posting minimal information
github caktus / django-timepiece / pendulum / tests.py View on Github external
def testUpdatePausedEntry(self):
        #--------------------------------------------------
        # 2. ENTRY THAT IS PAUSED
        id = 2
        now = datetime.now()

        # get a paused entry, and make sure it's paused
        entry = Entry.objects.get(pk=id)
        self.assertTrue(entry.is_paused)

        # try to get the form to update its information
        response = self.get_response(id)
        self.assertEquals(response.status_code, 302)

        # try to update it with no information specified
        response = self.post_response(id, {})
        self.assertEquals(response.status_code, 302)

        # try to update it with a little information specified
        response = self.post_response(id, {'project': 2,
                                           'comments': 'Updating the entry'})
        self.assertEquals(response.status_code, 302)

        # try to update it with all required information
github caktus / django-timepiece / pendulum / tests.py View on Github external
def testUpdateAlreadyClosedEntry(self):
        #--------------------------------------------------
        # 3. ENTRY THAT IS ALREADY CLOSED
        id = 3
        now = datetime.now()
        values = {'project': 2,
                  'activity': 2,
                  'start_time': ffd(now + timedelta(hours=-2)),
                  'end_time': ffd(now),
                  'comments': 'New comments'}

        # make sure the entry is already closed
        entry = Entry.objects.get(pk=id)
        self.assertTrue(entry.is_closed)
        self.assertFalse(entry.is_paused)

        # try to update the new entry with not enough information
        response = self.post_response(id, {})
        self.assertEquals(response.status_code, 200)

        # try various combinations of incomplete data
        response = self.post_response(id, {'project': values['project']})
        self.assertEquals(response.status_code, 200)

        response = self.post_response(id, {'project': values['project'],
                                           'activity': values['activity']})
        self.assertEquals(response.status_code, 200)

        response = self.post_response(id, {'project': values['project'],
github caktus / django-timepiece / pendulum / tests.py View on Github external
"""
        Try to update a good, closed entry to end in the future
        """
        id = 3
        now = datetime.now()
        values = {'project': 2,
                  'activity': 2,
                  'start_time': ffd(now + timedelta(hours=-2)),
                  'end_time': ffd(now + timedelta(hours=1)),
                  'comments': 'New comments'}

        response = self.post_response(id, values)
        self.assertEquals(response.status_code, 200)

        # make sure the information is still as in the fixture
        entry = Entry.objects.get(pk=id)
        self.assertNotEquals(entry.project.id, values['project'])
        self.assertNotEquals(entry.activity.id, values['activity'])
        self.assertNotEquals(ffd(entry.start_time), values['start_time'])
        self.assertNotEquals(ffd(entry.end_time), values['end_time'])
        self.assertNotEquals(entry.comments, values['comments'])
github caktus / django-timepiece / pendulum / views.py View on Github external
def clock_out(request, entry_id):
    """
    Allow a user to clock out or close a log entry.  If this method is invoked
    via a GET request, the user is presented with a form that allows them to
    select an activity type and enter comments about their activities.  Only
    the activity is required.  If this method is invoked via a POST request,
    the form is validated.  If the form data are valid, the entry is closed and
    the user is redirected to the entry list.  If the form data are invalid,
    the user is presented with the form again until they abort or they enter
    valid data.
    """

    try:
        # grab the entry from the database
        entry = pendulum.Entry.objects.get(pk=entry_id,
                                  user=request.user,
                                  end_time__isnull=True)
    except:
        # if this entry does not exist, redirect to the entry list
        request.user.message_set.create(message='Invalid log entry.')
        return HttpResponseRedirect(reverse('pendulum-entries'))

    if request.method == 'POST':
        # populate the form with the posted data
        form = ClockOutForm(request.POST)

        # validate the form data
        if form.is_valid():
            # the form is valid, save the entry
            entry.clock_out(form.cleaned_data['activity'],
                            form.cleaned_data['comments'])