File: ex_64b_hooks_warning.py

package info (click to toggle)
sqlkit 0.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,184 kB
  • sloc: python: 17,477; sql: 166; makefile: 95; xml: 23; sh: 11
file content (27 lines) | stat: -rw-r--r-- 720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""hooks/warning - related

Very similar to the precedent but with warning on a related table

"""
from sqlkit.exc import ValidationError, ValidationWarning
from sqlkit.db.utils import get_differences

class Hooks(object):
    def on_field_validation__genres(self, mask, field_name, field_value, field):
        for field_name, old, new in get_differences(mask.current):
            if field_name == 'genres':
                msg = "I'd really prefer you don't change genre!!!"
                raise ValidationWarning(msg)
        
lay = """
   title
   year
   director_id
   m2m=genres -
   """

t = SqlMask(model.Movie, layout=lay, label_map={'genres.name':'genres'},
         dbproxy=db, hooks=Hooks())

t.reload()