示例#1
0
 def get_value(self):
     from_ = self._get_value(self.from_)
     to = self._get_value(self.to)
     if from_ and to:
         if from_ != to:
             return '%s..%s' % (quote(from_), quote(to))
         else:
             return quote(from_)
     elif from_:
         return '>=%s' % quote(from_)
     elif to:
         return '<=%s' % quote(to)
示例#2
0
 def get_value(self):
     from_ = self._get_value(self.from_)
     to = self._get_value(self.to)
     if from_ and to:
         if from_ != to:
             return '%s..%s' % (quote(from_), quote(to))
         else:
             return quote(from_)
     elif from_:
         return '>=%s' % quote(from_)
     elif to:
         return '<=%s' % quote(to)
示例#3
0
    def _sig_add(self, *args):
        if not self.focus_out:
            return
        domain = self.field.domain_get(self.record)
        add_remove = self.record.expr_eval(self.attrs.get('add_remove'))
        if add_remove:
            domain = [domain, add_remove]
        context = self.field.context_get(self.record)
        value = self.wid_text.get_text().decode('utf-8')

        self.focus_out = False

        def callback(result):
            self.focus_out = True
            if result:
                ids = [x[0] for x in result]
                self.screen.load(ids, modified=True)
                self.screen.display(res_id=ids[0])
            self.screen.set_cursor()
            self.wid_text.set_text('')
        win = WinSearch(self.attrs['relation'], callback, sel_multi=True,
            context=context, domain=domain,
            view_ids=self.attrs.get('view_ids', '').split(','),
            views_preload=self.attrs.get('views', {}),
            new=self.attrs.get('create', True))
        win.screen.search_filter(quote(value))
        win.show()
示例#4
0
文件: widget.py 项目: zarumaru/tryton
    def search_remote(self, record, field, text, callback=None):
        model = self.get_model(record, field)
        domain = field.domain_get(record)
        context = field.get_search_context(record)
        order = field.get_search_order(record)
        access = common.MODELACCESS[model]
        create_access = int(self.attrs.get('create', 1)) and access['create']

        def search_callback(found):
            value = None
            if found:
                value = self.value_from_id(model, *found[0])
                field.set_client(record, value)
            if callback:
                callback()

        win = WinSearch(model,
                        search_callback,
                        sel_multi=False,
                        context=context,
                        domain=domain,
                        order=order,
                        view_ids=self.attrs.get('view_ids', '').split(','),
                        new=create_access,
                        title=self.attrs.get('string'))
        win.screen.search_filter(quote(text))
        return win
示例#5
0
    def _sig_add(self, *args):
        if not self.focus_out:
            return
        domain = self.field.domain_get(self.record)
        add_remove = self.record.expr_eval(self.attrs.get('add_remove'))
        if add_remove:
            domain = [domain, add_remove]
        context = self.field.get_context(self.record)
        value = self.wid_text.get_text().decode('utf-8')

        self.focus_out = False

        def callback(result):
            self.focus_out = True
            if result:
                ids = [x[0] for x in result]
                self.screen.load(ids, modified=True)
                self.screen.display(res_id=ids[0])
            self.screen.set_cursor()
            self.wid_text.set_text('')

        win = WinSearch(self.attrs['relation'],
                        callback,
                        sel_multi=True,
                        context=context,
                        domain=domain,
                        view_ids=self.attrs.get('view_ids', '').split(','),
                        views_preload=self.attrs.get('views', {}),
                        new=self.attrs.get('create', True),
                        title=self.attrs.get('string'))
        win.screen.search_filter(quote(value))
        win.show()
