Adding dynamic business logic/business process checks to a system
- by Jordan Reiter
I'm wondering if there is a good extant pattern (language here is Python/Django but also interested on the more abstract level) for creating a business logic layer that can be created without coding.
For example, suppose that a house rental should only be available during a specific time. A coder might create the following class:
from bizlogic import rules, LogicRule
from orders.models import Order
class BeachHouseAvailable(LogicRule):
def check(self, reservation):
house = reservation.house_reserved
if not (house.earliest_available < reservation.starts < house.latest_available )
raise RuleViolationWhen("Beach house is available only between %s and %s" % (house.earliest_available, house.latest_available))
return True
rules.add(Order, BeachHouseAvailable, name="BeachHouse Available")
This is fine, but I don't want to have to code something like this each time a new rule is needed.
I'd like to create something dynamic, ideally something that can be stored in a database.
The thing is, it would have to be flexible enough to encompass a wide variety of rules:
avoiding duplicates/overlaps (to continue the example "You already have a reservation for this time/location")
logic rules ("You can't rent a house to yourself", "This house is in a different place from your chosen destination")
sanity tests ("You've set a rental price that's 10x the normal rate. Are you sure this is the right price?"
Things like that.
Before I recreate the wheel, I'm wondering if there are already methods out there for doing something like this.