From d2874a90e9e998be2ef9446563865d2f655b7693 Mon Sep 17 00:00:00 2001 From: benarc Date: Mon, 11 May 2020 12:16:26 +0100 Subject: [PATCH] Working Events extension --- lnbits/extensions/events/README.md | 14 +++---------- lnbits/extensions/events/config.json.example | 2 +- lnbits/extensions/events/crud.py | 3 ++- .../events/templates/events/_api_docs.html | 14 ++----------- .../events/templates/events/display.html | 1 + .../events/templates/events/register.html | 21 +++++++++++++------ .../events/templates/events/ticket.html | 16 ++++++++++++-- lnbits/extensions/events/views_api.py | 9 ++++++++ 8 files changed, 47 insertions(+), 33 deletions(-) diff --git a/lnbits/extensions/events/README.md b/lnbits/extensions/events/README.md index 27729459..9108519c 100644 --- a/lnbits/extensions/events/README.md +++ b/lnbits/extensions/events/README.md @@ -1,11 +1,3 @@ -

Example Extension

-

*tagline*

-This is an example extension to help you organise and build you own. - -Try to include an image - - - -

If your extension has API endpoints, include useful ones here

- -curl -H "Content-type: application/json" -X POST https://YOUR-LNBITS/YOUR-EXTENSION/api/v1/EXAMPLE -d '{"amount":"100","memo":"example"}' -H "X-Api-Key: YOUR_WALLET-ADMIN/INVOICE-KEY" +

Events

+

Events: Sell and register event tickets

+Events alows you to make a wave of tickets for an event, each ticket is in the form of a unqiue QRcode, which the user presents at registration. Events comes with a shareable ticket scanner, which can be used to register attendees. diff --git a/lnbits/extensions/events/config.json.example b/lnbits/extensions/events/config.json.example index 3c9055d3..6bc144ab 100644 --- a/lnbits/extensions/events/config.json.example +++ b/lnbits/extensions/events/config.json.example @@ -1,6 +1,6 @@ { "name": "Events", - "short_description": "Sell/register event tickets", + "short_description": "Sell and register event tickets", "icon": "local_activity", "contributors": ["benarc"] } diff --git a/lnbits/extensions/events/crud.py b/lnbits/extensions/events/crud.py index 6c8503bd..b35a4bff 100644 --- a/lnbits/extensions/events/crud.py +++ b/lnbits/extensions/events/crud.py @@ -9,7 +9,7 @@ from .models import Tickets, Events #######TICKETS######## -def create_ticket(wallet: str, event: str, name: str, email: str) -> Tickets: +def create_ticket(wallet: str, event: str, name: str, email: str) -> Tickets: with open_ext_db("events") as db: eventdata = get_event(event) sold = eventdata.sold + 1 @@ -78,6 +78,7 @@ def update_event(event_id: str, **kwargs) -> Events: q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) with open_ext_db("events") as db: db.execute(f"UPDATE events SET {q} WHERE id = ?", (*kwargs.values(), event_id)) + row = db.fetchone("SELECT * FROM events WHERE id = ?", (event_id,)) return Events(**row) if row else None diff --git a/lnbits/extensions/events/templates/events/_api_docs.html b/lnbits/extensions/events/templates/events/_api_docs.html index c2a71b00..0caedae5 100644 --- a/lnbits/extensions/events/templates/events/_api_docs.html +++ b/lnbits/extensions/events/templates/events/_api_docs.html @@ -7,21 +7,11 @@ > -
Events: Sell and register tickets for an event
-

Events alows you to make a wave of tickets for an event. Once an attendee has paid for a ticket they get a unqiue code. Events comes with a shareable scanning frontend, so you can register the attendees
+

Events: Sell and register ticket waves for an event
+

Events alows you to make a wave of tickets for an event, each ticket is in the form of a unqiue QRcode, which the user presents at registration. Events comes with a shareable ticket scanner, which can be used to register attendees.
Created by, Ben Arc

