From ea3b858695440c845143571972740e0d08092db1 Mon Sep 17 00:00:00 2001 From: benarc Date: Sat, 9 May 2020 22:26:58 +0100 Subject: [PATCH] Replaced events extension with almost working vuejs one --- lnbits/extensions/events/README.md | 13 +- lnbits/extensions/events/config.json.example | 8 +- lnbits/extensions/events/config.json.wip | 6 - lnbits/extensions/events/crud.py | 116 +++ lnbits/extensions/events/migrations.py | 37 +- lnbits/extensions/events/models.py | 24 + lnbits/extensions/events/schema.sql | 26 - .../events/templates/events/_api_docs.html | 27 + .../events/templates/events/display.html | 739 ++++--------- .../events/templates/events/error.html | 35 + .../events/templates/events/index.html | 967 +++++++++--------- .../events/templates/events/register.html | 146 +++ .../events/templates/events/registration.html | 670 ------------ .../events/templates/events/ticket.html | 490 +-------- lnbits/extensions/events/views.py | 181 +--- lnbits/extensions/events/views_api.py | 194 +++- 16 files changed, 1273 insertions(+), 2406 deletions(-) delete mode 100644 lnbits/extensions/events/config.json.wip create mode 100644 lnbits/extensions/events/crud.py create mode 100644 lnbits/extensions/events/models.py delete mode 100644 lnbits/extensions/events/schema.sql create mode 100644 lnbits/extensions/events/templates/events/_api_docs.html create mode 100644 lnbits/extensions/events/templates/events/error.html create mode 100644 lnbits/extensions/events/templates/events/register.html delete mode 100644 lnbits/extensions/events/templates/events/registration.html diff --git a/lnbits/extensions/events/README.md b/lnbits/extensions/events/README.md index f1fe3d3ef..277294592 100644 --- a/lnbits/extensions/events/README.md +++ b/lnbits/extensions/events/README.md @@ -1,8 +1,11 @@ -

LNEVENTS

-

Create/sell tickets for an event

-

Events is an easy way to create/sell tickets for an event. +

Example Extension

+

*tagline*

+This is an example extension to help you organise and build you own. -It is advised to setup a specific wallet in lnbits for the event.

+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" diff --git a/lnbits/extensions/events/config.json.example b/lnbits/extensions/events/config.json.example index 738e264ff..3c9055d3b 100644 --- a/lnbits/extensions/events/config.json.example +++ b/lnbits/extensions/events/config.json.example @@ -1,6 +1,6 @@ { - "name": "Events", - "short_description": "LN tickets for events.", - "icon": "local_activity", - "contributors": ["arcbtc"] + "name": "Events", + "short_description": "Sell/register event tickets", + "icon": "local_activity", + "contributors": ["benarc"] } diff --git a/lnbits/extensions/events/config.json.wip b/lnbits/extensions/events/config.json.wip deleted file mode 100644 index 738e264ff..000000000 --- a/lnbits/extensions/events/config.json.wip +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Events", - "short_description": "LN tickets for events.", - "icon": "local_activity", - "contributors": ["arcbtc"] -} diff --git a/lnbits/extensions/events/crud.py b/lnbits/extensions/events/crud.py new file mode 100644 index 000000000..d0a23d89e --- /dev/null +++ b/lnbits/extensions/events/crud.py @@ -0,0 +1,116 @@ +from typing import List, Optional, Union + +from lnbits.db import open_ext_db +from lnbits.helpers import urlsafe_short_hash + +from .models import Tickets, Events + + +#######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 + amount_tickets = eventdata.amount_tickets - 1 + ticket_id = urlsafe_short_hash() + db.execute( + """ + INSERT INTO tickets (id, wallet, event, name, email, registered) + VALUES (?, ?, ?, ?, ?, ?) + """, + (ticket_id, wallet, event, name, email, False), + ) + db.execute( + """ + UPDATE events + SET sold = ?, amount_tickets = ? + WHERE id = ? + """, + (sold, amount_tickets, event), + ) + return get_ticket(ticket_id) + + +def get_ticket(ticket_id: str) -> Optional[Tickets]: + with open_ext_db("events") as db: + row = db.fetchone("SELECT * FROM tickets WHERE id = ?", (ticket_id,)) + + return Tickets(**row) if row else None + + +def get_tickets(wallet_ids: Union[str, List[str]]) -> List[Tickets]: + if isinstance(wallet_ids, str): + wallet_ids = [wallet_ids] + + with open_ext_db("events") as db: + q = ",".join(["?"] * len(wallet_ids)) + rows = db.fetchall(f"SELECT * FROM tickets WHERE wallet IN ({q})", (*wallet_ids,)) + print("scrum") + return [Tickets(**row) for row in rows] + + +def delete_ticket(ticket_id: str) -> None: + with open_ext_db("events") as db: + db.execute("DELETE FROM tickets WHERE id = ?", (ticket_id,)) + + + +########EVENTS######### + + +def create_event(*, wallet: str, name: str, info: str, closing_date: str, event_start_date: str, event_end_date: str, amount_tickets: int, price_per_ticket: int) -> Events: + with open_ext_db("events") as db: + event_id = urlsafe_short_hash() + db.execute( + """ + INSERT INTO events (id, wallet, name, info, closing_date, event_start_date, event_end_date, amount_tickets, price_per_ticket, sold) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """, + (event_id, wallet, name, info, closing_date, event_start_date, event_end_date, amount_tickets, price_per_ticket, 0), + ) + print(event_id) + + return get_event(event_id) + +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 + + +def get_event(event_id: str) -> Optional[Events]: + with open_ext_db("events") as db: + row = db.fetchone("SELECT * FROM events WHERE id = ?", (event_id,)) + + return Events(**row) if row else None + + +def get_events(wallet_ids: Union[str, List[str]]) -> List[Events]: + if isinstance(wallet_ids, str): + wallet_ids = [wallet_ids] + + with open_ext_db("events") as db: + q = ",".join(["?"] * len(wallet_ids)) + rows = db.fetchall(f"SELECT * FROM events WHERE wallet IN ({q})", (*wallet_ids,)) + + return [Events(**row) for row in rows] + + +def delete_event(event_id: str) -> None: + with open_ext_db("events") as db: + db.execute("DELETE FROM events WHERE id = ?", (event_id,)) + +########EVENTTICKETS######### + +def get_event_tickets(event_id: str, wallet_id: str) -> Tickets: + + with open_ext_db("events") as db: + rows = db.fetchall("SELECT * FROM tickets WHERE wallet = ? AND event = ?", (wallet_id, event_id)) + print(rows) + + return [Tickets(**row) for row in rows] \ No newline at end of file diff --git a/lnbits/extensions/events/migrations.py b/lnbits/extensions/events/migrations.py index 04435aa5f..523071e5b 100644 --- a/lnbits/extensions/events/migrations.py +++ b/lnbits/extensions/events/migrations.py @@ -1,5 +1,40 @@ from lnbits.db import open_ext_db +def m001_initial(db): + + db.execute( + """ + CREATE TABLE IF NOT EXISTS events ( + id TEXT PRIMARY KEY, + wallet TEXT NOT NULL, + name TEXT NOT NULL, + info TEXT NOT NULL, + closing_date TEXT NOT NULL, + event_start_date TEXT NOT NULL, + event_end_date TEXT NOT NULL, + amount_tickets INTEGER NOT NULL, + price_per_ticket INTEGER NOT NULL, + sold INTEGER NOT NULL, + time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now')) + ); + """ + ) + + db.execute( + """ + CREATE TABLE IF NOT EXISTS tickets ( + id TEXT PRIMARY KEY, + wallet TEXT NOT NULL, + event TEXT NOT NULL, + name TEXT NOT NULL, + email TEXT NOT NULL, + registered BOOLEAN NOT NULL, + time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now')) + ); + """ + ) def migrate(): - print("pending") + with open_ext_db("events") as db: + m001_initial(db) + diff --git a/lnbits/extensions/events/models.py b/lnbits/extensions/events/models.py new file mode 100644 index 000000000..d2d606630 --- /dev/null +++ b/lnbits/extensions/events/models.py @@ -0,0 +1,24 @@ +from typing import NamedTuple + + +class Events(NamedTuple): + id: str + wallet: str + name: str + info: str + closing_date: str + event_start_date: str + event_end_date: str + amount_tickets: int + price_per_ticket: int + sold: int + time: int + +class Tickets(NamedTuple): + id: str + wallet: str + event: str + name: str + email: str + registered: bool + time: int \ No newline at end of file diff --git a/lnbits/extensions/events/schema.sql b/lnbits/extensions/events/schema.sql deleted file mode 100644 index bc1dabca7..000000000 --- a/lnbits/extensions/events/schema.sql +++ /dev/null @@ -1,26 +0,0 @@ -CREATE TABLE IF NOT EXISTS events ( - key INTEGER PRIMARY KEY AUTOINCREMENT, - usr TEXT, - wal TEXT, - walnme TEXT, - walinvkey INTEGER, - uni TEXT, - tit TEXT, - cldate TEXT, - notickets INTEGER, - sold INTEGER DEFAULT 0, - prtick INTEGER, - descr TEXT, - unireg TEXT -); - -CREATE TABLE IF NOT EXISTS eventssold ( - key INTEGER PRIMARY KEY AUTOINCREMENT, - uni TEXT, - email TEXT, - name TEXT, - hash TEXT, - paid INTEGER DEFAULT 0, - reg INTEGER DEFAULT 0 -); - diff --git a/lnbits/extensions/events/templates/events/_api_docs.html b/lnbits/extensions/events/templates/events/_api_docs.html new file mode 100644 index 000000000..c2a71b00a --- /dev/null +++ b/lnbits/extensions/events/templates/events/_api_docs.html @@ -0,0 +1,27 @@ + + + + +
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
+ Created by, Ben Arc

+
+ + + +
+ + + + + diff --git a/lnbits/extensions/events/templates/events/display.html b/lnbits/extensions/events/templates/events/display.html index 30ec2508c..ccf687998 100644 --- a/lnbits/extensions/events/templates/events/display.html +++ b/lnbits/extensions/events/templates/events/display.html @@ -1,567 +1,202 @@ - +{% extends "public.html" %} {% block page %} +
+
+ + +

{{ event_name }}

+
+
{{ event_info }}
+
+ + + - - - - - LNBits Wallet - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - -
+ + + - - - -
- -
-

- LNBits Events - Lightning powered tickets -

-
- - -
-

-

{{ nme }}

-
-

{{ descr }}

-
-
-


-
-
-
- - -
- -

-
-
-
-
-

-
-

-
-
-
-
- + +
+ + Link to your ticket! +

+

You'll be redirected in 5 seconds...

- -
- + +
- + - + }) + +{% endblock %} diff --git a/lnbits/extensions/events/templates/events/error.html b/lnbits/extensions/events/templates/events/error.html new file mode 100644 index 000000000..80cfa8daa --- /dev/null +++ b/lnbits/extensions/events/templates/events/error.html @@ -0,0 +1,35 @@ +{% extends "public.html" %} {% block page %} +
+
+ + +
+

{{ event_name }} error

+
+ + +
{{ event_error }}
+
+
+
+
+
+ + {% endblock %} {% block scripts %} + + + + {% endblock %} +
diff --git a/lnbits/extensions/events/templates/events/index.html b/lnbits/extensions/events/templates/events/index.html index 18081ac0a..74304a0e1 100644 --- a/lnbits/extensions/events/templates/events/index.html +++ b/lnbits/extensions/events/templates/events/index.html @@ -1,501 +1,512 @@ - - -{% extends "legacy.html" %} {% block messages %} - - - - ! - - -{% endblock %} {% block menuitems %} -
  • - - Wallets - - - -
  • -
  • - - Extensions - - -
      - {% for extension in EXTENSIONS %} {% if extension.code in user_ext %} -
    • - {{ extension.name }} -
    • - {% endif %} {% endfor %} -
    • - Manager -
    • -
    -
  • -{% endblock %} {% block body %} - -
    - -
    -

    - Events - bitcoin tickets -

    - -

    -
    - - -
    - -
    -
    - -
    -
    -

    Make a ticket wave

    + + + + + +
    +
    +
    Events
    - - - -
    -
    -
    - - -
    - -
    - - -
    - - -
    - - -
    - -
    - - -
    -
    - -
    - - -
    - -
    - -
    - - -
    -
    - - -
    -
    -
    -
    - -
    - -
    -
    -

    Select a link

    -
    - -
    -
    -
    - -
    - -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    - -
    -
    -
    -
    -

    Ticket Waves

    -
    - -
    - + Export to CSV - - - - - - - - - - - -
    TitleAmtSoldClosingPriceWalletEditDel
    -
    - -
    -
    + + {% raw %} +