示例#6
0
    def _sig_add(self, *args):
        if not self.focus_out:
            return
        domain = self.field.domain_get(self.record)
        add_remove = self.record.expr_eval(self.attrs.get('add_remove'))
        if add_remove:
            domain = [domain, add_remove]
        context = self.field.get_search_context(self.record)
        order = self.field.get_search_order(self.record)
        value = self.wid_text.get_text()

        self.focus_out = False

        def callback(result):
            self.focus_out = True
            if result:
                ids = [x[0] for x in result]
                self.screen.load(ids, modified=True)
                self.screen.display(res_id=ids[0])
            self.screen.set_cursor()
            self.wid_text.set_text('')
        win = WinSearch(self.attrs['relation'], callback, sel_multi=True,
            context=context, domain=domain, order=order,
            view_ids=self.attrs.get('view_ids', '').split(','),
            views_preload=self.attrs.get('views', {}),
            new=self.create_access,
            title=self.attrs.get('string'))
        win.screen.search_filter(quote(value))
        if len(win.screen.group) == 1:
            win.response(None, Gtk.ResponseType.OK)
        else:
            win.show()
示例#7
0
    def search_remote(self,
                      record,
                      relation,
                      text,
                      domain=None,
                      context=None,
                      callback=None):
        field = record.group.fields[self.attrs['name']]
        relation = field.attrs['relation']
        access = common.MODELACCESS[relation]
        create_access = self.attrs.get('create', True) and access['create']

        def search_callback(found):
            value = None
            if found:
                value = found[0]
            field.set_client(record, value)
            if callback:
                callback()

        win = WinSearch(relation,
                        search_callback,
                        sel_multi=False,
                        context=context,
                        domain=domain,
                        view_ids=self.attrs.get('view_ids', '').split(','),
                        new=create_access,
                        title=self.attrs.get('string'))
        win.screen.search_filter(quote(text.decode('utf-8')))
        return win
 def get_value(self):
     values = []
     model, paths = self.treeview.get_selection().get_selected_rows()
     for path in paths:
         iter_ = model.get_iter(path)
         values.append(model.get_value(iter_, 0))
     return ';'.join(quote(v) for v in values)
 def search():
     button.set_active(False)
     self.search_window.hide()
     text = ''
     for label, entry in self.search_table.fields:
         if isinstance(entry, gtk.ComboBox):
             value = quote(entry.get_active_text())
         elif isinstance(entry, (Dates, Selection)):
             value = entry.get_value()
         else:
             value = quote(entry.get_text())
         if value:
             text += label + ' ' + value + ' '
     self.set_text(text)
     self.last_search_text = self.get_text()
     self.do_search()
示例#10
0
    def search_remote(self, record, field, text, callback=None):
        relation = field.attrs['relation']
        domain = field.domain_get(record)
        context = field.get_search_context(record)
        order = field.get_search_order(record)
        access = common.MODELACCESS[relation]
        create_access = self.attrs.get('create', True) and access['create']

        def search_callback(found):
            value = None
            if found:
                value = found[0]
            field.set_client(record, value)
            if callback:
                callback()

        win = WinSearch(relation,
                        search_callback,
                        sel_multi=False,
                        context=context,
                        domain=domain,
                        order=order,
                        view_ids=self.attrs.get('view_ids', '').split(','),
                        new=create_access,
                        title=self.attrs.get('string'))
        win.screen.search_filter(quote(text))
        return win
示例#11
0
 def search():
     self.search_popover.popdown()
     text = ''
     for label, entry in self.search_grid.fields:
         if isinstance(entry, Gtk.ComboBoxText):
             value = quote(entry.get_active_text()) or None
         elif isinstance(entry, (Between, Selection)):
             value = entry.get_value()
         else:
             value = quote(entry.get_text()) or None
         if value is not None:
             text += quote(label) + ': ' + value + ' '
     self.set_text(text)
     self.do_search()
     # Store text after doing the search
     # because domain parser could simplify the text
     self.last_search_text = self.get_text()
示例#12
0
 def search():
     self.search_window.hide()
     text = ''
     for label, entry in self.search_table.fields:
         if isinstance(entry, gtk.ComboBox):
             value = quote(entry.get_active_text()) or None
         elif isinstance(entry, (Dates, Selection)):
             value = entry.get_value()
         else:
             value = quote(entry.get_text()) or None
         if value is not None:
             text += quote(label) + ': ' + value + ' '
     self.set_text(text)
     self.do_search()
     # Store text after doing the search
     # because domain parser could simplify the text
     self.last_search_text = self.get_text()