- - - - - diff --git a/lnbits/extensions/events/templates/events/display.html b/lnbits/extensions/events/templates/events/display.html index 45791972..04658c4d 100644 --- a/lnbits/extensions/events/templates/events/display.html +++ b/lnbits/extensions/events/templates/events/display.html @@ -154,6 +154,7 @@ axios .post('/events/api/v1/tickets/' + self.paymentCheck, { event: '{{ event_id }}', + event_name: '{{ event_name }}', name: self.formDialog.data.name, email: self.formDialog.data.email }) diff --git a/lnbits/extensions/events/templates/events/register.html b/lnbits/extensions/events/templates/events/register.html index e64e4624..c7caea8c 100644 --- a/lnbits/extensions/events/templates/events/register.html +++ b/lnbits/extensions/events/templates/events/register.html @@ -84,6 +84,7 @@ type="text/css" href="{{ url_for('static', filename='vendor/vue-qrcode-reader@2.2.0/vue-qrcode-reader.min.css') }}" /> + {% endblock %} {% block scripts %} {% assets filters='rjsmin', output='__bundle__/core/chart.js', @@ -135,6 +136,9 @@ } }, methods: { + hoverEmail: function (tmp) { + this.tickets.data.emailtemp = tmp + }, closeCamera: function () { this.sendCamera.show = false }, @@ -144,19 +148,21 @@ decodeQR: function (res) { this.sendCamera.show = false var self = this - + LNbits.api .request('GET', '/events/api/v1/register/ticket/' + res) .then(function (response) { + self.$q.notify({ + type: 'positive', + message: 'Registered!' + }) self.tickets = response.data.map(function (obj) { - self.$q.notify({ - timeout: 5, - type: 'positive', - message: 'Registered!' - }) return mapEvents(obj) }) }) + .catch(function (error) { + LNbits.utils.notifyApiError(error) + }) }, getEventTickets: function () { var self = this @@ -171,6 +177,9 @@ return mapEvents(obj) }) }) + .catch(function (error) { + LNbits.utils.notifyApiError(error) + }) } }, created: function () { diff --git a/lnbits/extensions/events/templates/events/ticket.html b/lnbits/extensions/events/templates/events/ticket.html index c6d0a148..f8eaf93d 100644 --- a/lnbits/extensions/events/templates/events/ticket.html +++ b/lnbits/extensions/events/templates/events/ticket.html @@ -7,7 +7,7 @@

{{ ticket_name }} Ticket


- Bookmark or screenshot this page,
+ Bookmark, print or screenshot this page,
and present it for registration!

@@ -17,6 +17,10 @@ :options="{width: 340}" class="rounded-borders" > +
+ + Print @@ -28,7 +32,15 @@ Vue.component(VueQrcode.name, VueQrcode) new Vue({ el: '#vue', - mixins: [windowMixin] + mixins: [windowMixin], + data: function () { + return {} + }, + methods: { + printWindow: function () { + window.print() + } + } }) {% endblock %} diff --git a/lnbits/extensions/events/views_api.py b/lnbits/extensions/events/views_api.py index 8a856df1..e04ee8be 100644 --- a/lnbits/extensions/events/views_api.py +++ b/lnbits/extensions/events/views_api.py @@ -155,6 +155,15 @@ def api_event_tickets(wallet_id, event_id): @events_ext.route("/api/v1/register/ticket/", methods=["GET"]) def api_event_register_ticket(ticket_id): + + ticket = get_ticket(ticket_id) + + if not ticket: + return jsonify({"message": "Ticket does not exist."}), HTTPStatus.FORBIDDEN + + if ticket.registered == True: + return jsonify({"message": "Ticket already registered"}), HTTPStatus.FORBIDDEN + return jsonify([ticket._asdict() for ticket in reg_ticket(ticket_id)]), HTTPStatus.OK