Esempio n. 1
0
def dbinsert(spec, row, transaction=None):
    """Provede insert do tabulky dané specifikací.

    Argumenty:

      spec -- název specifikace datového objektu nad kterým má být proveden
        insert.
      row -- sekvence dvouprvkových sekvencí (id, value) nebo instance
        pd.Row
      transaction -- instance pd.DBTransactionDefault

    Vrací počet vložených řádků.

    """
    assert isinstance(row, (pd.Row, tuple, list)), row
    import pytis.form
    if isinstance(row, (tuple, list)):
        for item in row:
            if not isinstance(item, (tuple, list)) or len(item) != 2:
                errmsg = 'Column definition must be (ID, VALUE) pair.'
                raise ProgramError(errmsg)
            k, v = item
            if not isinstance(k, basestring):
                errmsg = 'Invalid column id %s' % k
                raise ProgramError(errmsg)
            if not isinstance(v, pd.Value):
                errmsg = 'Invalid column value %s' % v
                raise ProgramError(errmsg)
        row = pd.Row(row)
    data = pytis.util.data_object(spec)
    success, result = pytis.form.db_operation(data.insert, row, transaction=transaction)
    return result
Esempio n. 2
0
 def __setitem__(self, row, the_row):
     start = self._start_row
     try:
         index = row - start
         if index >= 0:
             self._cache[index] = the_row
         else:
             raise IndexError()
     except IndexError:
         size = self._size
         end = start + size
         new_start = max(row - size / 2, 0)
         new_end = new_start + size
         if end <= new_start or new_end <= start:
             cache = self._allocate(size)
         elif end < new_end:
             diff = new_end - end
             cache = self._cache[diff:] + self._allocate(diff)
         elif start > new_start:
             diff = start - new_start
             cache = self._allocate(diff) + self._cache[:-diff]
         else:
             raise ProgramError(start, end, new_start, new_end)
         assert len(cache) == self._size, len(cache)
         self._start_row = new_start
         cache[row - new_start] = the_row
         self._cache = cache
Esempio n. 3
0
    def cookie(self, name, default=None):
        """Return the value of given cookie as a unicode string.

        The 'default' value is returned if given cookie was not present in the HTTP request.

        """
        raise ProgramError(
            "Pytis Request interface not implemented by derived class!")
Esempio n. 4
0
 def x(arg):
     if sys.version_info[0] == 2 and isinstance(arg, str):
         try:
             arg = unistr(arg, charset)
         except Exception:
             raise ProgramError(
                 "Cannot convert argument to unicode for charset %s" %
                 (charset, ))
         arg = arg.encode('UTF-8')
     return arg
Esempio n. 5
0
    def set_cookie(self, name, value, expires=None):
        """Set the value of given cookie.

        The value of cookie 'name' will be set to a string 'value', with optional expiration time
        set to 'expires' seconds.  This cookie will be sent with the HTTP response for the current
        request.

        """
        raise ProgramError(
            "Pytis Request interface not implemented by derived class!")
Esempio n. 6
0
    def param(self, name, default=None):
        """Return the value of request parameter 'name'.

        The returned value is a unicode string (with HTTP escapes decoded) for ordinary parameters,
        a 'FileUpload' instance for uploaded multipart data or a sequence of such values when
        multiple values of the parameter were sent with the request.

        """
        raise ProgramError(
            "Pytis Request interface not implemented by derived class!")
Esempio n. 7
0
    def uri(self):
        """Return request URI path relative to server's root.

        The returned URI is a unicode value, which normally starts with a slash
        and continues with an arbitrary numper of path elements separated by
        slashes.  Transfer encoding and HTTP escapes are decoded.

        """
        raise ProgramError(
            "Pytis Request interface not implemented by derived class!")
Esempio n. 8
0
 def set(self, default):
     import subprocess
     p = subprocess.Popen(["lpoptions", "-d", default],
                          close_fds=True,
                          stdin=open("/dev/null", 'r'),
                          stdout=open("/dev/null", 'w'),
                          stderr=subprocess.PIPE)
     (stdout, stderr) = p.communicate()
     exitcode = p.wait()
     if exitcode != 0:
         raise ProgramError(stderr.strip())
     return