示例#13
0
    def sig_edit(self, entry=None, icon_pos=None, *args):
        model = self.get_model()
        if not model or not common.MODELACCESS[model]['read']:
            return
        if not self.focus_out or not self.field:
            return
        self.changed = False
        self.focus_out = False
        value = self.field.get(self.record)

        if (icon_pos == Gtk.EntryIconPosition.SECONDARY
                and not self._readonly
                and self.has_target(value)):
            self.field.set_client(self.record, self.value_from_id(None, ''))
            self.wid_text.set_text('')
            self.changed = True
            self.focus_out = True
            return

        if self.has_target(value):
            screen = self.get_screen()
            screen.load([self.id_from_value(self.field.get(self.record))])

            def callback(result):
                if result:
                    self.field.set_client(self.record,
                        self.value_from_id(screen.current_record.id,
                            screen.current_record.rec_name()),
                        force_change=True)
                self.focus_out = True
                self.changed = True
            WinForm(screen, callback, save_current=True,
                title=self.attrs.get('string'))
            return
        if not self._readonly:
            domain = self.field.domain_get(self.record)
            context = self.field.get_search_context(self.record)
            order = self.field.get_search_order(self.record)
            text = self.wid_text.get_text()

            def callback(result):
                if result:
                    self.field.set_client(self.record,
                        self.value_from_id(*result[0]), force_change=True)
                self.focus_out = True
                self.changed = True
            win = WinSearch(model, callback, sel_multi=False,
                context=context, domain=domain, order=order,
                view_ids=self.attrs.get('view_ids', '').split(','),
                views_preload=self.attrs.get('views', {}),
                new=self.create_access, title=self.attrs.get('string'),
                exclude_field=self.attrs.get('relation_field'))
            win.screen.search_filter(quote(text))
            win.show()
            return
        self.focus_out = True
        self.changed = True
示例#14
0
 def get_value(self):
     values = []
     model, paths = self.treeview.get_selection().get_selected_rows()
     if not paths:
         return
     for path in paths:
         iter_ = model.get_iter(path)
         values.append(model.get_value(iter_, 0))
     return ';'.join(quote(v) for v in values)
示例#15
0
 def search():
     button.set_active(False)
     self.search_window.hide()
     text = ''
     for label, entry in self.search_table.fields:
         if isinstance(entry, gtk.ComboBox):
             value = quote(entry.get_active_text()) or None
         elif isinstance(entry, (Dates, Selection)):
             value = entry.get_value()
         else:
             value = quote(entry.get_text()) or None
         if value is not None:
             text += quote(label) + ': ' + value + ' '
     self.set_text(text)
     self.do_search()
     # Store text after doing the search
     # because domain parser could simplify the text
     self.last_search_text = self.get_text()
示例#16
0
    def sig_edit(self, *args):
        model = self.get_model()
        if not model or not common.MODELACCESS[model]['read']:
            return
        if not self.focus_out or not self.field:
            return
        self.changed = False
        value = self.field.get(self.record)
        model = self.get_model()

        self.focus_out = False
        if model and self.has_target(value):
            screen = self.get_screen()
            screen.load([self.id_from_value(self.field.get(self.record))])

            def callback(result):
                if result:
                    self.field.set_client(
                        self.record,
                        self.value_from_id(screen.current_record.id,
                                           screen.current_record.rec_name()),
                        force_change=True)
                self.focus_out = True
                self.changed = True

            WinForm(screen, callback, save_current=True)
            return
        elif model and not self._readonly:
            domain = self.field.domain_get(self.record)
            context = self.field.context_get(self.record)
            text = self.wid_text.get_text().decode('utf-8')

            def callback(result):
                if result:
                    self.field.set_client(self.record,
                                          self.value_from_id(*result[0]),
                                          force_change=True)
                self.focus_out = True
                self.changed = True

            win = WinSearch(model,
                            callback,
                            sel_multi=False,
                            context=context,
                            domain=domain,
                            view_ids=self.attrs.get('view_ids', '').split(','),
                            views_preload=self.attrs.get('views', {}),
                            new=self.create_access)
            win.screen.search_filter(quote(text))
            win.show()
            return
        self.focus_out = True
        self.changed = True
        return
 def search():
     button.set_active(False)
     self.search_window.hide()
     text = ''
     for label, entry in self.search_table.fields:
         if isinstance(entry, gtk.ComboBox):
             value = entry.get_active_text()
         else:
             value = entry.get_text()
         if value:
             text += label + ' ' + quote(value) + ' '
     self.set_text(text)
     self.do_search()
