Beispiel #1
0
def mark_products(product_id=None, mark=True):
    """Mark/unmark all products."""
    assert isinstance(mark, bool)
    assert product_id is None or isinstance(product_id, (int, tuple, list))
    row = pd.Row((('marked', pd.bval(mark)),))
    if product_id is None:
        condition = pd.EQ('marked', pd.bval(not mark))
    elif isinstance(product_id, (list, tuple)):
        condition = pd.OR(*[pd.EQ('product_id', pd.ival(x)) for x in product_id])
    else:
        condition = pd.EQ('product_id', pd.ival(product_id))
    import pytis.extensions
    return pytis.extensions.dbupdate_many('misc.Products', condition=condition, update_row=row)
Beispiel #2
0
 def close(self, req, session_key):
     session_id, session_key = self._split_key(session_key)
     # We don't verify session_key here, because we know that
     # 'CookieAuthenticationProvider.authenticate()' only calls
     # 'close()' after 'check()' or 'init()', but this is not
     # required by definition.  Thus it should be either
     # documented somewhere or not relied upon.
     self._data.delete(pd.ival(session_id))
Beispiel #3
0
 def check(self, req, session_key):
     session_id, session_key = self._split_key(session_key)
     row = self._data.row(pd.ival(session_id))
     if row and row['session_key'].value() == session_key and not self._is_expired(row):
         self._update_last_access(row)
         return wiking.module.Users.user(req, uid=row['uid'].value())
     else:
         return None
Beispiel #4
0
    def assigned_names(self, uid):
        """Return sequence of crypto names assigned to user identified by uid.

        Arguments:

          uid -- user uid, integer

        """
        return self._data.select_map(lambda row: row['name'], condition=pd.EQ('uid', pd.ival(uid)))
Beispiel #5
0
    def assigned_names(self, uid):
        """Return sequence of crypto names assigned to user identified by uid.

        Arguments:

          uid -- user uid, integer

        """
        return self._data.select_map(lambda row: row['name'],
                                     condition=pd.EQ('uid', pd.ival(uid)))
Beispiel #6
0
 def _customize_fields(self, fields):
     fields.modify_many((
         'value',
         'fee',
     ), fixed=True)
     fields.modify('fee',
                   editable=computer(lambda row, value: value is not None),
                   runtime_arguments=computer(
                       lambda row, value: dict(value=pd.ival(value))),
                   codebook='cb.InsuranceFee')
Beispiel #7
0
 def test_hidden(self):
     row, fields = self._fields((
         pp.Field('numeric', type=pd.Integer()),
         pp.Field('string', type=pd.String()),
         pp.Field('multiline', type=pd.String(), height=4),
         pp.Field('date', type=pd.Date()),
         pp.Field('datetime', type=pd.DateTime()),
         pp.Field('boolean', type=pd.Boolean()),
         pp.Field('checklist', type=pd.Array(inner_type=pd.Integer()),
                  enumerator=pd.FixedEnumerator(range(10)),
                  selection_type=pp.SelectionType.CHECKLIST),
         pp.Field('choice', type=pd.Integer(),
                  enumerator=pd.FixedEnumerator(range(10)),
                  selection_type=pp.SelectionType.CHOICE),
         pp.Field('radio', type=pd.Integer(),
                  enumerator=pd.FixedEnumerator(range(10)),
                  selection_type=pp.SelectionType.RADIO),
     ))
     context = self._export_context('cs')
     for fid, value, exported in (
             ('numeric', 5, '5'),
             ('string', 'x', 'x'),
             ('multiline', 'xxx\nxxx', 'xxx\nxxx'),
             ('date', datetime.date(2016, 8, 30), '30.08.2016'),
             ('datetime', datetime.datetime(2016, 8, 30, 12, 40, tzinfo=context.timezone()),
              '30.08.2016 12:40:00'),
             ('boolean', True, 'T'),
             ('boolean', False, 'F'),
             ('checklist', (pd.ival(1), pd.ival(4)), ('1', '4')),
             ('choice', 5, '5'),
             ('radio', 5, '5'),
     ):
         field = pu.find(fid, fields, key=lambda f: f.id)
         row[fid] = pd.Value(row.type(fid), value)
         self.assertEqual(context.localize(field.hidden(context)),
                          ''.join('<input type="hidden" name="%s" value=%s/>' %
                                  (fid, saxutils.quoteattr(v))
                                  for v in pu.xtuple(exported)))
         error = field.validate(self.Request(params={fid: exported}), context.locale_data())
         self.assertIs(error, None, "%s: %s" % (error and error.message(), exported))
         self.assertEqual(row[fid].value(), value)
Beispiel #8
0
 def test_prefill(self):
     row = self._mega_row(new=True, a=1, b=pd.ival(3), d=77)
     self._check_values(row, a=1, b=3, c=5, d=77, x=88)
Beispiel #9
0
 def _parent_filter(self, page_id):
     return pd.NE('page_id', pd.ival(None))
Beispiel #10
0
              type=pd.DateTime()), (datetime.datetime(2016,
                                                      8,
                                                      30,
                                                      12,
                                                      40,
                                                      tzinfo=Timezone()),
                                    '30.08.2016 12:40:00')),
    (pp.Field('daterange', type=pd.DateRange()), (pd.DateRange().adjust_value(
        (datetime.date(1975, 8, 30),
         datetime.date(2016, 8, 30))), ('30.08.1975', '30.08.2016'))),
    (pp.Field('boolean', type=pd.Boolean()), (True, 'T'), (False, 'F')),
    (pp.Field('checklist',
              type=pd.Array(inner_type=pd.Integer()),
              enumerator=pd.FixedEnumerator(range(10)),
              selection_type=pp.SelectionType.CHECKLIST),
     ((pd.ival(1), pd.ival(4)), ('1', '4'))),
    (pp.Field('choice',
              type=pd.Integer(),
              enumerator=pd.FixedEnumerator(range(10)),
              selection_type=pp.SelectionType.CHOICE), (5, '5')),
    (pp.Field('radio',
              type=pd.Integer(),
              enumerator=pd.FixedEnumerator(range(10)),
              selection_type=pp.SelectionType.RADIO), (5, '5')),
)


class Request:
    """Minimal request representation for testing purposes."""
    def __init__(self, params=None):
        self._params = params or {}