diff --git a/ordr3/events.py b/ordr3/events.py index 8c63ca8..182c965 100644 --- a/ordr3/events.py +++ b/ordr3/events.py @@ -57,7 +57,7 @@ class OrderStatusChangeEmail(EmailNotification): """ user notification for order status change """ subject = "[ordr] Order Status Change" - template = "ordr3:templates/emails/order.jinja2" + template = "ordr3:templates/emails/status_change.jinja2" class PasswordResetEmail(EmailNotification): diff --git a/ordr3/repo.py b/ordr3/repo.py index fedd5e3..d1479e7 100644 --- a/ordr3/repo.py +++ b/ordr3/repo.py @@ -28,6 +28,10 @@ class AbstractOrderRepository(abc.ABC): def get_order(self, reference): """ get an order from the datastore by primary key """ + @abc.abstractmethod + def delete_order(self, order): + """ remove an order from the datastore """ + @abc.abstractmethod def list_orders(self): """ list orders orderd by date, descending """ @@ -94,6 +98,12 @@ class SqlAlchemyRepository(AbstractOrderRepository): """ add an order to the database """ self._add_item_to_db(order) + def delete_order(self, order): + """ remove an order from the datastore """ + for log_entry in order.log: + self.session.delete(log_entry) + self._delete_item_from_db(order) + def get_order(self, reference): """ get an order from the database by primary key """ try: diff --git a/ordr3/resources.py b/ordr3/resources.py index 8407276..1f0ad93 100644 --- a/ordr3/resources.py +++ b/ordr3/resources.py @@ -90,9 +90,18 @@ class OrderList(BaseResource): return [ (Allow, "role:user", "view"), (Allow, "role:user", "add"), - (Allow, "role:purchaser", "edit-multiple"), + (Allow, "role:purchaser", "batch-edit"), + (Allow, "role:purchaser", "batch-delete"), ] + def __getitem__(self, key): + """ returns child resources """ + try: + order = self.request.repo.get_order(key) + return Order.from_model(order, self) + except StopIteration as e: + raise KeyError from e + class Root(BaseResource): """ Root resource """ diff --git a/ordr3/services.py b/ordr3/services.py index ed793c4..7fe51ab 100644 --- a/ordr3/services.py +++ b/ordr3/services.py @@ -56,9 +56,14 @@ def _find_consumables(repo, repeat=3, days=365 * 2): def create_log_entry(order, status, user): + old_status = order.status + log_entry = models.LogEntry(order.id, status, user.username) order.add_to_log(log_entry) + # is this noteworthy? + return (old_status != status) and (order.created_by != user.username) + def verify_credentials(repo, pass_ctx, username, password): try: diff --git a/ordr3/static/script.js b/ordr3/static/script.js index cfa2155..97201e6 100644 --- a/ordr3/static/script.js +++ b/ordr3/static/script.js @@ -123,6 +123,14 @@ $(function() { } }); + $(".o3-set-multi-status").on("click", function(event) { + // set status to multiple items + var target = $(event.delegateTarget); + var selects = $(".o3-data-edit-multiple select"); + console.log(target.attr("data-multi-value")) + selects.val(target.attr("data-multi-value")) + }); + var infinite = new Waypoint.Infinite({ element: $('.infinite-container')[0] }); diff --git a/ordr3/static/style.css b/ordr3/static/style.css index 57cb014..0aebd88 100644 --- a/ordr3/static/style.css +++ b/ordr3/static/style.css @@ -187,5 +187,9 @@ td.o3-actions a:hover { white-space: nowrap; } - - +.o3-data-edit-multiple td { + vertical-align:middle; + } +.o3-data-edit-multiple select { + width: 7rem; + } diff --git a/ordr3/templates/emails/status_change.jinja2 b/ordr3/templates/emails/status_change.jinja2 new file mode 100755 index 0000000..9d63e72 --- /dev/null +++ b/ordr3/templates/emails/status_change.jinja2 @@ -0,0 +1,16 @@ +Dear {{ user.first_name }}, + +The status of one or more of your orders have been changed by {{ request.user.first_name }}: + +{% for order in data %} +{{ order.cas_description }} +- new status: {{ order.status.name|title }} +{% endfor %} + +You can now log in at {{ request.resource_url(request.root) }} and order some more stuff. + +Regards, +The Ordr System + +-- +Please don't respont to this email! This is an automatically generated notification. diff --git a/ordr3/templates/layout_full.jinja2 b/ordr3/templates/layout_full.jinja2 index 7995093..4d6269f 100644 --- a/ordr3/templates/layout_full.jinja2 +++ b/ordr3/templates/layout_full.jinja2 @@ -32,10 +32,10 @@