Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ParsePy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ParsePy
Commits
da62808e
Commit
da62808e
authored
Nov 04, 2012
by
Billy Tobon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GeoPoint Support added
GeoPoints use string with format POINT(lat lon)
parent
205a4af1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
+20
-0
.gitignore
+6
-0
__init__.py
+12
-0
tests.py
+2
-0
No files found.
.gitignore
0 → 100644
View file @
da62808e
*.pyc
.DS_Store
settings_local.py
__init__.py
View file @
da62808e
...
@@ -17,6 +17,7 @@ import base64
...
@@ -17,6 +17,7 @@ import base64
import
json
import
json
import
datetime
import
datetime
import
collections
import
collections
import
re
API_ROOT
=
'https://api.parse.com/1/classes'
API_ROOT
=
'https://api.parse.com/1/classes'
...
@@ -117,6 +118,10 @@ class ParseObject(ParseBase):
...
@@ -117,6 +118,10 @@ class ParseObject(ParseBase):
response_dict
=
self
.
_executeCall
(
uri
,
'GET'
)
response_dict
=
self
.
_executeCall
(
uri
,
'GET'
)
self
.
_populateFromDict
(
response_dict
)
self
.
_populateFromDict
(
response_dict
)
def
_isGeoPoint
(
self
,
value
):
if
isinstance
(
value
,
str
):
return
re
.
search
(
"
\\
bPOINT
\\
(
\\
b([-+]?
\\
d*
\\
.
\\
d+|
\\
d+) ([-+]?
\\
d*
\\
.
\\
d+|
\\
d+)
\\
)"
,
value
,
re
.
I
)
def
_populateFromDict
(
self
,
attrs_dict
):
def
_populateFromDict
(
self
,
attrs_dict
):
if
'objectId'
in
attrs_dict
:
if
'objectId'
in
attrs_dict
:
self
.
_object_id
=
attrs_dict
[
'objectId'
]
self
.
_object_id
=
attrs_dict
[
'objectId'
]
...
@@ -145,6 +150,11 @@ class ParseObject(ParseBase):
...
@@ -145,6 +150,11 @@ class ParseObject(ParseBase):
elif
type
(
value
)
==
ParseBinaryDataWrapper
:
elif
type
(
value
)
==
ParseBinaryDataWrapper
:
value
=
{
'__type'
:
'Bytes'
,
value
=
{
'__type'
:
'Bytes'
,
'base64'
:
base64
.
b64encode
(
value
)}
'base64'
:
base64
.
b64encode
(
value
)}
elif
self
.
_isGeoPoint
(
value
):
coordinates
=
re
.
findall
(
r'[-+]?\d*\.\d+|\d+'
,
value
)
value
=
{
'__type'
:
'GeoPoint'
,
'latitude'
:
float
(
coordinates
[
0
]),
'longitude'
:
float
(
coordinates
[
1
])}
return
(
key
,
value
)
return
(
key
,
value
)
...
@@ -159,6 +169,8 @@ class ParseObject(ParseBase):
...
@@ -159,6 +169,8 @@ class ParseObject(ParseBase):
elif
value
[
'__type'
]
==
'Bytes'
:
elif
value
[
'__type'
]
==
'Bytes'
:
value
=
ParseBinaryDataWrapper
(
base64
.
b64decode
(
value
=
ParseBinaryDataWrapper
(
base64
.
b64decode
(
value
[
'base64'
]))
value
[
'base64'
]))
elif
value
[
'__type'
]
==
'GeoPoint'
:
value
=
'POINT(
%
s
%
s)'
%
(
value
[
'latitude'
],
value
[
'longitude'
])
else
:
else
:
raise
Exception
(
'Invalid __type.'
)
raise
Exception
(
'Invalid __type.'
)
...
...
tests.py
View file @
da62808e
...
@@ -26,6 +26,7 @@ def test_obj(saved=False):
...
@@ -26,6 +26,7 @@ def test_obj(saved=False):
ret
.
score
=
1337
ret
.
score
=
1337
ret
.
playerName
=
"Sean Plott"
ret
.
playerName
=
"Sean Plott"
ret
.
cheatMode
=
False
ret
.
cheatMode
=
False
ret
.
location
=
"POINT(30.0 -43.21)"
#"POINT(30 -43.21)"
if
saved
:
if
saved
:
ret
.
save
()
ret
.
save
()
return
ret
return
ret
...
@@ -48,6 +49,7 @@ class TestParseObjectAndQuery(unittest.TestCase):
...
@@ -48,6 +49,7 @@ class TestParseObjectAndQuery(unittest.TestCase):
# TODO: str vs unicode
# TODO: str vs unicode
#self.assertEqual(o.playerName.__class__, unicode)
#self.assertEqual(o.playerName.__class__, unicode)
self
.
assertEqual
(
o
.
cheatMode
.
__class__
,
bool
)
self
.
assertEqual
(
o
.
cheatMode
.
__class__
,
bool
)
self
.
assertEqual
(
o
.
location
,
"POINT(30.0 -43.21)"
)
def
test_object
(
self
):
def
test_object
(
self
):
"""Test the creation, retrieval and updating of a ParseObject"""
"""Test the creation, retrieval and updating of a ParseObject"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment