Skip to content
This repository was archived by the owner on Dec 19, 2021. It is now read-only.

Commit 298b7ab

Browse files
committed
Implement collection delete method for NobiruList
Implements a delete method that can be called on a NobiruList collection. The method takes an object instance, and returns None if successful; otherwise it raises a 404 Not Found error.
1 parent c6cebb6 commit 298b7ab

File tree

12 files changed

+102
-24
lines changed

12 files changed

+102
-24
lines changed

db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from flask_sqlalchemy import SQLAlchemy
2-
from utils.nobiru import NobiruQuery
2+
from nobiru.nobiru_query import NobiruQuery
33

44
db = SQLAlchemy(query_class=NobiruQuery)

models/emergency_contact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from db import db
22
from models.base_model import BaseModel
3-
from utils.nobiru import NobiruList
3+
from nobiru.nobiru_list import NobiruList
44
from utils.time import Time
55

66

models/property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from db import db
2-
from utils.nobiru import NobiruList
2+
from nobiru.nobiru_list import NobiruList
33
from models.base_model import BaseModel
44
from models.user import UserModel
55
from models.property_assignment import PropertyAssignment

models/tenant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from db import db
2-
from utils.nobiru import NobiruList
2+
from nobiru.nobiru_list import NobiruList
33
from models.base_model import BaseModel
44
from models.tickets import TicketModel
55
from utils.time import Time

models/tickets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from db import db
2-
from utils.nobiru import NobiruList
2+
from nobiru.nobiru_list import NobiruList
33
from datetime import datetime, timedelta
44
from models.base_model import BaseModel
55
from utils.time import Time

models/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from flask import current_app
2-
from utils.nobiru import NobiruList
2+
from nobiru.nobiru_list import NobiruList
33
from datetime import datetime
44
from models.tickets import TicketModel
55
import bcrypt

nobiru/__init__.py

Whitespace-only changes.

nobiru/nobiru.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Nobiru:
2+
@staticmethod
3+
def json(collection):
4+
return [object.json() for object in collection]

nobiru/nobiru_list.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from db import db
2+
from flask import abort
3+
from nobiru.nobiru import Nobiru
4+
from sqlalchemy.orm.collections import InstrumentedList
5+
from sqlalchemy.orm.collections import collection
6+
7+
8+
class NobiruList(InstrumentedList):
9+
def json(self):
10+
return Nobiru.json(self)
11+
12+
@collection.remover
13+
def delete(self, entity):
14+
try:
15+
self.remove(entity)
16+
db.session.commit()
17+
except ValueError:
18+
abort(404, f"{entity._name()} not found")

nobiru/nobiru_query.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from nobiru.nobiru import Nobiru
2+
from flask_sqlalchemy import BaseQuery
3+
4+
5+
class NobiruQuery(BaseQuery):
6+
def json(self):
7+
return Nobiru.json(self)

0 commit comments

Comments
 (0)