示例#18
0
    def sig_activate(self):
        model = self.get_model()
        if not model or not common.MODELACCESS[model]['read']:
            return
        if not self.focus_out or not self.field:
            return
        self.changed = False
        value = self.field.get(self.record)
        model = self.get_model()

        self.focus_out = False
        if model and not self.has_target(value):
            if (not self._readonly and
                (self.wid_text.get_text()
                 or self.field.get_state_attrs(self.record)['required'])):
                domain = self.field.domain_get(self.record)
                context = self.field.get_search_context(self.record)
                order = self.field.get_search_order(self.record)
                text = self.wid_text.get_text()

                def callback(result):
                    if result:
                        self.field.set_client(self.record,
                                              self.value_from_id(*result[0]),
                                              force_change=True)
                    else:
                        self.wid_text.set_text('')
                    self.focus_out = True
                    self.changed = True

                win = WinSearch(model,
                                callback,
                                sel_multi=False,
                                context=context,
                                domain=domain,
                                order=order,
                                view_ids=self.attrs.get('view_ids',
                                                        '').split(','),
                                views_preload=self.attrs.get('views', {}),
                                new=self.create_access,
                                title=self.attrs.get('string'),
                                exclude_field=self.attrs.get('relation_field'))
                win.screen.search_filter(quote(text))
                if len(win.screen.group) == 1:
                    win.response(None, Gtk.ResponseType.OK)
                else:
                    win.show()
                return
        self.focus_out = True
        self.changed = True
        return
示例#19
0
    def _sig_add(self, *args):
        context = self.field.context_get(self.record)
        value = self.wid_text.get_text().decode('utf-8')
        domain = self.field.domain_get(self.record)

        def callback(result):
            if result:
                self.add_new_keys([r[0] for r in result])
            self.wid_text.set_text('')

        win = WinSearch(self.schema_model, callback, sel_multi=True,
            context=context, domain=domain, new=False)
        win.screen.search_filter(quote(value))
        win.show()
示例#20
0
    def _sig_add(self, *args):
        context = self.field.get_context(self.record)
        value = self.wid_text.get_text()
        domain = self.field.domain_get(self.record)

        def callback(result):
            if result:
                self.add_new_keys([r[0] for r in result])
            self.wid_text.set_text('')

        win = WinSearch(self.schema_model, callback, sel_multi=True,
            context=context, domain=domain, new=False)
        win.screen.search_filter(quote(value))
        win.show()
示例#21
0
    def sig_edit(self, *args):
        model = self.get_model()
        if not model or not common.MODELACCESS[model]['read']:
            return
        if not self.focus_out or not self.field:
            return
        self.changed = False
        value = self.field.get(self.record)
        model = self.get_model()

        self.focus_out = False
        if model and self.has_target(value):
            screen = self.get_screen()
            screen.load([self.id_from_value(self.field.get(self.record))])

            def callback(result):
                if result:
                    self.field.set_client(self.record,
                        self.value_from_id(screen.current_record.id,
                            screen.current_record.rec_name()),
                        force_change=True)
                self.focus_out = True
                self.changed = True
            WinForm(screen, callback, save_current=True)
            return
        elif model and not self._readonly:
            domain = self.field.domain_get(self.record)
            context = self.field.context_get(self.record)
            text = self.wid_text.get_text().decode('utf-8')

            def callback(result):
                if result:
                    self.field.set_client(self.record,
                        self.value_from_id(*result[0]), force_change=True)
                self.focus_out = True
                self.changed = True
            win = WinSearch(model, callback, sel_multi=False,
                context=context, domain=domain,
                view_ids=self.attrs.get('view_ids', '').split(','),
                views_preload=self.attrs.get('views', {}),
                new=self.create_access)
            win.screen.search_filter(quote(text))
            win.show()
            return
        self.focus_out = True
        self.changed = True
        return
