Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: a9c5eb0df0
Fetching contributors…

Cannot retrieve contributors at this time

35 lines (30 sloc) 1.137 kB
# __BEGIN_LICENSE__
# Copyright (C) 2008-2010 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# __END_LICENSE__
from django import forms
from geocamMemo.models import MemoMessage
from datetime import datetime
import re
class GeolocationTimestampDateTimeFormField(forms.DateTimeField):
def clean(self, value):
""" datetime from geolocation timestamp
ex: Sat Feb 19 2011 15:37:53 GMT-0800 (PST)"""
try:
if value is not None:
m = re.match(r"(\S+ \S+ \d+ \d+ \d+\:\d+\:\d+)", value)
if m:
clean_date = m.group(1)
dt = datetime.strptime(clean_date, "%a %b %d %Y %H:%M:%S")
return dt
else:
return None
else:
return None
except:
raise forms.ValidationError
class MemoMessageForm(forms.ModelForm):
position_timestamp = GeolocationTimestampDateTimeFormField()
class Meta:
model = MemoMessage
Jump to Line
Something went wrong with that request. Please try again.