Esempio n. 9
0
def help_page(uri):
    """Return a help page for given URI as a 'lcg.ContentNode' instance."""
    global generator
    if not generator:
        for cls in (DmpHelpGenerator, SpecHelpGenerator):
            try:
                generator = cls()
                break
            except HelpGenerator.NotAvailable:
                continue
        else:
            raise ProgramError("No usable help generator available.")
    return generator.help_page(uri)
Esempio n. 10
0
def dbupdate_many(spec, condition=None, update_row=None,
                  transaction=None):
    """Provede update nad tabulkou danou specifikací.

    Argumenty:

      spec -- specifikace datového objektu nad kterým má být proveden
        select; string'
      condition -- podmínka updatovaní.
      update_row -- řádek kterým se provede update,
      transaction -- instance pd.DBTransactionDefault

    Vrací počet updatovaných řádků.

    """
    if not isinstance(condition, pd.Operator):
        errmsg = "Nebyla předána podmínka pro update_many."
        raise ProgramError(errmsg)
    if not isinstance(update_row, pd.Row):
        errmsg = "Nebyl předán řádek pro update_many."
        raise ProgramError(errmsg)
    data = pytis.util.data_object(spec)
    return data.update_many(condition, update_row, transaction=transaction)
Esempio n. 11
0
 def _create_form(self):
     # Vytvoř rozdělené okno
     self._splitter = splitter = wx.SplitterWindow(self._parent, -1)
     wx_callback(wx.EVT_SPLITTER_DOUBLECLICKED, splitter, splitter.GetId(),
                 lambda e: True)
     wx_callback(wx.EVT_SPLITTER_SASH_POS_CHANGED, splitter,
                 splitter.GetId(), self._on_sash_changed)
     # Vytvoř formuláře
     self._main_form = self._create_main_form(splitter,
                                              **self._unprocessed_kwargs)
     self._side_form = self._create_side_form(splitter)
     orientation = self._initial_orientation()
     if orientation == Orientation.HORIZONTAL:
         splitter.SplitHorizontally(self._main_form, self._side_form)
     elif orientation == Orientation.VERTICAL:
         splitter.SplitVertically(self._main_form, self._side_form)
     else:
         raise ProgramError("Invalid dual form orientation: %r" %
                            orientation)
     if isinstance(self._main_form, EditForm):
         gravity = 0
     elif isinstance(self._side_form, EditForm):
         gravity = 1
     elif orientation == Orientation.HORIZONTAL:
         gravity = 0.5
     else:
         gravity = 0
     splitter.SetSashGravity(gravity)
     splitter.SetMinimumPaneSize(80)
     # Setting a minimal size here is a hack to avoid wx/gtk hanging when
     # the splitter size becomes too small.  It is unknown what actually
     # causes the hang, but 180x180 seems to be the lowest minimal size
     # which avoids it.
     splitter.SetMinSize((180, 180))
     self._select_form(self._main_form)
     self._set_main_form_callbacks()
     self._set_side_form_callbacks()
Esempio n. 12
0
 def default_value(self):
     value, error = self.validate('0')
     if error is not None:
         raise ProgramError("Can't validate default value")
     return value
Esempio n. 13
0
 def mime_type(self):
     """Return the mime type provided byt he UA as a string"""
     raise ProgramError(
         "Pytis FileUpload interface not implemented by derived class!")
Esempio n. 14
0
 def filename(self):
     """Return the original filename (without path) as a unicode string."""
     raise ProgramError(
         "Pytis FileUpload interface not implemented by derived class!")
Esempio n. 15
0
 def file(self):
     """Return an open file-like object from which the data may be read."""
     raise ProgramError(
         "Pytis FileUpload interface not implemented by derived class!")
Esempio n. 16
0
 def localizer(self):
     """Return an 'lcg.Localizer()' instance for the current request locales."""
     raise ProgramError(
         "Pytis Request interface not implemented by derived class!")
Esempio n. 17
0
 def __init__(self):
     ProgramError.__init__(self, 'Not within select')
Esempio n. 18
0
 def has_param(self, name):
     """Return true if the parameter 'name' was sent with the request."""
     raise ProgramError(
         "Pytis Request interface not implemented by derived class!")