示例#22
0
    def _sig_add(self, *args):
        from tryton.gui.window.win_search import WinSearch
        domain = self.domain[:]
        model_name = self.screen.model_name
        value = self.wid_text.get_text().decode('utf-8')

        def callback(result):
            if result:
                ids = [x[0] for x in result]
                self.screen.load(ids, modified=True)
                self.screen.display(res_id=ids[0])
            self.screen.set_cursor()
            self.wid_text.set_text('')

        win = WinSearch(model_name, callback, sel_multi=True,
            context=self.context, domain=domain)
        win.screen.search_filter(quote(value))
        win.show()
示例#23
0
    def search_remote(self, record, relation, text, domain=None,
            context=None, callback=None):
        field = record.group.fields[self.attrs['name']]
        relation = field.attrs['relation']
        access = common.MODELACCESS[relation]
        create_access = self.attrs.get('create', True) and access['create']

        def search_callback(found):
            value = None
            if found:
                value = found[0]
            field.set_client(record, value)
            if callback:
                callback()
        win = WinSearch(relation, search_callback, sel_multi=False,
            context=context, domain=domain, new=create_access)
        win.screen.search_filter(quote(text.decode('utf-8')))
        return win
示例#24
0
    def _sig_add(self, *args):
        from tryton.gui.window.win_search import WinSearch
        domain = self.domain[:]
        model_name = self.screen.model_name
        value = self.wid_text.get_text()

        def callback(result):
            if result:
                ids = [x[0] for x in result]
                self.screen.load(ids, modified=True)
                self.screen.display(res_id=ids[0])
            self.screen.set_cursor()
            self.wid_text.set_text('')

        win = WinSearch(model_name, callback, sel_multi=True,
            context=self.context, domain=domain)
        win.screen.search_filter(quote(value))
        win.show()
示例#25
0
    def _sig_add(self, *args):
        if not self.focus_out:
            return
        access = common.MODELACCESS[self.screen.model_name]
        if not access['write'] or not access['read']:
            return
        self.view.set_value()
        domain = self.field.domain_get(self.record)
        context = self.field.get_search_context(self.record)
        domain = [domain, self.record.expr_eval(self.attrs.get('add_remove'))]
        removed_ids = self.field.get_removed_ids(self.record)
        domain = ['OR', domain, ('id', 'in', removed_ids)]
        text = self.wid_text.get_text()

        self.focus_out = False

        sequence = self._sequence()

        def callback(result):
            self.focus_out = True
            if result:
                ids = [x[0] for x in result]
                self.screen.load(ids, modified=True)
                self.screen.display(res_id=ids[0])
                if sequence:
                    self.screen.group.set_sequence(
                        field=sequence, position=self.screen.new_position)
            self.screen.set_cursor()
            self.wid_text.set_text('')

        order = self.field.get_search_order(self.record)
        win = WinSearch(self.attrs['relation'],
                        callback,
                        sel_multi=True,
                        context=context,
                        domain=domain,
                        order=order,
                        view_ids=self.attrs.get('view_ids', '').split(','),
                        views_preload=self.attrs.get('views', {}),
                        new=self.but_new.get_property('sensitive'),
                        title=self.attrs.get('string'),
                        exclude_field=self.attrs.get('relation_field'))
        win.screen.search_filter(quote(text))
        win.show()
示例#26
0
    def sig_activate(self):
        model = self.get_model()
        if not model or not common.MODELACCESS[model]['read']:
            return
        if not self.focus_out or not self.field:
            return
        self.changed = False
        value = self.field.get(self.record)
        model = self.get_model()

        self.focus_out = False
        if model and not self.has_target(value):
            if (not self._readonly
                    and (self.wid_text.get_text()
                        or self.field.get_state_attrs(
                            self.record)['required'])):
                domain = self.field.domain_get(self.record)
                context = self.field.context_get(self.record)
                text = self.wid_text.get_text().decode('utf-8')

                def callback(result):
                    if result:
                        self.field.set_client(self.record,
                            self.value_from_id(*result[0]), force_change=True)
                    else:
                        self.set_text('')
                    self.focus_out = True
                    self.changed = True

                win = WinSearch(model, callback, sel_multi=False,
                    context=context, domain=domain,
                    view_ids=self.attrs.get('view_ids', '').split(','),
                    views_preload=self.attrs.get('views', {}),
                    new=self.create_access)
                win.screen.search_filter(quote(text))
                if len(win.screen.group) == 1:
                    win.response(None, gtk.RESPONSE_OK)
                else:
                    win.show()
                return
        self.focus_out = True
        self.changed = True
        return
