def sig_logs(self, widget=None): obj_id = self.id_get() if obj_id < 0 or obj_id is False: self.message_info(_('You have to select one record!')) return False fields = [ ('id', _('ID:')), ('create_uid.rec_name', _('Creation User:'******'create_date', _('Creation Date:')), ('write_uid.rec_name', _('Latest Modification by:')), ('write_date', _('Latest Modification Date:')), ] try: res = RPCExecute('model', self.model, 'read', [obj_id], [x[0] for x in fields], context=self.context) except RPCException: return message_str = '' for line in res: for (key, val) in fields: value = str(line.get(key, False) or '/') if line.get(key, False) \ and key in ('create_date', 'write_date'): display_format = date_format() + ' %H:%M:%S' date = timezoned_date(line[key]) value = common.datetime_strftime(date, display_format) message_str += val + ' ' + value + '\n' message_str += _('Model:') + ' ' + self.model message(message_str) return True
def modified(self, value): if value.get(self.name): text = datetime_strftime(timezoned_date(value[self.name]), self.get_format()) else: text = '' return self.widget.compute_date(self.widget.get_text()) != text
def get_client(self, record): value = super(DateTimeField, self).get_client(record) if value: value = common.timezoned_date(value) return datetime_strftime(value, date_format() + ' ' + self.time_format(record)) return ''
def sig_logs(self, widget=None): current_record = self.screen.current_record if not current_record or current_record.id < 0: self.message_info( _('You have to select one record.'), gtk.MESSAGE_INFO) return False fields = [ ('id', _('ID:')), ('create_uid.rec_name', _('Creation User:'******'create_date', _('Creation Date:')), ('write_uid.rec_name', _('Latest Modification by:')), ('write_date', _('Latest Modification Date:')), ] try: res = RPCExecute('model', self.model, 'read', [current_record.id], [x[0] for x in fields], context=self.screen.context) except RPCException: return date_format = self.screen.context.get('date_format', '%x') datetime_format = date_format + ' %X.%f' message_str = '' for line in res: for (key, val) in fields: value = str(line.get(key, False) or '/') if line.get(key, False) \ and key in ('create_date', 'write_date'): date = timezoned_date(line[key]) value = common.datetime_strftime(date, datetime_format) message_str += val + ' ' + value + '\n' message_str += _('Model:') + ' ' + self.model message(message_str) return True
def sig_logs(self, widget=None): current_record = self.screen.current_record if not current_record or current_record.id < 0: self.message_info( _('You have to select one record.'), gtk.MESSAGE_INFO) return False fields = [ ('id', _('ID:')), ('create_uid.rec_name', _('Creation User:'******'create_date', _('Creation Date:')), ('write_uid.rec_name', _('Latest Modification by:')), ('write_date', _('Latest Modification Date:')), ] try: res = RPCExecute('model', self.model, 'read', [current_record.id], [x[0] for x in fields], context=self.screen.context) except RPCException: return date_format = self.screen.context.get('date_format', '%x') datetime_format = date_format + ' %H:%M:%S.%f' message_str = '' for line in res: for (key, val) in fields: value = str(line.get(key, False) or '/') if line.get(key, False) \ and key in ('create_date', 'write_date'): date = timezoned_date(line[key]) value = common.datetime_strftime(date, datetime_format) message_str += val + ' ' + value + '\n' message_str += _('Model:') + ' ' + self.model message(message_str) return True
def sig_logs(self, widget=None): obj_id = self.id_get() if obj_id < 0 or obj_id is False: self.message_info(_('You have to select one record!')) return False fields = [ ('id', _('ID:')), ('create_uid.rec_name', _('Creation User:'******'create_date', _('Creation Date:')), ('write_uid.rec_name', _('Latest Modification by:')), ('write_date', _('Latest Modification Date:')), ] try: res = RPCExecute('model', self.model, 'read', [obj_id], [x[0] for x in fields], context=self.screen.context) except RPCException: return message_str = '' for line in res: for (key, val) in fields: value = str(line.get(key, False) or '/') if line.get(key, False) \ and key in ('create_date', 'write_date'): date = timezoned_date(line[key]) value = common.datetime_strftime(date, '%X') message_str += val + ' ' + value + '\n' message_str += _('Model:') + ' ' + self.model message(message_str) return True
def get_client(self, record): value = super(DateTimeField, self).get_client(record) if value: value = common.timezoned_date(value) return datetime_strftime( value, date_format() + ' ' + self.time_format(record)) return ''
def cal_open(self, widget): parent = get_toplevel_window() win = gtk.Dialog(_('Date Time Selection'), parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) win.set_has_separator(True) win.set_icon(TRYTON_ICON) win.vbox.set_spacing(2) hbox = gtk.HBox(spacing=2) hbox.pack_start(gtk.Label(_('Hour:')), expand=False, fill=False) widget_hour = gtk.SpinButton(gtk.Adjustment(0, 0, 23, 1, 5), 1, 0) hbox.pack_start(widget_hour, expand=True, fill=True) hbox.pack_start(gtk.Label(_('Minute:')), expand=False, fill=False) widget_minute = gtk.SpinButton( gtk.Adjustment(0, 0, 59, 1, 10), 1, 0) hbox.pack_start(widget_minute, expand=True, fill=True) win.vbox.pack_start(hbox, expand=False, fill=True) cal = gtk.Calendar() cal.set_display_options(gtk.CALENDAR_SHOW_HEADING | \ gtk.CALENDAR_SHOW_DAY_NAMES | \ gtk.CALENDAR_SHOW_WEEK_NUMBERS | \ gtk.CALENDAR_WEEK_START_MONDAY) cal.connect('day-selected-double-click', lambda *x: win.response(gtk.RESPONSE_OK)) win.vbox.pack_start(cal, expand=True, fill=True) win.show_all() self.set_value(self.record, self.field) val = self.field.get(self.record) if val: val = timezoned_date(val) widget_hour.set_value(val.hour) widget_minute.set_value(val.minute) cal.select_month(val.month - 1, val.year) cal.select_day(val.day) else: widget_hour.set_value(time.localtime()[3]) widget_minute.set_value(time.localtime()[4]) response = win.run() if response == gtk.RESPONSE_OK: hour = int(widget_hour.get_value()) minute = int(widget_minute.get_value()) year = int(cal.get_date()[0]) month = int(cal.get_date()[1]) + 1 day = int(cal.get_date()[2]) date = untimezoned_date(datetime.datetime(year, month, day, hour, minute)) self.field.set_client(self.record, date) self.display(self.record, self.field) self._focus_out() parent.present() win.destroy()
def format_datetime(): if not value: return '' format_ = context.get('date_format', '%x') + ' ' + time_format(field) if (not isinstance(value, datetime.datetime) or value.time() == datetime.time.min): format_ = '%x' time = value else: time = timezoned_date(value) return datetime_strftime(time, format_)
def format_datetime(): if not value: return '' format_ = context.get('date_format', '%x') + ' ' + time_format(field) if not isinstance(value, datetime.datetime): time = datetime.datetime.combine(value, datetime.time.min) else: time = timezoned_date(value) if time.time() == datetime.time.min: format_ = '%x' return datetime_strftime(time, format_)
def format_datetime(): if not value: return '' if not isinstance(value, datetime.datetime): time = datetime.datetime.combine(value, datetime.time.min) else: time = timezoned_date(value) format_ = date_format(context.get('date_format')) if time.time() != datetime.time.min: format_ += ' ' + time_format(field) return time.strftime(format_)
def sig_logs(self, widget=None): current_record = self.screen.current_record if not current_record or current_record.id < 0: self.message_info(_('You have to select one record.'), Gtk.MessageType.INFO) return False fields = [ ('id', _('ID:')), ('create_uid.rec_name', _('Created by:')), ('create_date', _('Created at:')), ('write_uid.rec_name', _('Edited by:')), ('write_date', _('Edited at:')), ] try: data = RPCExecute('model', self.model, 'read', [current_record.id], [x[0] for x in fields], context=self.screen.context)[0] except RPCException: return date_format = self.screen.context.get('date_format', '%x') datetime_format = date_format + ' %H:%M:%S.%f' message_str = '' for (key, label) in fields: value = data keys = key.split('.') name = keys.pop(-1) for key in keys: value = value.get(key + '.', {}) value = (value or {}).get(name, '/') if isinstance(value, datetime.datetime): value = timezoned_date(value).strftime(datetime_format) message_str += '%s %s\n' % (label, value) message_str += _('Model:') + ' ' + self.model message(message_str) return True
def set_value(self, value): self.widget.props.value = timezoned_date(value)
def __init__(self, revisions, revision=None, format_='%x %H:%M:%S.%f'): self.parent = get_toplevel_window() self.win = Gtk.Dialog(title=_('Revision'), transient_for=self.parent, modal=True, destroy_with_parent=True) Main().add_window(self.win) cancel_button = self.win.add_button(set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) cancel_button.set_image( IconFactory.get_image('tryton-cancel', Gtk.IconSize.BUTTON)) cancel_button.set_always_show_image(True) ok_button = self.win.add_button(set_underline(_("OK")), Gtk.ResponseType.OK) ok_button.set_image( IconFactory.get_image('tryton-ok', Gtk.IconSize.BUTTON)) ok_button.set_always_show_image(True) self.win.set_default_response(Gtk.ResponseType.OK) self.win.set_icon(GNUHEALTH_ICON) self.win.vbox.set_spacing(3) self.win.vbox.pack_start(Gtk.Label(label=_('Select a revision')), expand=False, fill=True, padding=0) self.win.vbox.pack_start(Gtk.HSeparator(), expand=True, fill=True, padding=0) hbox = Gtk.HBox(spacing=3) label = Gtk.Label(label=_('Revision:')) hbox.pack_start(label, expand=True, fill=True, padding=0) list_store = Gtk.ListStore(str, str) # Set model on instantiation to get the default cellrenderer as text combobox = Gtk.ComboBox(model=list_store, has_entry=True) self.entry = combobox.get_child() self.entry.connect('focus-out-event', self.focus_out) self.entry.connect('activate', self.activate) label.set_mnemonic_widget(self.entry) combobox.connect('changed', self.changed) self.entry.set_property('activates_default', True) self._format = format_ if revision: self.entry.set_text(revision.strftime(self._format)) self._value = revision active = -1 else: self._value = None active = 0 list_store.append(('', '')) for i, (rev, id_, name) in enumerate(revisions, 1): list_store.append( (timezoned_date(rev).strftime(self._format), name)) if rev == revision: active = i combobox.set_active(active) cell = Gtk.CellRendererText() combobox.pack_start(cell, expand=True) combobox.add_attribute(cell, 'text', 1) hbox.pack_start(combobox, expand=True, fill=True, padding=0) combobox.set_entry_text_column(0) self.win.vbox.pack_start(hbox, expand=True, fill=True, padding=0) self.win.show_all()
def get_client(self, record): value = super(DateTimeField, self).get_client(record) if value: return common.timezoned_date(value)