Make datetime handline offset-aware. Now requires pytz. Fixes #142.

This commit is contained in:
Ross Poulton 2013-01-23 10:59:12 +11:00
parent 13702852e1
commit 341a40b9ae
6 changed files with 24 additions and 28 deletions

View File

@ -7,7 +7,6 @@ forms.py - Definitions of newforms-based forms for creating and maintaining
tickets.
"""
from datetime import datetime
from StringIO import StringIO
from django import forms
@ -15,6 +14,7 @@ from django.forms import extras
from django.conf import settings
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from django.utils import timezone
from helpdesk.lib import send_templated_mail, safe_template_context
from helpdesk.models import Ticket, Queue, FollowUp, Attachment, IgnoreEmail, TicketCC, CustomField, TicketCustomFieldValue, TicketDependency
@ -243,7 +243,7 @@ class TicketForm(forms.Form):
t = Ticket( title = self.cleaned_data['title'],
submitter_email = self.cleaned_data['submitter_email'],
created = datetime.now(),
created = timezone.now(),
status = Ticket.OPEN_STATUS,
queue = q,
description = self.cleaned_data['body'],
@ -273,7 +273,7 @@ class TicketForm(forms.Form):
f = FollowUp( ticket = t,
title = _('Ticket Opened'),
date = datetime.now(),
date = timezone.now(),
public = True,
comment = self.cleaned_data['body'],
user = user,
@ -462,7 +462,7 @@ class PublicTicketForm(forms.Form):
t = Ticket(
title = self.cleaned_data['title'],
submitter_email = self.cleaned_data['submitter_email'],
created = datetime.now(),
created = timezone.now(),
status = Ticket.OPEN_STATUS,
queue = q,
description = self.cleaned_data['body'],
@ -484,7 +484,7 @@ class PublicTicketForm(forms.Form):
f = FollowUp(
ticket = t,
title = _('Ticket Opened Via Web'),
date = datetime.now(),
date = timezone.now(),
public = True,
comment = self.cleaned_data['body'],
)

View File

@ -7,12 +7,11 @@ models.py - Model (and hence database) definitions. This is the core of the
helpdesk structure.
"""
from datetime import datetime
from django.contrib.auth.models import User
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils import timezone
from helpdesk.settings import HAS_TAG_SUPPORT
if HAS_TAG_SUPPORT:
@ -451,12 +450,12 @@ class Ticket(models.Model):
def save(self, *args, **kwargs):
if not self.id:
# This is a new ticket as no ID yet exists.
self.created = datetime.now()
self.created = timezone.now()
if not self.priority:
self.priority = 3
self.modified = datetime.now()
self.modified = timezone.now()
super(Ticket, self).save(*args, **kwargs)
@ -489,7 +488,7 @@ class FollowUp(models.Model):
date = models.DateTimeField(
_('Date'),
default = datetime.now()
default = timezone.now()
)
title = models.CharField(
@ -541,7 +540,7 @@ class FollowUp(models.Model):
def save(self, *args, **kwargs):
t = self.ticket
t.modified = datetime.now()
t.modified = timezone.now()
t.save()
super(FollowUp, self).save(*args, **kwargs)
@ -857,7 +856,7 @@ class KBItem(models.Model):
def save(self, *args, **kwargs):
if not self.last_updated:
self.last_updated = datetime.now()
self.last_updated = timezone.now()
return super(KBItem, self).save(*args, **kwargs)
def _score(self):
@ -1038,7 +1037,7 @@ class IgnoreEmail(models.Model):
def save(self, *args, **kwargs):
if not self.date:
self.date = datetime.now()
self.date = timezone.now()
return super(IgnoreEmail, self).save(*args, **kwargs)
def test(self, email):

View File

@ -11,15 +11,13 @@ The API documentation can be accessed by visiting http://helpdesk/api/help/
through templates/helpdesk/help_api.html.
"""
from datetime import datetime
from django import forms
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import loader, Context
from django.utils import simplejson
from django.utils import simplejson, timezone
from django.views.decorators.csrf import csrf_exempt
from helpdesk.forms import TicketForm
@ -182,7 +180,7 @@ class API:
f = FollowUp(
ticket=ticket,
date=datetime.now(),
date=timezone.now(),
comment=message,
user=self.request.user,
title='Comment Added',
@ -257,7 +255,7 @@ class API:
f = FollowUp(
ticket=ticket,
date=datetime.now(),
date=timezone.now(),
comment=resolution,
user=self.request.user,
title='Resolved',

View File

@ -7,8 +7,6 @@ views/public.py - All public facing views, eg non-staff (no authentication
required) views.
"""
from datetime import datetime
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.shortcuts import render_to_response, get_object_or_404

View File

@ -24,6 +24,7 @@ from django.shortcuts import render_to_response, get_object_or_404
from django.template import loader, Context, RequestContext
from django.utils.translation import ugettext as _
from django.utils.html import escape
from django.utils import timezone
from django import forms
from helpdesk.forms import TicketForm, UserSettingsForm, EmailIgnoreForm, EditTicketForm, TicketCCForm, EditFollowUpForm, TicketDependencyForm
@ -339,7 +340,7 @@ def update_ticket(request, ticket_id, public=False):
if ticket.due_date:
due_date = ticket.due_date
else:
due_date = datetime.now()
due_date = timezone.now()
due_date = due_date.replace(due_date_year, due_date_month, due_date_day)
tags = request.POST.get('tags', '')
@ -369,7 +370,7 @@ def update_ticket(request, ticket_id, public=False):
if owner is -1 and ticket.assigned_to:
owner = ticket.assigned_to.id
f = FollowUp(ticket=ticket, date=datetime.now(), comment=comment)
f = FollowUp(ticket=ticket, date=timezone.now(), comment=comment)
if request.user.is_staff or helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE:
f.user = request.user
@ -596,22 +597,22 @@ def mass_update(request):
if action == 'assign' and t.assigned_to != user:
t.assigned_to = user
t.save()
f = FollowUp(ticket=t, date=datetime.now(), title=_('Assigned to %(username)s in bulk update' % {'username': user.username}), public=True, user=request.user)
f = FollowUp(ticket=t, date=timezone.now(), title=_('Assigned to %(username)s in bulk update' % {'username': user.username}), public=True, user=request.user)
f.save()
elif action == 'unassign' and t.assigned_to is not None:
t.assigned_to = None
t.save()
f = FollowUp(ticket=t, date=datetime.now(), title=_('Unassigned in bulk update'), public=True, user=request.user)
f = FollowUp(ticket=t, date=timezone.now(), title=_('Unassigned in bulk update'), public=True, user=request.user)
f.save()
elif action == 'close' and t.status != Ticket.CLOSED_STATUS:
t.status = Ticket.CLOSED_STATUS
t.save()
f = FollowUp(ticket=t, date=datetime.now(), title=_('Closed in bulk update'), public=False, user=request.user, new_status=Ticket.CLOSED_STATUS)
f = FollowUp(ticket=t, date=timezone.now(), title=_('Closed in bulk update'), public=False, user=request.user, new_status=Ticket.CLOSED_STATUS)
f.save()
elif action == 'close_public' and t.status != Ticket.CLOSED_STATUS:
t.status = Ticket.CLOSED_STATUS
t.save()
f = FollowUp(ticket=t, date=datetime.now(), title=_('Closed in bulk update'), public=True, user=request.user, new_status=Ticket.CLOSED_STATUS)
f = FollowUp(ticket=t, date=timezone.now(), title=_('Closed in bulk update'), public=True, user=request.user, new_status=Ticket.CLOSED_STATUS)
f.save()
# Send email to Submitter, Owner, Queue CC
context = safe_template_context(t)
@ -953,7 +954,7 @@ def hold_ticket(request, ticket_id, unhold=False):
ticket = ticket,
user = request.user,
title = title,
date = datetime.now(),
date = timezone.now(),
public = True,
)
f.save()

View File

@ -133,6 +133,6 @@ setup(
package_data=find_package_data("helpdesk", only_in_packages=False),
include_package_data=True,
zip_safe=False,
install_requires=['setuptools'],
install_requires=['setuptools', 'pytz'],
)