Coverage for control/cust/contrib_table.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from config import Config as C, Names as N
2from control.table import Table
3from control.utils import pick as G, thisYear
5CW = C.web
7UNKNOWN = CW.unknown
8Qt = G(UNKNOWN, N.title)
11class ContribT(Table):
12 """Logic for the contrib table.
14 When we insert a contrib record, we want to fill in
16 * the current year
17 * the country of the current user
18 * the name of the current user
19 * the email address of the current user
21 set of criteriaEntry records and prefill some of their fields.
22 """
24 def __init__(self, *args, **kwargs):
25 super().__init__(*args, **kwargs)
27 def insert(self, force=False):
28 mayInsert = force or self.mayInsert
29 if not mayInsert:
30 return None
32 context = self.context
33 db = context.db
34 auth = context.auth
35 uid = self.uid
36 eppn = self.eppn
37 countryId = self.countryId
38 table = self.table
40 (name, email) = auth.nameEmail()
42 prefilledFields = {
43 N.title: Qt,
44 N.year: G(db.yearInv, thisYear()),
45 N.country: countryId,
46 N.contactPersonName: [name],
47 N.contactPersonEmail: [email],
48 }
50 result = db.insertItem(table, uid, eppn, False, **prefilledFields)
51 self.adjustWorkflow(result)
53 return result