From ecd18542e6accc9c2b12ec38b992e7e3ce0fdf2c Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 9 Sep 2017 19:02:14 +0200 Subject: [PATCH] draft of Eventbrite API import GUI: #58 --- README.md | 1 + angular_app/import-persons.html | 31 +++++++++++++++++++ angular_app/js/controllers.js | 22 ++++++++++++-- angular_app/js/services.js | 54 ++++++++++++++++++++++----------- eventman_server.py | 19 ++++++++++++ static/i18n/it_IT.json | 8 +++-- 6 files changed, 114 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 626ad4d..e90b215 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Be sure to have a running MongoDB server, locally. If you want to install the de sudo pip3 install pymongo # version 3.2.2 or later sudo pip3 install python-dateutil sudo pip3 install pycups # only needed if you want to print labels + sudo pip3 install eventbrite # only needed if you want to import from Eventbrite using their API sudo pip3 install serial # only for the qrcode_reader script sudo pip3 install requests # only for the qrcode_reader script git clone https://github.com/raspibo/eventman diff --git a/angular_app/import-persons.html b/angular_app/import-persons.html index 3f22ea0..6d1891f 100644 --- a/angular_app/import-persons.html +++ b/angular_app/import-persons.html @@ -1,5 +1,36 @@
+
+
+

{{'Import tickets with Eventbrite API' | translate}}

+
+
+
+
+ + +
+
+ + +
+ + {{'create a new event' | translate}} + +
+ + +
+
+
+ +
+
+
+
+

{{'Import tickets from Eventbrite CSV' | translate}}

diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index ae05be0..713fda0 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -826,14 +826,32 @@ eventManControllers.controller('UsersCtrl', ['$scope', '$rootScope', '$state', ' ); -eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event', - function ($scope, $log, $upload, Event) { +eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'EbAPI', 'Event', + function ($scope, $log, $upload, EbAPI, Event) { $scope.file = null; $scope.progress = 0; $scope.progressbarType = 'warning'; $scope.deduplicate = false; + $scope.targetEvent = null; + $scope.createNewEvent = true; + $scope.ebAPIkey = ''; + $scope.ebEventID = ''; $scope.reply = {}; $scope.events = Event.all(); + + $scope.apiImport = function() { + if (!($scope.ebAPIkey && $scope.ebEventID)) { + $log.warn('missing Eventbrite API key or Event ID'); + return; + } + EbAPI.apiImport({ + create: $scope.createNewEvent, + eventID: $scope.ebEventID, + targetEvent: $scope.targetEvent, + apiKey: $scope.ebAPIkey + }); + }; + $scope.upload = function(file, url) { $log.debug("FileUploadCtrl.upload"); $scope.progress = 0; diff --git a/angular_app/js/services.js b/angular_app/js/services.js index d8365d6..a51e11f 100644 --- a/angular_app/js/services.js +++ b/angular_app/js/services.js @@ -22,7 +22,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope', all: { method: 'GET', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, isArray: true, transformResponse: function(data, headers) { data = angular.fromJson(data); @@ -39,7 +39,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope', get: { method: 'GET', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, transformResponse: function(data, headers) { data = angular.fromJson(data); convert_dates(data); @@ -57,7 +57,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope', update: { method: 'PUT', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, transformResponse: function(data, headers) { data = angular.fromJson(data); convert_dates(data); @@ -85,7 +85,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', all: { method: 'GET', url: '/tickets', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, isArray: true, transformResponse: function(data, headers) { data = angular.fromJson(data); @@ -96,7 +96,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', get: { method: 'GET', url: 'events/:id/tickets/:ticket_id', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, transformResponse: function(data, headers) { data = angular.fromJson(data); if (data.error) { @@ -108,7 +108,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', add: { method: 'POST', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, isArray: false, url: 'events/:event_id/tickets', params: {uuid: $rootScope.app_uuid}, @@ -123,7 +123,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', update: { method: 'PUT', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, isArray: false, url: 'events/:event_id/tickets/:ticket_id', params: {uuid: $rootScope.app_uuid}, @@ -137,7 +137,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', 'delete': { method: 'DELETE', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, isArray: false, url: 'events/:event_id/tickets/:ticket_id', params: {uuid: $rootScope.app_uuid}, @@ -155,7 +155,7 @@ eventManServices.factory('Setting', ['$resource', '$rootScope', return $resource('settings/', {}, { query: { method: 'GET', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, isArray: true, transformResponse: function(data, headers) { data = angular.fromJson(data); @@ -168,7 +168,7 @@ eventManServices.factory('Setting', ['$resource', '$rootScope', update: { method: 'PUT', - interceptor : {responseError: $rootScope.errorHandler} + interceptor: {responseError: $rootScope.errorHandler} } }); }] @@ -180,7 +180,27 @@ eventManServices.factory('Info', ['$resource', '$rootScope', return $resource('info/', {}, { get: { method: 'GET', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, + isArray: false, + transformResponse: function(data, headers) { + data = angular.fromJson(data); + if (data.error) { + return data; + } + return data.info || {}; + } + } + }); + }] +); + + +eventManServices.factory('EbAPI', ['$resource', '$rootScope', + function($resource, $rootScope) { + return $resource('ebapi/', {}, { + apiImport: { + method: 'POST', + interceptor: {responseError: $rootScope.errorHandler}, isArray: false, transformResponse: function(data, headers) { data = angular.fromJson(data); @@ -200,7 +220,7 @@ eventManServices.factory('User', ['$resource', '$rootScope', return $resource('users/:id', {id: '@_id'}, { all: { method: 'GET', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, isArray: true, transformResponse: function(data, headers) { data = angular.fromJson(data); @@ -213,7 +233,7 @@ eventManServices.factory('User', ['$resource', '$rootScope', get: { method: 'GET', - interceptor : {responseError: $rootScope.errorHandler}, + interceptor: {responseError: $rootScope.errorHandler}, transformResponse: function(data, headers) { return angular.fromJson(data); } @@ -221,24 +241,24 @@ eventManServices.factory('User', ['$resource', '$rootScope', add: { method: 'POST', - interceptor : {responseError: $rootScope.errorHandler} + interceptor: {responseError: $rootScope.errorHandler} }, update: { method: 'PUT', - interceptor : {responseError: $rootScope.errorHandler} + interceptor: {responseError: $rootScope.errorHandler} }, login: { method: 'POST', url: '/login', - interceptor : {responseError: $rootScope.errorHandler} + interceptor: {responseError: $rootScope.errorHandler} }, logout: { method: 'GET', url: '/logout', - interceptor : {responseError: $rootScope.errorHandler} + interceptor: {responseError: $rootScope.errorHandler} } }); }] diff --git a/eventman_server.py b/eventman_server.py index ca5799e..16096cc 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -995,6 +995,20 @@ class UsersHandler(CollectionHandler): super(UsersHandler, self).put(id_, resource, resource_id, **kwargs) +class EbAPIImportHandler(BaseHandler): + """Import events and attendees using Eventbrite API.""" + @gen.coroutine + @authenticated + def post(self, *args, **kwargs): + reply = {} + data = escape.json_decode(self.request.body or '{}') + apiKey = data.get('apiKey') + targetEvent = data.get('targetEvent') + eventID = data.get('eventID') + create = data.get('create') + self.write(reply) + + class EbCSVImportPersonsHandler(BaseHandler): """Importer for CSV files exported from Eventbrite.""" csvRemap = { @@ -1259,8 +1273,13 @@ def run(): (r'/v%s%s' % (API_VERSION, _users_path), UsersHandler, init_params), (r"/(?:index.html)?", RootHandler, init_params), (r"/ebcsvpersons", EbCSVImportPersonsHandler, init_params), + (r"/v%s/ebcsvpersons" % API_VERSION, EbCSVImportPersonsHandler, init_params), + (r"/ebapi", EbAPIImportHandler, init_params), + (r"/v%s/ebapi" % API_VERSION, EbAPIImportHandler, init_params), (r"/settings", SettingsHandler, init_params), + (r"/v%s/settings" % API_VERSION, SettingsHandler, init_params), (r"/info", InfoHandler, init_params), + (r"/v%s/info" % API_VERSION, InfoHandler, init_params), _ws_handler, (r'/login', LoginHandler, init_params), (r'/v%s/login' % API_VERSION, LoginHandler, init_params), diff --git a/static/i18n/it_IT.json b/static/i18n/it_IT.json index 7184dbf..8ea8997 100644 --- a/static/i18n/it_IT.json +++ b/static/i18n/it_IT.json @@ -58,12 +58,16 @@ "until": "fino a", "Delete event": "Cancella l'evento", "Delete all tickets in event": "Cancella tutti i ticket dell'evento", + "Import tickets with Eventbrite API": "Importa i biglietti tramite le API di Eventbrite", + "API key": "API key", + "Eventbrite Event ID": "Eventbrite Event ID", + "create a new event": "crea un nuovo evento", + "Associate tickets to this event": "Associa i biglietti a questo evento", + "Import": "Importa", "Import tickets from Eventbrite CSV": "Importa i biglietti da un CSV Eventbrite", "CSV file": "File CSV", "CSV exported from Eventbrite": "CSV esportato da Eventbrite", - "Associate tickets to this event": "Associa i biglietti a questo evento", "deduplicate entries": "deduplica le voci", - "Import": "Importa", "Users": "Utenti", "All tickets": "Tutti i biglietti", "Import tickets": "Importa biglietti",