diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 4b868f8..48c9018 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -74,10 +74,13 @@ eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', ); -eventManControllers.controller('PersonDetailsCtrl', ['$scope', 'Person', '$routeParams', - function ($scope, Person, $routeParams) { +eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$routeParams', 'Person', 'Action', + function ($scope, $routeParams, Person, Action) { if ($routeParams.id) { $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 $scope.save = function() { diff --git a/angular_app/js/services.js b/angular_app/js/services.js index e9b4c7b..4d3358f 100644 --- a/angular_app/js/services.js +++ b/angular_app/js/services.js @@ -3,6 +3,11 @@ /* Services that are used to interact with the backend. */ var eventManServices = angular.module('eventManServices', ['ngResource']); +eventManServices.factory('Action', ['$resource', + function($resource) { + return $resource('actions'); + }] +); eventManServices.factory('Event', ['$resource', function($resource) { diff --git a/angular_app/person-detail.html b/angular_app/person-detail.html index 12438b5..c791b28 100644 --- a/angular_app/person-detail.html +++ b/angular_app/person-detail.html @@ -18,4 +18,23 @@ + +
+
Actions
+ + + + + + + + + + + + + +
ActionEvent ID
{{action.action}}{{action.event_id}}
+
+ diff --git a/eventman_server.py b/eventman_server.py index 0748907..260a6b6 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -43,7 +43,7 @@ class RootHandler(BaseHandler): angular_app_path = os.path.join(os.path.dirname(__file__), "angular_app") @gen.coroutine - def get(self): + def get(self, *args, **kwargs): # serve the ./angular_app/index.html file with open(self.angular_app_path + "/index.html", 'r') as fd: self.write(fd.read()) @@ -57,7 +57,15 @@ class CollectionHandler(BaseHandler): collection = None @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: # read a single document self.write(self.db.get(self.collection, id_)) @@ -91,12 +99,29 @@ class PersonsHandler(CollectionHandler): """Handle requests for Persons.""" collection = 'persons' + def handle_events(self, _id, **kwds): + return {'events': []} + class EventsHandler(CollectionHandler): """Handle requests for 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): """Importer for CSV files exported from eventbrite.""" csvRemap = { @@ -137,8 +162,9 @@ class EbCSVImportPersonsHandler(BaseHandler): registered_data = { 'event_id': self.db.toID(targetEvent), 'person_id': self.db.toID(_id), + 'action': 'registered', 'from_file': filename} - self.db.insertOne('registered', registered_data) + self.db.insertOne('actions', registered_data) self.write(reply) @@ -163,8 +189,9 @@ def run(): init_params = dict(db=db_connector) application = tornado.web.Application([ - (r"/persons/?(?P\w+)?", PersonsHandler, init_params), + (r"/persons/?(?P\w+)?/?(?P\w+)?", PersonsHandler, init_params), (r"/events/?(?P\w+)?", EventsHandler, init_params), + (r"/actions/?.*", ActionsHandler, init_params), (r"/(?:index.html)?", RootHandler, init_params), (r"/ebcsvpersons", EbCSVImportPersonsHandler, init_params), (r'/(.*)', tornado.web.StaticFileHandler, {"path": "angular_app"}) diff --git a/utils.py b/utils.py index a9c61ee..372ed23 100644 --- a/utils.py +++ b/utils.py @@ -20,6 +20,7 @@ import csv import json import datetime import StringIO +from bson.objectid import ObjectId def csvParse(csvStr, remap=None, merge=None): @@ -74,7 +75,7 @@ class ImprovedEncoder(json.JSONEncoder): """Enhance the default JSON encoder to serialize datetime objects.""" def default(self, o): if isinstance(o, (datetime.datetime, datetime.date, - datetime.time, datetime.timedelta)): + datetime.time, datetime.timedelta, ObjectId)): return str(o) return json.JSONEncoder.default(self, o)