|
|
## Auction Rules |
|
|
\ No newline at end of file |
|
|
# Auction Rules
|
|
|
|
|
|
Rules is very important part of every auction.
|
|
|
|
|
|
Rules declared inside Auction class and play "role" of encapsulation of some business data from users.
|
|
|
|
|
|
Auction roles in must cases uses in bundle with `AuctionStatusRole` that allow to apply roles for specific states of auction. [[example](https://gitlab.prozorro.sale/prozorro-sale/auction/-/blob/master/src/prozorro_sale/auction/packages/priorityEnglish/auction.py#L88)]
|
|
|
|
|
|
To implement custom role you must create role class and extends from `schematics.role` and implement __init__ method with `pass` body, and `__call__` method with conditions to describe or not to describe data.
|
|
|
|
|
|
```python
|
|
|
class MyCustomRole(schematics.role):
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
pass
|
|
|
|
|
|
def __call__(self, name, value, context):
|
|
|
if name == 'name_of_value_to_hide':
|
|
|
return
|
|
|
return value
|
|
|
```
|
|
|
|
|
|
`name` - name of the field.
|
|
|
|
|
|
`value` - value that contains in the object by key `name`.
|
|
|
|
|
|
`context` - auction contains that defined inside Auction class and contains data of auction that will helm in some
|
|
|
business logic.
|
|
|
To add some custom context - you should to redifine `to_primitive` method of auction [[example](https://gitlab.prozorro.sale/prozorro-sale/auction/-/blob/master/src/prozorro_sale/auction/models/__init__.py#L192)]
|
|
|
|
|
|
|
|
|
[Examples of implementation of custom roles](https://gitlab.prozorro.sale/prozorro-sale/auction/-/blob/master/src/prozorro_sale/auction/role_plugins.py)
|
|
|
|