My favorites
▼
|
Sign in
jaikuengine
Jaiku, now with more open source!
Project Home
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
common
/
properties.py
r159
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python2.4
# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = 'termie@google.com (Andy Smith)'
import re
import time, datetime
try:
import cPickle as pickle
except ImportError:
import pickle
from google.appengine.ext import db
from google.appengine.api.datastore_types import Blob
DJANGO_DATE = "%Y-%m-%d"
DJANGO_TIME = "%H:%M:%S"
class DateTimeProperty(db.DateTimeProperty):
def validate(self, value):
"""Validate a datetime, attempt to convert from string
Returns:
A valid datetime object
"""
# XXX termie: pretty naive at this point, ask for forgiveness
try:
us = 0
m_fractional = re.search('(.*)\.(\d+)$', value)
if (m_fractional):
value = m_fractional.group(1)
fractional_s = m_fractional.group(2)
scaled_to_us = fractional_s + '0' * (6 - len(fractional_s))
truncated_to_us = scaled_to_us[0:6]
us = int(truncated_to_us)
t = time.strptime(value, "%s %s"%(DJANGO_DATE, DJANGO_TIME))
t = (t)[0:6] + (us,)
d = datetime.datetime(*t)
value = d
except ValueError, e:
# eat the error
pass
except TypeError, e:
# we passed it a datetime, probably, let the orignal handle this
pass
value = super(DateTimeProperty, self).validate(value)
return value
class DictProperty(db.Property):
def validate(self, value):
value = super(DictProperty, self).validate(value)
if not isinstance(value, dict):
raise Exception("NOT A DICT %s" % value)
return value
def default_value(self):
return {}
def datastore_type(self):
return Blob
def get_value_for_datastore(self, model_instance):
value = super(DictProperty, self).get_value_for_datastore(model_instance)
return Blob(pickle.dumps(value, protocol=-1))
def make_value_from_datastore(self, model_instance):
value = super(DictProperty, self).make_value_from_datastore(model_instance)
return pickle.loads(str(value))
Show details
Hide details
Change log
r1
by andyster on Mar 13, 2009
Diff
initial commit for jaikuengine project
Go to:
/branches
/tags
/trunk
/trunk/CHANGELOG
/trunk/COPYING
/trunk/Makefile
/trunk/README
/trunk/__init__.py
/trunk/actor
/trunk/actor/__init__.py
/trunk/actor/models.py
/trunk/actor/templates
...nk/actor/templates/contacts.html
...nk/actor/templates/contacts.json
...k/actor/templates/followers.html
/trunk/actor/templates/history.atom
/trunk/actor/templates/history.html
/trunk/actor/templates/history.json
/trunk/actor/templates/history.rss
/trunk/actor/templates/invite.html
/trunk/actor/templates/item.html
/trunk/actor/templates/item.json
...nk/actor/templates/overview.atom
...nk/actor/templates/overview.html
...nk/actor/templates/overview.json
/trunk/actor/templates/overview.rss
...actor/templates/people_base.html
...or/templates/settings_badge.html
...tor/templates/settings_base.html
...r/templates/settings_delete.html
...r/templates/settings_design.html
...or/templates/settings_email.html
...or/templates/settings_feeds.html
...actor/templates/settings_im.html
...or/templates/settings_index.html
.../templates/settings_jsbadge.html
...r/templates/settings_mobile.html
...ates/settings_notifications.html
...templates/settings_password.html
...or/templates/settings_photo.html
.../templates/settings_privacy.html
.../templates/settings_profile.html
...mplates/sidebar_privateuser.html
/trunk/actor/tests.py
/trunk/actor/urls.py
/trunk/actor/views.py
/trunk/api
/trunk/api/__init__.py
/trunk/api/models.py
/trunk/api/templates
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 2510 bytes, 81 lines
View raw file
File properties
svn:executable
*
Powered by
Google Project Hosting