示例#27
0
    def _sig_add(self, *args):
        if not self.focus_out:
            return
        access = common.MODELACCESS[self.screen.model_name]
        if not access["write"] or not access["read"]:
            return
        domain = self.field.domain_get(self.record)
        context = self.field.context_get(self.record)
        domain = [domain, self.record.expr_eval(self.attrs.get("add_remove"))]
        removed_ids = self.field.get_removed_ids(self.record)
        domain = ["OR", domain, ("id", "in", removed_ids)]
        text = self.wid_text.get_text().decode("utf-8")

        self.focus_out = False

        sequence = None
        if self.screen.current_view.view_type == "tree":
            sequence = self.screen.current_view.attributes.get("sequence")

        def callback(result):
            self.focus_out = True
            if result:
                ids = [x[0] for x in result]
                self.screen.load(ids, modified=True)
                self.screen.display(res_id=ids[0])
                if sequence:
                    self.screen.group.set_sequence(field=sequence)
            self.screen.set_cursor()
            self.wid_text.set_text("")

        win = WinSearch(
            self.attrs["relation"],
            callback,
            sel_multi=True,
            context=context,
            domain=domain,
            view_ids=self.attrs.get("view_ids", "").split(","),
            views_preload=self.attrs.get("views", {}),
            new=self.but_new.get_property("sensitive"),
        )
        win.screen.search_filter(quote(text))
        win.show()
示例#28
0
    def _sig_add(self, *args):
        if not self.focus_out:
            return
        access = common.MODELACCESS[self.screen.model_name]
        if not access['write'] or not access['read']:
            return
        self.view.set_value()
        domain = self.field.domain_get(self.record)
        context = self.field.context_get(self.record)
        domain = [domain, self.record.expr_eval(self.attrs.get('add_remove'))]
        removed_ids = self.field.get_removed_ids(self.record)
        domain = ['OR', domain, ('id', 'in', removed_ids)]
        text = self.wid_text.get_text().decode('utf-8')

        self.focus_out = False

        sequence = None
        if self.screen.current_view.view_type == 'tree':
            sequence = self.screen.current_view.attributes.get('sequence')

        def callback(result):
            self.focus_out = True
            if result:
                ids = [x[0] for x in result]
                self.screen.load(ids, modified=True)
                self.screen.display(res_id=ids[0])
                if sequence:
                    self.screen.group.set_sequence(field=sequence)
            self.screen.set_cursor()
            self.wid_text.set_text('')

        win = WinSearch(self.attrs['relation'], callback, sel_multi=True,
            context=context, domain=domain,
            view_ids=self.attrs.get('view_ids', '').split(','),
            views_preload=self.attrs.get('views', {}),
            new=self.but_new.get_property('sensitive'))
        win.screen.search_filter(quote(text))
        win.show()
示例#29
0
    def search_remote(self,
                      record,
                      relation,
                      text,
                      domain=None,
                      context=None,
                      callback=None):
        field = record.group.fields[self.attrs['name']]

        def search_callback(found):
            value = None
            if found:
                value = found[0]
            field.set_client(record, value)
            if callback:
                callback()

        win = WinSearch(relation,
                        search_callback,
                        sel_multi=False,
                        context=context,
                        domain=domain)
        win.screen.search_filter(quote(text.decode('utf-8')))
        return win
 def test_quote(self):
     "Test quote"
     self.assertEqual(quote('test'), 'test')
     self.assertEqual(quote('foo bar'), '"foo bar"')
     self.assertEqual(quote('"foo"'), '\\\"foo\\\"')
     self.assertEqual(quote('foo\\bar'), 'foo\\\\bar')