-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from uchicago-sg/replicate-to-go-site
Add replication for new inquiries and listings
- Loading branch information
Showing
9 changed files
with
163 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from google.appengine.ext import ndb, db | ||
import urllib2 | ||
import json | ||
from caravel.storage import config | ||
|
||
|
||
class ReplicationMixin(ndb.Model): | ||
|
||
""" | ||
The ReplicatedMixin triggers a background urlfetch call to update this | ||
listing. | ||
""" | ||
|
||
REPLICATION_URL = None | ||
|
||
def encode_for_replication(self): | ||
return self.to_dict() | ||
|
||
def _post_put_hook(self, future): | ||
""" | ||
Write this entity to the third-party site URL. | ||
""" | ||
|
||
if self.REPLICATION_URL: | ||
data = self.encode_for_replication() | ||
data["key"] = self.key.id() | ||
data["replication_key"] = config.replication_key | ||
|
||
urllib2.urlopen(self.REPLICATION_URL, json.dumps(data)) | ||
|
||
return super(ReplicationMixin, self)._post_put_hook(future) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="col-xs-12 col-sm-6 float-to-inline-block listing thumbnail-width"> | ||
<div class="thumbnail"> | ||
<iframe style="width:100%;height:350px" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/view?zoom=14¢er=41.7943%2C-87.5907&key=AIzaSyDzo7LIWcwdUI1_cUBML8HSphyuFBDTs6M" allowfullscreen></iframe> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from caravel.tests import helper | ||
from caravel import model | ||
import json | ||
|
||
|
||
class TestListings(helper.CaravelTestCase): | ||
|
||
def test_creation(self): | ||
# Submit an inquiry. | ||
with self.google_apps_user("visitor@uchicago.edu"): | ||
self.post("/listing_b", data={ | ||
"principal": "buyer@foo.com", | ||
"message": u"message\u2606 goes here", | ||
"csrf_token": self.csrf_token("/listing_b"), | ||
}) | ||
|
||
self.assertEquals( | ||
[(u, json.loads(d)) for u, d in self.webhooks], | ||
[ | ||
("https://go-marketplace.appspot.com/listings", | ||
{u"replication_key": u"~key~", | ||
u"key": u"listing_a", | ||
u"title": u"Listing \u2606A", | ||
u"sold": False, | ||
u"body": u"Body of \u2606A", | ||
u"categories": [u"cars"], | ||
u"photos": [ | ||
{u"large": u"/_ah/gcs/test.appspot.com/listing-a-large", | ||
u"small": u"/_ah/gcs/test.appspot.com/listing-a-small"}, | ||
{u"large": u"/_ah/gcs/test.appspot.com/listing-a2-large", | ||
u"small": u"/_ah/gcs/test.appspot.com/listing-a2-small"} | ||
], | ||
u"posted_at": self.listing_a.posted_at.isoformat(), | ||
u"price": 3.1, | ||
u"seller": { | ||
u"email": u"seller-a@uchicago.edu", | ||
u"validated": True}, | ||
u"moderated": True}), | ||
("https://go-marketplace.appspot.com/listings", | ||
{u"replication_key": u"~key~", | ||
u"key": u"listing_b", | ||
u"title": u"Listing \u2606B", | ||
u"sold": False, | ||
u"body": u"Body of \u2606B", | ||
u"categories": [u"apartments"], | ||
u"photos": [ | ||
{u"large": u"/_ah/gcs/test.appspot.com/listing-b-large", | ||
u"small": u"/_ah/gcs/test.appspot.com/listing-b-small"}, | ||
{u"large": u"/_ah/gcs/test.appspot.com/listing-b2-large", | ||
u"small": u"/_ah/gcs/test.appspot.com/listing-b2-small"} | ||
], | ||
u"posted_at": self.listing_b.posted_at.isoformat(), | ||
u"price": 71.1, | ||
u"seller": { | ||
u"email": u"seller-b@uchicago.edu", | ||
u"validated": False}, | ||
u"moderated": True}), | ||
("https://go-marketplace.appspot.com/inquiries", | ||
{u"key": 11, | ||
u"listing": "listing_b", | ||
u"message": u"message\u2606 goes here", | ||
u"moderated": True, | ||
u"replication_key": u"~key~", | ||
u"sender": { | ||
u"email": u"visitor@uchicago.edu", u"validated": True} | ||
}) | ||
]) |
Empty file.
Empty file.