draft of resource-to-resource resolution
This commit is contained in:
parent
bc32466ff7
commit
ae5619ec73
5 changed files with 62 additions and 7 deletions
7
angular_app/js/controllers.js
vendored
7
angular_app/js/controllers.js
vendored
|
@ -74,10 +74,13 @@ eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
eventManControllers.controller('PersonDetailsCtrl', ['$scope', 'Person', '$routeParams',
|
eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$routeParams', 'Person', 'Action',
|
||||||
function ($scope, Person, $routeParams) {
|
function ($scope, $routeParams, Person, Action) {
|
||||||
if ($routeParams.id) {
|
if ($routeParams.id) {
|
||||||
$scope.person = Person.get($routeParams);
|
$scope.person = Person.get($routeParams);
|
||||||
|
Action.get({person_id: $routeParams.id}, function(data) {
|
||||||
|
$scope.actions = angular.fromJson(data).actions;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// store a new Person or update an existing one
|
// store a new Person or update an existing one
|
||||||
$scope.save = function() {
|
$scope.save = function() {
|
||||||
|
|
5
angular_app/js/services.js
vendored
5
angular_app/js/services.js
vendored
|
@ -3,6 +3,11 @@
|
||||||
/* Services that are used to interact with the backend. */
|
/* Services that are used to interact with the backend. */
|
||||||
var eventManServices = angular.module('eventManServices', ['ngResource']);
|
var eventManServices = angular.module('eventManServices', ['ngResource']);
|
||||||
|
|
||||||
|
eventManServices.factory('Action', ['$resource',
|
||||||
|
function($resource) {
|
||||||
|
return $resource('actions');
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
|
||||||
eventManServices.factory('Event', ['$resource',
|
eventManServices.factory('Event', ['$resource',
|
||||||
function($resource) {
|
function($resource) {
|
||||||
|
|
|
@ -18,4 +18,23 @@
|
||||||
|
|
||||||
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>
|
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div class="panel panel-primary table-striped top5">
|
||||||
|
<div class="panel-heading">Actions</div>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Action</th>
|
||||||
|
<th>Event ID</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr ng-repeat="action in actions">
|
||||||
|
<td>{{action.action}}</td>
|
||||||
|
<td>{{action.event_id}}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ class RootHandler(BaseHandler):
|
||||||
angular_app_path = os.path.join(os.path.dirname(__file__), "angular_app")
|
angular_app_path = os.path.join(os.path.dirname(__file__), "angular_app")
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def get(self):
|
def get(self, *args, **kwargs):
|
||||||
# serve the ./angular_app/index.html file
|
# serve the ./angular_app/index.html file
|
||||||
with open(self.angular_app_path + "/index.html", 'r') as fd:
|
with open(self.angular_app_path + "/index.html", 'r') as fd:
|
||||||
self.write(fd.read())
|
self.write(fd.read())
|
||||||
|
@ -57,7 +57,15 @@ class CollectionHandler(BaseHandler):
|
||||||
collection = None
|
collection = None
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def get(self, id_=None):
|
def get(self, id_=None, resource=None, **kwargs):
|
||||||
|
if resource:
|
||||||
|
method = getattr(self, 'handle_%s' % resource, None)
|
||||||
|
if method and callable(method):
|
||||||
|
try:
|
||||||
|
self.write(method(id_, **kwargs))
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
pass
|
||||||
if id_ is not None:
|
if id_ is not None:
|
||||||
# read a single document
|
# read a single document
|
||||||
self.write(self.db.get(self.collection, id_))
|
self.write(self.db.get(self.collection, id_))
|
||||||
|
@ -91,12 +99,29 @@ class PersonsHandler(CollectionHandler):
|
||||||
"""Handle requests for Persons."""
|
"""Handle requests for Persons."""
|
||||||
collection = 'persons'
|
collection = 'persons'
|
||||||
|
|
||||||
|
def handle_events(self, _id, **kwds):
|
||||||
|
return {'events': []}
|
||||||
|
|
||||||
|
|
||||||
class EventsHandler(CollectionHandler):
|
class EventsHandler(CollectionHandler):
|
||||||
"""Handle requests for Events."""
|
"""Handle requests for Events."""
|
||||||
collection = 'events'
|
collection = 'events'
|
||||||
|
|
||||||
|
|
||||||
|
class ActionsHandler(CollectionHandler):
|
||||||
|
"""Handle requests for Actions."""
|
||||||
|
collection = 'actions'
|
||||||
|
|
||||||
|
def get(self, *args, **kwargs):
|
||||||
|
params = self.request.arguments or {}
|
||||||
|
if 'event_id' in params:
|
||||||
|
params['event_id'] = self.db.toID(params['event_id'][0])
|
||||||
|
if 'person_id' in params:
|
||||||
|
params['person_id'] = self.db.toID(params['person_id'][0])
|
||||||
|
data = self.db.query(self.collection, params)
|
||||||
|
self.write({'actions': data})
|
||||||
|
|
||||||
|
|
||||||
class EbCSVImportPersonsHandler(BaseHandler):
|
class EbCSVImportPersonsHandler(BaseHandler):
|
||||||
"""Importer for CSV files exported from eventbrite."""
|
"""Importer for CSV files exported from eventbrite."""
|
||||||
csvRemap = {
|
csvRemap = {
|
||||||
|
@ -137,8 +162,9 @@ class EbCSVImportPersonsHandler(BaseHandler):
|
||||||
registered_data = {
|
registered_data = {
|
||||||
'event_id': self.db.toID(targetEvent),
|
'event_id': self.db.toID(targetEvent),
|
||||||
'person_id': self.db.toID(_id),
|
'person_id': self.db.toID(_id),
|
||||||
|
'action': 'registered',
|
||||||
'from_file': filename}
|
'from_file': filename}
|
||||||
self.db.insertOne('registered', registered_data)
|
self.db.insertOne('actions', registered_data)
|
||||||
self.write(reply)
|
self.write(reply)
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,8 +189,9 @@ def run():
|
||||||
init_params = dict(db=db_connector)
|
init_params = dict(db=db_connector)
|
||||||
|
|
||||||
application = tornado.web.Application([
|
application = tornado.web.Application([
|
||||||
(r"/persons/?(?P<id_>\w+)?", PersonsHandler, init_params),
|
(r"/persons/?(?P<id_>\w+)?/?(?P<resource>\w+)?", PersonsHandler, init_params),
|
||||||
(r"/events/?(?P<id_>\w+)?", EventsHandler, init_params),
|
(r"/events/?(?P<id_>\w+)?", EventsHandler, init_params),
|
||||||
|
(r"/actions/?.*", ActionsHandler, init_params),
|
||||||
(r"/(?:index.html)?", RootHandler, init_params),
|
(r"/(?:index.html)?", RootHandler, init_params),
|
||||||
(r"/ebcsvpersons", EbCSVImportPersonsHandler, init_params),
|
(r"/ebcsvpersons", EbCSVImportPersonsHandler, init_params),
|
||||||
(r'/(.*)', tornado.web.StaticFileHandler, {"path": "angular_app"})
|
(r'/(.*)', tornado.web.StaticFileHandler, {"path": "angular_app"})
|
||||||
|
|
3
utils.py
3
utils.py
|
@ -20,6 +20,7 @@ import csv
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
import StringIO
|
import StringIO
|
||||||
|
from bson.objectid import ObjectId
|
||||||
|
|
||||||
|
|
||||||
def csvParse(csvStr, remap=None, merge=None):
|
def csvParse(csvStr, remap=None, merge=None):
|
||||||
|
@ -74,7 +75,7 @@ class ImprovedEncoder(json.JSONEncoder):
|
||||||
"""Enhance the default JSON encoder to serialize datetime objects."""
|
"""Enhance the default JSON encoder to serialize datetime objects."""
|
||||||
def default(self, o):
|
def default(self, o):
|
||||||
if isinstance(o, (datetime.datetime, datetime.date,
|
if isinstance(o, (datetime.datetime, datetime.date,
|
||||||
datetime.time, datetime.timedelta)):
|
datetime.time, datetime.timedelta, ObjectId)):
|
||||||
return str(o)
|
return str(o)
|
||||||
return json.JSONEncoder.default(self, o)
|
return json.JSONEncoder.default(self, o)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue