Ejemplo n.º 1
0
def create_db():
  response.subtitle = T("Database Creation")
  response.view='nas/index.html'
  alias = db((db.databases.deleted==False)).select(db.databases.id,db.databases.alias,orderby=db.databases.alias)
  cmb_alias = SELECT(*[OPTION(field["alias"],_value=field["alias"]) for field in alias], _id="cmb_alias", _style="margin-top: 0px;")
  if len(cmb_alias)==0:
    cmb_alias.insert(0, OPTION("", _value=""))
  gform = DIV(
             HR(),
             P(SPAN(T('1. Create a new database alias. See ')),A("Customer Databases",_href=URL("databases"),_style="color:#0069D6;font-style: italic;"),
               BR(),
               SPAN(T('2. The sqlite and Google SQL databases are created automatically.')),
               BR(),
               SPAN(T('3. Other types of databases must be created manually before.')),
               BR(),
               SPAN(T('4. Please select an alias, and start the creation:'))
               ,_style="font-style: italic;"),
             DIV(SPAN(T('Database alias:'),_style="padding-right: 15px;padding-left: 15px;"),cmb_alias,
               P(SPAN(T('Starting the process?'), _id="msg_result",_style="font-style: italic;"),
                 ui.control.get_mobil_button(label=T("Start"), href="#", onclick="createDatabase();", 
                 cformat=None, icon="check", theme="b", style="width: 100px;"),
               _style="padding-top: 0px;")),
             HR()
             ,_style="font-weight: bold;", _align="left")
  return dict(form=gform)
Ejemplo n.º 2
0
def tz_nice_detector_widget(field, value, **attributes):
    options = []
    value_missing = True
    for tzn in TZSETS:
        #retrieve offset
        localized = datetime.datetime.now(pytz.timezone(tzn[0]))
        if value == tzn[0]:
            # This is the preselected value.
            value_missing = False
            options.append(
                OPTION(
                    tzn[1],
                    _value=tzn[0],
                    _selected="selected",
                    data=dict(localized=localized.strftime('%Y-%m-%d %H:%M'))))
        else:
            options.append(
                OPTION(
                    tzn[1],
                    _value=tzn[0],
                    data=dict(localized=localized.strftime('%Y-%m-%d %H:%M'))))

    _id = '%s_%s' % (field._tablename, field.name)
    _name = field.name

    if value_missing and 'autodetect' in attributes and attributes.pop(
            'autodetect') is True:
        current.response.files.append(
            URL('static', 'plugin_timezone/jstz.min.js'))
        script = """
jQuery(document).ready(function () {
  var tz = jstz.determine();
  var nice_tz_select = jQuery('#%(_id)s');
  nice_tz_select.on('change.plugin_timezone', function(e, data) {
      var localized = jQuery('#%(_id)s option:selected').data('localized');
      var placeholder = '#plugin_timezone_localized';
      if (!jQuery(placeholder).length) nice_tz_select.after('<span id="plugin_timezone_localized" style="display: block" />');
      if (typeof (data) !== 'undefined') {
        localized = 'auto: ' + localized;
      }
      else {
        manual = 'auto: ' + localized;
      }
      // jQuery(placeholder).html(localized);
  });
  if (typeof (tz) !== 'undefined') {
      var name = tz.name();
      nice_tz_select.val(name).trigger('change.plugin_timezone', [name]);
  }
});
    """ % dict(_id=_id)
        return CAT(SELECT(*options, _id=_id, _name=_name, **attributes),
                   SCRIPT(script))
    return SELECT(*options, _id=_id, _name=_name, **attributes)
Ejemplo n.º 3
0
 def test_SELECT(self):
     self.assertEqual(
         SELECT('<>', _a='1', _b='2').xml(), b'<select a="1" b="2">' +
         b'<option value="&lt;&gt;">&lt;&gt;</option></select>')
     self.assertEqual(
         SELECT(OPTION('option 1', _value='1'),
                OPTION('option 2', _value='2')).xml(),
         b'<select><option value="1">option 1</option><option value="2">option 2</option></select>'
     )
     self.assertEqual(
         SELECT(OPTION('option 1', _value='1', _selected='selected'),
                OPTION('option 2', _value='2'),
                _multiple='multiple').xml(),
         b'<select multiple="multiple"><option selected="selected" value="1">option 1</option><option value="2">option 2</option></select>'
     )
     # More then one select with mutilple
     self.assertEqual(
         SELECT(OPTION('option 1', _value='1', _selected='selected'),
                OPTION('option 2', _value='2', _selected='selected'),
                _multiple='multiple').xml(),
         b'<select multiple="multiple"><option selected="selected" value="1">option 1</option><option selected="selected" value="2">option 2</option></select>'
     )
     # OPTGROUP
     self.assertEqual(
         SELECT(
             OPTGROUP(
                 OPTION('option 1', _value='1'),
                 OPTION('option 2', _value='2'),
                 _label='Group 1',
             )).xml(),
         b'<select><optgroup label="Group 1"><option value="1">option 1</option><option value="2">option 2</option></optgroup></select>'
     )
     # List
     self.assertEqual(
         SELECT([1, 2, 3, 4, 5]).xml(),
         b'<select><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>'
     )
     # Tuple
     self.assertEqual(
         SELECT((1, 2, 3, 4, 5)).xml(),
         b'<select><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>'
     )
     # String value
     self.assertEqual(
         SELECT('Option 1', 'Option 2').xml(),
         b'<select><option value="Option 1">Option 1</option><option value="Option 2">Option 2</option></select>'
     )
     # list as a value
     self.assertEqual(
         SELECT(OPTION('option 1', _value=[1, 2, 3]),
                OPTION('option 2', _value=[4, 5, 6], _selected='selected'),
                _multiple='multiple').xml(),
         b'<select multiple="multiple"><option value="[1, 2, 3]">option 1</option><option selected="selected" value="[4, 5, 6]">option 2</option></select>'
     )
Ejemplo n.º 4
0
def create_db():
    response.subtitle = T("Database Creation")
    response.view = 'nas/index.html'
    alias = db(
        (db.databases.deleted == False)).select(db.databases.id,
                                                db.databases.alias,
                                                orderby=db.databases.alias)
    cmb_alias = SELECT(
        *[OPTION(field["alias"], _value=field["alias"]) for field in alias],
        _id="cmb_alias",
        _style="margin-top: 0px;")
    if len(cmb_alias) == 0:
        cmb_alias.insert(0, OPTION("", _value=""))
    gform = DIV(
        HR(),
        P(SPAN(T('1. Create a new database alias. See ')),
          A("Customer Databases",
            _href=URL("databases"),
            _style="color:#0069D6;font-style: italic;"),
          BR(),
          SPAN(
              T('2. The sqlite and Google SQL databases are created automatically.'
                )),
          BR(),
          SPAN(
              T('3. Other types of databases must be created manually before.')
          ),
          BR(),
          SPAN(T('4. Please select an alias, and start the creation:')),
          _style="font-style: italic;"),
        DIV(
            SPAN(T('Database alias:'),
                 _style="padding-right: 15px;padding-left: 15px;"), cmb_alias,
            P(SPAN(T('Starting the process?'),
                   _id="msg_result",
                   _style="font-style: italic;"),
              ui.control.get_mobil_button(label=T("Start"),
                                          href="#",
                                          onclick="createDatabase();",
                                          cformat=None,
                                          icon="check",
                                          theme="b",
                                          style="width: 100px;"),
              _style="padding-top: 0px;")),
        HR(),
        _style="font-weight: bold;",
        _align="left")
    return dict(form=gform)
Ejemplo n.º 5
0
def translate():
    return FORM(SELECT(
      _id="translate",
      _onchange="document.location='%s?_language='+jQuery(this).val()" \
          % URL(r=request,args=request.args),
      value=session._language,
      *[OPTION(k,_value=v) for v,k in languages]))
Ejemplo n.º 6
0
    def widget(self, f, v):
        """El widget
        """
        import uuid
        uid = str(uuid.uuid4())[:8]
        d_id = "cascade-" + uid
        wrapper = TABLE(_id=d_id, _class='cascade-widget')
        parent = None
        parent_format = None
        fn = ''
        vr = 'var dd%s = [];var oi%s = [];\n' % (uid, uid)
        prompt = [self.prompt(table) for table in self.tables]
        vr += 'var pr%s = ["' % uid + '","'.join([str(p)
                                                  for p in prompt]) + '"];\n'
        f_inp = SQLFORM.widgets.string.widget(f, v)
        f_id = f_inp['_id']
        f_inp['_type'] = "hidden"
        for tc, table in enumerate(self.tables):
            db = table._db
            format = table._format
            options = db(table['id'] > 0).select()
            id = str(table) + '_' + format[2:-2]
            opts = [OPTION(format % opt,_value=opt.id,
                                 _parent=opt[str(parent)] if parent else '0') \
                                  for opt in options]
            opts.insert(0, OPTION(prompt[tc], _value=0))
            inp = SELECT(opts ,_parent=str(parent) + \
                                  "_" + str(parent_format),
                                  _id=id,_name=id,
                                  _disabled="disabled" if parent else None)
            wrapper.append(TR(inp))
            next = str(tc + 1)
            vr += 'var p%s = jQuery("#%s #%s"); dd%s.push(p%s);\n' % (
                tc, d_id, id, uid, tc)
            vr += 'var i%s = jQuery("option",p%s).clone(); oi%s.push(i%s);\n' % (
                tc, tc, uid, tc)
            fn_in = 'for (i=%s;i<%s;i+=1){dd%s[i].find("option").remove();'\
                    'dd%s[i].append(\'<option value="0">\' + pr%s[i] + \'</option>\');'\
                    'dd%s[i].attr("disabled","disabled");}\n' % \
                           (next,len(self.tables),uid,uid,uid,uid)
            fn_in +='oi%s[%s].each(function(i){'\
                    'if (jQuery(this).attr("parent") == dd%s[%s].val()){'\
                    'dd%s[%s].append(this);}});' % (uid,next,uid,tc,uid,next)
            fn_in += 'dd%s[%s].removeAttr("disabled");\n' % (uid, next)
            fn_in += 'jQuery("#%s").val("");' % f_id
            if (tc < len(self.tables) - 1):
                fn += 'dd%s[%s].change(function(){%s});\n' % (uid, tc, fn_in)
            else:
                fn_in = 'jQuery("#%s").val(jQuery(this).val());' % f_id
                fn += 'dd%s[%s].change(function(){%s});\n' % (uid, tc, fn_in)
                if v:
                    fn += 'dd%s[%s].val(%s);' % (uid, tc, v)
            parent = table
            parent_format = format[2:-2]

        wrapper.append(f_inp)
        wrapper.append(SCRIPT(vr, fn))
        return wrapper
Ejemplo n.º 7
0
def get_view_lst(table):
  rtable = TABLE(_style="width: 100%;")
  if table in("address","contact"):
    nervatype_lst=['', 'customer', 'employee', 'event', 'place', 'product', 'project', 'tool', 'trans']
    rtable.append(TR(TD(DIV("nervatype",_class="div_label"),_class="td_label",_style="width: 90px;"),
         TD(SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="address_nervatype", _name="nervatype"),
            _class="td_input", _style="width: 175px;"),
         TD()
         ))
  elif table=="event":
    nervatype_lst=['', 'customer', 'employee', 'place', 'product', 'project', 'tool', 'trans']
    rtable.append(TR(TD(DIV("nervatype",_class="div_label"),_class="td_label",_style="width: 90px;"),
         TD(SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="event_nervatype", _name="nervatype"),
            _class="td_input", _style="width: 175px;"),
         TD()
         ))
  elif table=="fieldvalue":
    nervatype_lst=['', 'address', 'barcode', 'contact', 'currency', 'customer', 'employee', 'event', 'item', 'link', 
                   'log', 'movement', 'payment', 'price', 'place', 'product', 'project', 'rate', 'tax',
                   'tool', 'trans', 'setting']
    rtable.append(TR(TD(DIV("nervatype",_class="div_label"),_class="td_label",_style="width: 90px;"),
         TD(SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="fieldvalue_nervatype", _name="nervatype"),
            _class="td_input", _style="width: 175px;"),
         TD()
         ))
  elif table=="link":
    nervatype_lst=['', 'address', 'barcode', 'contact', 'currency', 'customer', 'employee', 'event', 'groups', 'item', 
                   'movement', 'payment', 'price', 'place', 'product', 'project', 'rate', 'tax',
                   'tool', 'trans']
    rtable.append(TR(TD(DIV("nervatype1",_class="div_label"),_class="td_label",_style="width: 90px;"),
         TD(SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="link_nervatype1", _name="nervatype1"),
            _class="td_input", _style="width: 175px;"),
         TD(DIV("nervatype2",_class="div_label"),_class="td_label",_style="width: 90px;"),
         TD(SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="link_nervatype2", _name="nervatype2"),
            _class="td_input", _style="width: 175px;"),
         TD()
         ))
#   elif table=="log":
#     nervatype_lst=['notype','customer', 'employee', 'event', 'groups', 'place', 'product', 'project', 'tool', 'trans']
#     rtable.append(TR(TD(DIV("nervatype",_class="div_label"),_class="td_label",_style="width: 90px;"),
#          TD(SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="log_nervatype", _name="nervatype"),
#             _class="td_input", _style="width: 175px;"),
#          TD()
#          ))
  return rtable
Ejemplo n.º 8
0
def index():
  response.title=T('NDI Wizard')
  response.subtitle=T('Data Interface Wizard')
  lst_nom = ["address","barcode","contact","currency","customer","deffield","employee","event","fieldvalue","groups","item","link",
         "log","movement","numberdef","pattern","payment","place","price","product","project","rate","tax","tool","trans","sql"]
  response.lst_nom = SELECT(*[OPTION(str(nom).upper(), _value=nom) for nom in lst_nom], _id="lst_nom", 
                            _size=len(lst_nom),_style="width: 100%;font-weight: bold;", 
                            _onchange="changeItem();setLabels(this.value.toUpperCase()+'"
                            +T(" fieldname and type values")+"','"+URL('ndr','getResource')+"?file_name=docs/ndi/ndi&content=view&lang=auto#'+this.value+'_fields');")
  return dict()
Ejemplo n.º 9
0
def create_backup():
  response.subtitle = T("Create a Backup")
  response.view='nas/index.html'
  alias = db((db.databases.deleted==False)).select(db.databases.id,db.databases.alias,orderby=db.databases.alias)
  cmb_alias = SELECT(*[OPTION(field["alias"],_value=field["alias"]) for field in alias], _id="cmb_alias")
  if len(cmb_alias)==0:
    cmb_alias.insert(0, OPTION("", _value=""))
  cmb_format = SELECT([OPTION(T("backup"), _value="backup"),OPTION(T("XML"), _value="xml")], _id="cmb_format")
  if len(cmb_format)==0:
    cmb_format.insert(0, OPTION("", _value=""))
  cmb_filename = SELECT([OPTION(T("Alias"), _value=""),OPTION(T("Download"), _value="download"),
                         OPTION(T("Custom"), _value="custom")], _id="cmb_filename")
  if request.env.web2py_runtime_gae:
    cmb_filename = SELECT([OPTION(T("Download"), _value="download")], _id="cmb_filename")
    cust_filename = ""
  else:
    cust_filename = INPUT(_type="text",_value="",_id="cust_filename")
  gform = DIV(
             HR(),
             P(SPAN(T('Nervatura backup: '), _style="color:brown;"),BR(),
               SPAN(T('NOM objects: '), _style="color:green;"),SPAN("address, barcode, contact, currency, customer, deffield, employee, event, fieldvalue, groups, item, link, \
               log, movement, numberdef, pattern, payment, place, price, product, project, rate, tax, tool, trans"),BR(),
              SPAN(T('Settings objects: '), _style="color:green;"),SPAN("ui_audit, ui_language, \
                ui_menu, ui_menufields, ui_message, ui_report, ui_reportfields, \
                ui_reportsources, ui_userconfig"),BR(),
              SPAN(T('Not included: '), _style="color:red;"),SPAN("ui_printqueue"),BR(),BR(),
              SPAN(T("Independent from the database type and version of the NAS server."),_style="font-style: italic;")),
             DIV(
               DIV(SPAN(T('Database alias:'),_style="padding-right: 15px;padding-left: 15px;"),cmb_alias),
               DIV(SPAN(T('Filename:') ,_style="padding-right: 15px;padding-left: 15px;"),cmb_filename, SPAN(" "),
               cust_filename, _style="padding-top: 10px;"), 
               DIV(SPAN(T('Backup format:'),_style="padding-right: 15px;padding-left: 15px;"),cmb_format, _style="padding-top: 10px;"),
             P(
                SPAN(T('Starting the process?'), _id="msg_result",_style="font-style: italic;"),
                ui.control.get_mobil_button(label=T("Start"), href="#", onclick="createDataBackup();", 
                  cformat=None, icon="check", theme="b", style="width: 100px;",
                  title=ns.T('Start customer backup creation')),
               _style="padding-top: 5px;")),
             HR()
             ,_style="font-weight: bold;", _align="left")
  return dict(form=gform)
Ejemplo n.º 10
0
def restore_backup():
  response.subtitle = T("Restore the Customer Data")
  response.view='nas/index.html'
  
  msg_result = T('Starting the process?')
  if request.post_vars:
    if request.post_vars.alias==None or request.post_vars.alias=="":
      msg_result = T("Error: Missing alias parameter!")
    if request.post_vars.has_key("frm_file"):
      if request.post_vars.bfile=="":
        msg_result = T("Error: Missing upload file!")
      else:
        msg_result = dbtool.loadBackupData(alias=request.vars.alias, bfile=request.post_vars.bfile)
    else:
      if request.post_vars.filename=="":
        msg_result = T("Error: Missing upload filename!")
      else:
        msg_result = dbtool.loadBackupData(alias=request.vars.alias, filename=request.post_vars.filename)
    request.post_vars = None
  
  alias = db((db.databases.deleted==False)).select(db.databases.id,db.databases.alias,orderby=db.databases.alias)
  cmb_alias = SELECT(*[OPTION(field["alias"],_value=field["alias"]) for field in alias], _name="alias", _id="cmb_alias")
  if len(cmb_alias)==0:
    cmb_alias.insert(0, OPTION("", _value=""))
  dfiles = os.listdir(os.path.join(ns.request.folder, 'static/backup'))
  files = []
  for dfile in dfiles:
    if str(dfile).endswith(".backup") or str(dfile).endswith(".xml"):
      files.append(dfile)
  files.sort()
  cmb_files = SELECT(*files, _id="cmb_files", _name="filename")
  if len(cmb_files)==0:
    cmb_files.insert(0, OPTION("", _value=""))
  cmd_filename=INPUT(_type="submit",_name="frm_filename", _title= ns.T('Start restore from local backup file'),
                             _value=T("Start restore"),_onclick="msg_result.innerHTML='"+T("Process started. Waiting for the server to respond ...")+"';")
  cmd_filename["_data-theme"] = "b"
  cmd_filename["_data-icon"] = "check"
  cmd_file=INPUT(_type="submit",_name="frm_file", _title= ns.T('Upload file and Start restore'),
    _value=T("Upload and Start restore"),
    _onclick="msg_result.innerHTML='"+T("Process started. Waiting for the server to respond ...")+"';")
  cmd_file["_data-theme"] = "b"
  cmd_file["_data-icon"] = "check"
  cmd_file["_data-ajax"] = "false"
  if request.env.web2py_runtime_gae:
    gform = DIV(
              HR(),
              P(SPAN(T('The sqlite and Google SQL databases are created automatically. Other types of databases must be created manually before.'))),
              FORM(
                   DIV(SPAN(T('Database alias:'),_style="padding-right: 15px;padding-left: 15px;"),cmb_alias),
                   DIV(SPAN(T('File:') ,_style="padding-right: 15px;padding-left: 15px;"),
                       INPUT(_type='file', _name='bfile', _id='bfile', _requires=IS_NOT_EMPTY()), SPAN("",_style="padding-left: 15px;"),
                       cmd_file,
                       _style="padding-top: 8px;"), 
                   _id="frm_upload_files",_name="frm_upload", **{"_data-ajax":"false"}),
              P(SPAN(msg_result, _id="msg_result",_style="padding-left: 15px;font-style: italic;padding-top: 5px;")),
              HR()
              ,_style="font-weight: bold;", _align="left")
  else:
    gform = DIV(
              HR(),
              P(SPAN(T('The sqlite and Google SQL databases are created automatically. Other types of databases must be created manually before.'))),
              FORM(
                   DIV(SPAN(T('Database alias:'),_style="padding-right: 15px;padding-left: 15px;"),cmb_alias),
                   DIV(SPAN(T('Filename:') ,_style="padding-right: 15px;padding-left: 15px;"),cmb_files,
                       SPAN("",_style="padding-left: 15px;"), 
                       cmd_filename,
                       _style="padding-top: 8px;"),
                   DIV(SPAN(T('File:') ,_style="padding-right: 15px;padding-left: 15px;"),
                       INPUT(_type='file', _name='bfile', _id='bfile', _requires=IS_NOT_EMPTY()), SPAN("",_style="padding-left: 15px;"),
                       cmd_file,
                       _style="padding-top: 8px;"), 
                   _id="frm_upload_files",_name="frm_upload", **{"_data-ajax":"false"}),
              P(SPAN(msg_result, _id="msg_result",_style="padding-left: 15px;font-style: italic;padding-top: 5px;")),
              HR()
              ,_style="font-weight: bold;", _align="left")
  return dict(form=gform)
Ejemplo n.º 11
0
 "hola2!",
 BR(),
 LABEL("hola1", _width="25%"),
 INPUT(_type='text',
       _name='myvar',
       requires=IS_NOT_EMPTY(),
       _width="75%"),
 LABEL("hola2", _width="25%"),
 INPUT(_type='text',
       _name='myvar',
       requires=IS_NOT_EMPTY(),
       _width="25%"),
 LABEL("hola2", _width="25%"),
 SELECT(OPTION("1", _value="uno"),
        OPTION("2", _value="dos"),
        OPTION("3", _value="tres"),
        _name='mysel',
        _width="25%"),
 LABEL("hola3", _width="25%"),
 INPUT(_type='text',
       _name='myvar',
       requires=IS_NOT_EMPTY(),
       _width="75%"),
 LABEL("Options:", _width="25%"),
 INPUT(_type='checkbox', _name='myvar', _width="10%"),
 LABEL("check1", _width="65%"),
 LABEL("", _width="25%"),
 INPUT(_type='checkbox', _name='myvar', _width="10%"),
 LABEL("check1", _width="65%"),
 LABEL("", _width="25%"),
 INPUT(_type='checkbox', _name='myvar', _width="10%"),
Ejemplo n.º 12
0
def restore_backup():
    response.subtitle = T("Restore the Customer Data")
    response.view = 'nas/index.html'

    msg_result = T('Starting the process?')
    if request.post_vars:
        if request.post_vars.alias == None or request.post_vars.alias == "":
            msg_result = T("Error: Missing alias parameter!")
        if request.post_vars.has_key("frm_file"):
            if request.post_vars.bfile == "":
                msg_result = T("Error: Missing upload file!")
            else:
                msg_result = dbtool.loadBackupData(
                    alias=request.vars.alias, bfile=request.post_vars.bfile)
        else:
            if request.post_vars.filename == "":
                msg_result = T("Error: Missing upload filename!")
            else:
                msg_result = dbtool.loadBackupData(
                    alias=request.vars.alias,
                    filename=request.post_vars.filename)
        request.post_vars = None

    alias = db(
        (db.databases.deleted == False)).select(db.databases.id,
                                                db.databases.alias,
                                                orderby=db.databases.alias)
    cmb_alias = SELECT(
        *[OPTION(field["alias"], _value=field["alias"]) for field in alias],
        _name="alias",
        _id="cmb_alias")
    if len(cmb_alias) == 0:
        cmb_alias.insert(0, OPTION("", _value=""))
    dfiles = os.listdir(os.path.join(ns.request.folder, 'static/backup'))
    files = []
    for dfile in dfiles:
        if str(dfile).endswith(".backup") or str(dfile).endswith(".xml"):
            files.append(dfile)
    files.sort()
    cmb_files = SELECT(*files, _id="cmb_files", _name="filename")
    if len(cmb_files) == 0:
        cmb_files.insert(0, OPTION("", _value=""))
    cmd_filename = INPUT(
        _type="submit",
        _name="frm_filename",
        _title=ns.T('Start restore from local backup file'),
        _value=T("Start restore"),
        _onclick="msg_result.innerHTML='" +
        T("Process started. Waiting for the server to respond ...") + "';")
    cmd_filename["_data-theme"] = "b"
    cmd_filename["_data-icon"] = "check"
    cmd_file = INPUT(
        _type="submit",
        _name="frm_file",
        _title=ns.T('Upload file and Start restore'),
        _value=T("Upload and Start restore"),
        _onclick="msg_result.innerHTML='" +
        T("Process started. Waiting for the server to respond ...") + "';")
    cmd_file["_data-theme"] = "b"
    cmd_file["_data-icon"] = "check"
    cmd_file["_data-ajax"] = "false"
    if request.env.web2py_runtime_gae:
        gform = DIV(
            HR(),
            P(
                SPAN(
                    T('The sqlite and Google SQL databases are created automatically. Other types of databases must be created manually before.'
                      ))),
            FORM(DIV(
                SPAN(T('Database alias:'),
                     _style="padding-right: 15px;padding-left: 15px;"),
                cmb_alias),
                 DIV(SPAN(T('File:'),
                          _style="padding-right: 15px;padding-left: 15px;"),
                     INPUT(_type='file',
                           _name='bfile',
                           _id='bfile',
                           _requires=IS_NOT_EMPTY()),
                     SPAN("", _style="padding-left: 15px;"),
                     cmd_file,
                     _style="padding-top: 8px;"),
                 _id="frm_upload_files",
                 _name="frm_upload",
                 **{"_data-ajax": "false"}),
            P(
                SPAN(msg_result,
                     _id="msg_result",
                     _style=
                     "padding-left: 15px;font-style: italic;padding-top: 5px;")
            ),
            HR(),
            _style="font-weight: bold;",
            _align="left")
    else:
        gform = DIV(
            HR(),
            P(
                SPAN(
                    T('The sqlite and Google SQL databases are created automatically. Other types of databases must be created manually before.'
                      ))),
            FORM(DIV(
                SPAN(T('Database alias:'),
                     _style="padding-right: 15px;padding-left: 15px;"),
                cmb_alias),
                 DIV(SPAN(T('Filename:'),
                          _style="padding-right: 15px;padding-left: 15px;"),
                     cmb_files,
                     SPAN("", _style="padding-left: 15px;"),
                     cmd_filename,
                     _style="padding-top: 8px;"),
                 DIV(SPAN(T('File:'),
                          _style="padding-right: 15px;padding-left: 15px;"),
                     INPUT(_type='file',
                           _name='bfile',
                           _id='bfile',
                           _requires=IS_NOT_EMPTY()),
                     SPAN("", _style="padding-left: 15px;"),
                     cmd_file,
                     _style="padding-top: 8px;"),
                 _id="frm_upload_files",
                 _name="frm_upload",
                 **{"_data-ajax": "false"}),
            P(
                SPAN(msg_result,
                     _id="msg_result",
                     _style=
                     "padding-left: 15px;font-style: italic;padding-top: 5px;")
            ),
            HR(),
            _style="font-weight: bold;",
            _align="left")
    return dict(form=gform)
Ejemplo n.º 13
0
def pagination(request, curr_host):
    # Pagination! Send it the db, request and current host record, get back
    # a dictionary to put into the view.
    # TODO: Remove db, request and session for current.globalenv

    db = current.globalenv['db']
    cache = current.globalenv['cache']
    session = current.globalenv['session']

    from gluon.html import OPTION, SELECT, FORM, A, INPUT, SCRIPT

    hostlist = []
    hostprev = "#"
    hostnext = "#"
    hostselected = 0
    hostnextstyle = hostprevstyle = ""
    hostprevtitle = hostnexttitle = ""
    hostindex = 1
    # Create more filters here
    if request.vars.filterconfirmed is not None:
        session.hostfilterconfirmed = request.vars.filterconfirmed

    if session.hostfilterconfirmed == 'Unconfirmed [H]osts':
        query = (db.t_hosts)
    else:
        query = (db.t_hosts.f_confirmed == False)

    if session.hostfilter:
        hostfilter = session.hostfilter[0]
        if hostfilter is not None:
            if hostfilter[0] == "userid":
                query &= (db.t_hosts.f_engineer == hostfilter[1])
            elif hostfilter[0] == "assetgroup":
                query &= (db.t_hosts.f_asset_group.contains(hostfilter[1]))
            elif hostfilter[0] == "range":
                query &= (db.t_hosts.f_ipv4.contains(hostfilter[1]))

    for h_rec in db(query).select():
        hostlist.append(OPTION(host_title_maker(h_rec), _value=h_rec.id))
        if hostselected != 0 and hostnext == "#":
            hostnext = h_rec.id
            hostnexttitle = "Go to " + host_title_maker(h_rec)
        if h_rec.id == curr_host.id:
            hostselected = hostindex
        if hostselected == 0:
            hostprev = h_rec.id
            hostprevtitle = "Go to " + host_title_maker(h_rec)
        hostindex = hostindex + 1

    if hostprev == "#":
        hostprevstyle = "display:none"
    if hostnext == "#":
        hostnextstyle = "display:none"

    pagination = {}
    pagination['previous'] = A("(p)",
                               _id="prevhostlink",
                               _class="button",
                               _href=hostprev,
                               _style=hostprevstyle,
                               _title=hostprevtitle)
    pagination['next'] = A("(n)",
                           _id="nexthostlink",
                           _class="button",
                           _href=hostnext,
                           _style=hostnextstyle,
                           _title=hostnexttitle)
    pagination['form'] = FORM(
        SELECT(hostlist,
               value=request.args(0),
               _class="chosen-select",
               _id="host_select",
               _name="host_select",
               _onchange="window.location.href=$('#host_select').val()",
               **{'_data-placeholder': 'Choose a host'}),
        SCRIPT('$("#host_select").select2({width: "80%"});'),
    )
    pagination['host_number'] = "( %d/%d )" % (hostselected, len(hostlist))

    return pagination
Ejemplo n.º 14
0
def pagination_services(request, curr_service):
    # Pagination! Send it the db, request and current host record, get back
    # a dictionary to put into the view.

    db = current.globalenv['db']
    #cache = current.globalenv['cache']

    from gluon.html import OPTION, SELECT, FORM, A
    from skaldship.general import host_title_maker

    servicelist = []
    serviceprev = "#"
    servicenext = "#"
    serviceselected = 0
    servicenextstyle = serviceprevstyle = ""
    serviceprevtitle = servicenexttitle = ""
    serviceindex = 1
    servicecount = 0
    query = db.t_services.f_hosts_id == db.t_hosts.id
    """
    # Create more filters here
    if request.vars.filterconfirmed is not None:
        session.servicefilterconfirmed=request.vars.filterconfirmed

    if session.servicefilterconfirmed == 'Unconfirmed [H]osts':
        query=db.t_services
    else:
        query=db.t_services.f_confirmed==False

    """
    for h_rec in db(query).select(orderby=db.t_hosts.id):
        hostrecord = h_rec.t_hosts
        servicelist.append(
            OPTION(host_title_maker(hostrecord) + " - " +
                   service_title_maker(h_rec.t_services),
                   _value=h_rec.t_services.id))
        if serviceselected != 0 and servicenext == "#":
            servicenext = h_rec.t_services.id
            servicenexttitle = "Go to " + host_title_maker(
                hostrecord) + " - " + service_title_maker(h_rec.t_services)
        if h_rec.t_services.id == curr_service.id:
            serviceselected = serviceindex
        if serviceselected == 0:
            serviceprev = h_rec.t_services.id
            serviceprevtitle = "Go to " + host_title_maker(
                hostrecord) + " - " + service_title_maker(h_rec.t_services)
        if h_rec.t_services.f_hosts_id == curr_service.f_hosts_id:
            serviceindex += 1
            servicecount += 1

    if serviceprev == "#":
        serviceprevstyle = "display:none"
    if servicenext == "#":
        servicenextstyle = "display:none"

    pagination = {}
    pagination['form'] = FORM(
        A("<<(p)",
          _id="prevservicelink",
          _class="button",
          _href=serviceprev,
          _style=serviceprevstyle,
          _title=serviceprevtitle),
        "    ",
        SELECT(servicelist,
               value=request.args(0),
               _class="autowidth",
               _id="service_select",
               _name="service_select",
               _onchange="window.location.href=$('#service_select').val()"),
        "  ",
        A("(n)>>",
          _id="nextservicelink",
          _class="button",
          _href=servicenext,
          _style=servicenextstyle,
          _title=servicenexttitle),
        _method='get')

    pagination['service_number'] = "( %d/%d )" % (serviceselected,
                                                  servicecount)

    return pagination
Ejemplo n.º 15
0
    def apply_method(r, **attr):
        """
            Apply method.

            @param r: the S3Request
            @param attr: controller options for this request
        """

        if r.representation == "html":

            from gluon.dal import Field
            from gluon.html import FORM, INPUT, OPTION, SELECT
            from gluon.validators import IS_IN_SET, IS_EMPTY_OR
            from s3fields import s3_datetime
            from s3validators import IS_LOCATION_SELECTOR2
            from s3widgets import S3LocationSelectorWidget2

            T = current.T
            table = r.table
            response = current.response
            session = current.session
            formstyle = current.deployment_settings.get_ui_formstyle()
            tracker = S3Trackable(table, record_id=r.id)

            form = FORM()
            fappend = form.append
            comment = ""

            opts = {
                1: T("Check-In"),
                2: T("Check-Out"),
                3: T("Update Base Location"),
            }
            id = "action"
            label = T("Action")
            widget = SELECT(
                [OPTION(opts[opt], _value=opt) for opt in opts],
                _id=id,
                _name=id,
                _value=1,
                requries=IS_IN_SET(opts),
            )
            row = formstyle("%s__row" % id, label, widget, comment)
            fappend(row)

            field = s3_datetime()
            field.tablename = r.tablename
            id = "timestmp"
            label = T("Time")
            value = current.request.utcnow
            widget = field.widget(field, value)
            row = formstyle("%s__row" % id, label, widget, comment)
            fappend(row)

            field = table.location_id
            field.requires = IS_EMPTY_OR(IS_LOCATION_SELECTOR2())
            value = tracker.get_location(_fields=["id"],
                                         as_rows=True).first().id
            id = "location"
            label = ""  # Replaced by Widget
            widget = S3LocationSelectorWidget2()(field, value)
            row = formstyle("%s__row" % id, label, widget, comment)
            fappend(row)

            id = "submit"
            label = ""
            widget = INPUT(_type="submit", _value=T("Apply"))
            row = formstyle("%s__row" % id, label, widget, comment)
            fappend(row)

            response.view = "create.html"
            title = T("Update Location")
            output = dict(title=title, form=form)

            script = \
'''$("#action").change(function(){
var type=$("#action").val()
if(type==2){$('#location__row').hide()}else{$('#location__row').show()}})'''
            response.s3.jquery_ready.append(script)
            if form.accepts(current.request.vars, current.session):

                form_vars = form.vars
                action = form_vars.get("action", None)
                if action == "1":
                    # Check-In
                    location_id = form_vars.get("location_id", None)
                    if location_id:
                        # We're not Checking-in in S3Track terms (that's about interlocking with another object)
                        #tracker.check_in()
                        timestmp = form_vars.get("timestmp", None)
                        if timestmp:
                            # @ToDo: Convert from string
                            pass
                        tracker.set_location(location_id, timestmp=timestmp)
                        response.confirmation = T("Checked-In successfully!")

                elif action == "2":
                    # Check-Out
                    # We're not Checking-out in S3Track terms (that's about removing an interlock with another object)
                    #tracker.check_out()
                    timestmp = form_vars.get("timestmp", None)
                    if timestmp:
                        # @ToDo: Convert from string
                        pass
                    tracker.set_location(r.record.location_id,
                                         timestmp=timestmp)
                    response.confirmation = T("Checked-Out successfully!")

                elif action == "3":
                    # Update Base Location
                    location_id = form_vars.get("location_id", None)
                    if location_id:
                        tracker.set_base_location(location_id)
                        response.confirmation = T("Base Location Updated!")

            return output

        else:
            raise HTTP(501, current.ERROR.BAD_METHOD)
Ejemplo n.º 16
0
def create_fieldlist(table):
  fields_lst = []
#   if table=="setting":
#     table="fieldvalue"
  fields = ns.db[table].fields
  for fname in fields:
    fieldcat=1
    if fname in("id","deleted"):
      continue
    
    if ns.db[table][fname].type=="text":
      ns.db[table][fname].widget=lambda field,value: SQLFORM.widgets.string.widget(field,value)
    if type(ns.db[table][fname].requires).__name__=="check_boolean":
      fields_lst.append({"fieldname":fname,"label":ns.db[table][fname].label,
                       "widget":SELECT([OPTION("", _value=""),OPTION(T("YES"), _value="1"),OPTION(T("NO"), _value="0",)], _id=table+"_"+fname, _name=fname),
                       "fieldcat":1})
      continue
    
    if table in("address","contact"):
      if fname=="nervatype":
        ns.db[table].nervatype.requires = IS_IN_SET(('customer', 'employee', 'event', 'place', 'product', 'project', 'tool', 'trans'))
        fieldcat=0
      elif fname=="ref_id":
        fields_lst.append({"fieldname":"refnumber","label":T('Ref.No.'),
                       "widget":INPUT(_type="text",_value="",_name="refnumber",_id=table+"_refnumber",_class="string"),
                       "fieldcat":0})
        fields_lst.append({"fieldname":"rownumber","label":T('Row No.'),
                       "widget":INPUT(_type="text",_value="0",_name="rownumber",_id=table+"_rownumber",_class="integer"),
                       "fieldcat":0})
        continue
    elif table=="barcode":
      if fname=="code":
        fields_lst.append({"fieldname":"code","label":T('Barcode'),
                       "widget":INPUT(_type="text",_value="",_name="code",_id=table+"_code",_class="string"),
                       "fieldcat":0})
        continue
      elif fname=="product_id":
        fields_lst.append({"fieldname":"partnumber","label":T('Product No.'),
                       "widget":INPUT(_type="text",_value="",_name="partnumber",_id=table+"_partnumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="barcodetype":
        ns.db.barcode.barcodetype.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('barcodetype')), ns.db.groups.groupvalue, '%(groupvalue)s')
    elif table=="currency":
      if fname=="curr":
        fieldcat=0
    elif table=="customer":
      if fname=="custnumber":
        fieldcat=0
      elif fname=="custtype":
        ns.db.customer.custtype.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('custtype')&(ns.db.groups.groupvalue!="own")), ns.db.groups.groupvalue, '%(groupvalue)s')
    elif table=="deffield":
      if fname=="fieldname":
        fieldcat=0
      elif fname=="nervatype":
        ns.db[table].nervatype.requires = IS_IN_SET(('address', 'barcode', 'contact', 'currency', 'customer', 'employee', 'event', 'item', 'link', 
                                                     'log', 'movement', 'payment', 'price', 'place', 'product', 'project', 'rate', 'tax',
                                                     'tool', 'trans', 'setting'))
      elif fname=="subtype":
        ns.db[table][fname].widget=lambda field,value: SQLFORM.widgets.string.widget(field,value)
      elif fname=="fieldtype":
        ns.db.deffield.fieldtype.requires = IS_IN_DB(ns.db((ns.db.groups.groupname.like('fieldtype'))
          &(ns.db.groups.groupvalue!="checkbox")&(ns.db.groups.groupvalue!="trans")), ns.db.groups.groupvalue, '%(groupvalue)s')
    elif table=="employee":
      if fname=="empnumber":
        fieldcat=0
      elif fname=="usergroup":
        ns.db.employee.usergroup.requires = IS_IN_DB(ns.db((ns.db.groups.groupname.like('usergroup'))&(ns.db.groups.deleted==0)), 
                                                     ns.db.groups.groupvalue, '%(groupvalue)s')
      elif fname=="department":
        ns.db.employee.department.requires = IS_EMPTY_OR(IS_IN_DB(ns.db((ns.db.groups.groupname.like('department'))
          &(ns.db.groups.deleted==0)), ns.db.groups.groupvalue, '%(groupvalue)s'))
      elif fname in("password","registration_key","reset_password_key","registration_id"):
        continue
    elif table=="event":
      if fname=="calnumber":
        fieldcat=0
      elif fname=="ref_id":
        fields_lst.append({"fieldname":"refnumber","label":T('Ref. No.'),
                       "widget":INPUT(_type="text",_value="",_name="refnumber",_id=table+"_refnumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="nervatype":
        ns.db[table].nervatype.requires = IS_IN_SET(('customer', 'employee', 'place', 'product', 'project', 'tool', 'trans'))
      elif fname=="eventgroup":
        ns.db[table][fname].widget=lambda field,value: SQLFORM.widgets.string.widget(field,value)
    elif table=="groups":
      if fname in("groupname","groupvalue"):
        fieldcat=0
    elif table=="item":
      if fname=="trans_id":
        fields_lst.append({"fieldname":"transnumber","label":T('Doc.No.'),
                       "widget":INPUT(_type="text",_value="",_name="transnumber",_id=table+"_transnumber",_class="string"),
                       "fieldcat":0})
        fields_lst.append({"fieldname":"rownumber","label":T('Row No.'),
                       "widget":INPUT(_type="text",_value="0",_name="rownumber",_id=table+"_rownumber",_class="integer"),
                       "fieldcat":0})
        fields_lst.append({"fieldname":"inputmode","label":T('Input mode'),
                       "widget":SELECT([OPTION("", _value=""),OPTION(T("fxprice"), _value="fxprice"),
                                        OPTION(T("netamount"), _value="netamount"),OPTION(T("amount"), _value="amount")
                                        ], _id="item_inputmode", _name="inputmode"),
                       "fieldcat":1})
        fields_lst.append({"fieldname":"inputvalue","label":T('Input value'),
                       "widget":INPUT(_type="text",_value="0",_name="inputvalue",_id=table+"_inputvalue",_class="double"),
                       "fieldcat":1})
        continue
      elif fname=="product_id":
        fields_lst.append({"fieldname":"partnumber","label":T('Product No.'),
                       "widget":INPUT(_type="text",_value="",_name="partnumber",_id=table+"_partnumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="tax_id":
        taxcode = ns.db(ns.db.tax.inactive==0).select(ns.db.tax.taxcode)
        widget=SELECT(*[OPTION(field.taxcode) for field in taxcode], _id="item_taxcode", _name="taxcode")
        widget.insert(0, OPTION(""))
        fields_lst.append({"fieldname":"taxcode","label":T('Tax'), "widget":widget, "fieldcat":1})
        continue
      elif fname in("fxprice","netamount","vatamount","amount"):
        continue
    elif table=="link":
      nervatype_lst=['address', 'barcode', 'contact', 'currency', 'customer', 'employee', 'event', 'groups', 'item', 
                   'movement', 'payment', 'price', 'place', 'product', 'project', 'rate', 'tax',
                   'tool', 'trans']
      if fname == "nervatype_1":
        widget=SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="link_nervatype1", _name="nervatype1")
        widget.insert(0, OPTION(""))
        fields_lst.append({"fieldname":"nervatype1","label":T('Nervatype 1'), "widget":widget, "fieldcat":0})
        continue
      elif fname == "nervatype_2":
        widget=SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="link_nervatype2", _name="nervatype2")
        widget.insert(0, OPTION(""))
        fields_lst.append({"fieldname":"nervatype2","label":T('Nervatype 2'), "widget":widget, "fieldcat":0})
        continue
      elif fname=="ref_id_1":
        fields_lst.append({"fieldname":"refnumber1","label":T('Ref. No. 1'),
                       "widget":INPUT(_type="text",_value="",_name="refnumber1",_id=table+"_refnumber1",_class="string"),
                       "fieldcat":0})
        continue
      elif fname=="ref_id_2":
        fields_lst.append({"fieldname":"refnumber2","label":T('Ref. No. 2'),
                       "widget":INPUT(_type="text",_value="",_name="refnumber2",_id=table+"_refnumber2",_class="string"),
                       "fieldcat":0})
        continue
    elif table=="log":
      nervatype_lst=['address', 'barcode', 'contact', 'currency', 'customer', 'employee', 'deffield',
                     'event', 'groups', 'item', 'link', 'movement', 'payment', 'price', 'place', 'product', 'project', 
                     'rate', 'tax', 'tool', 'trans', 'setting']
      if fname=="employee_id":
        fields_lst.append({"fieldname":"empnumber","label":T('Employee No.'),
                       "widget":INPUT(_type="text",_value="",_name="empnumber",_id=table+"_empnumber",_class="string"),
                       "fieldcat":0})
        continue
      elif fname=="crdate":
        fieldcat=0
      elif fname == "nervatype":
        widget=SELECT(*[OPTION(nervatype) for nervatype in nervatype_lst], _id="log_nervatype", _name="nervatype")
        widget.insert(0, OPTION(""))
        fields_lst.append({"fieldname":"nervatype","label":T('Nervatype'), "widget":widget, "fieldcat":1})
        continue
      elif fname == "logstate":
        widget=SELECT(*[OPTION(logstate.groupvalue) for logstate in ns.db(ns.db.groups.groupname.like('logstate')).select(ns.db.groups.groupvalue)], _id="log_logstate", _name="logstate")
        widget.insert(0, OPTION(""))
        fields_lst.append({"fieldname":"logstate","label":T('State'), "widget":widget, "fieldcat":1})
        continue
      elif fname=="ref_id":
        fields_lst.append({"fieldname":"refnumber","label":T('Ref.No.'),
                       "widget":INPUT(_type="text",_value="",_name="refnumber",_id=table+"_refnumber",_class="string"),
                       "fieldcat":1})
        continue
    elif table=="movement":
      if fname=="trans_id":
        fields_lst.append({"fieldname":"transnumber","label":T('Doc.No.'),
                       "widget":INPUT(_type="text",_value="",_name="transnumber",_id=table+"_transnumber",_class="string"),
                       "fieldcat":0})
        fields_lst.append({"fieldname":"rownumber","label":T('Row No.'),
                       "widget":INPUT(_type="text",_value="0",_name="rownumber",_id=table+"_rownumber",_class="integer"),
                       "fieldcat":0})
        continue
      elif fname=="movetype":
        ns.db.movement.movetype.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('movetype')
                & ns.db.groups.groupvalue.belongs(('inventory', 'store', 'tool'))
                ), ns.db.groups.groupvalue, '%(groupvalue)s')
      elif fname=="product_id":
        fields_lst.append({"fieldname":"partnumber","label":T('Product No.'),
                       "widget":INPUT(_type="text",_value="",_name="partnumber",_id=table+"_partnumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="tool_id":
        fields_lst.append({"fieldname":"serial","label":T('Serial'),
                       "widget":INPUT(_type="text",_value="",_name="serial",_id=table+"_serial",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="place_id":
        fields_lst.append({"fieldname":"planumber","label":T('Place No.'),
                       "widget":INPUT(_type="text",_value="",_name="planumber",_id=table+"_planumber",_class="string"),
                       "fieldcat":1})
        continue
    elif table=="numberdef":
      if fname=="numberkey":
        fieldcat=0
    elif table=="pattern":
      if fname=="description":
        fieldcat=0
      elif fname=="transtype":  
        ns.db.pattern.transtype.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('transtype')), 
                                                    ns.db.groups.groupvalue, '%(groupvalue)s')
    elif table=="payment":
      if fname=="trans_id":
        fields_lst.append({"fieldname":"transnumber","label":T('Doc.No.'),
                       "widget":INPUT(_type="text",_value="",_name="transnumber",_id=table+"_transnumber",_class="string"),
                       "fieldcat":0})
        fields_lst.append({"fieldname":"rownumber","label":T('Row No.'),
                       "widget":INPUT(_type="text",_value="0",_name="rownumber",_id=table+"_rownumber",_class="integer"),
                       "fieldcat":0})
        continue
    elif table=="place":
      if fname=="planumber":
        fieldcat=0
      elif fname=="place_id":
        fields_lst.append({"fieldname":"ref_planumber","label":T('Ref. No.'),
                       "widget":INPUT(_type="text",_value="",_name="ref_planumber",_id=table+"_ref_planumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="placetype":  
        ns.db.place.placetype.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('placetype')), 
                                                    ns.db.groups.groupvalue, '%(groupvalue)s')
      elif fname=="storetype":
        continue
    elif table=="price":
      if fname=="product_id":
        fields_lst.append({"fieldname":"partnumber","label":T('Product No.'),
                       "widget":INPUT(_type="text",_value="",_name="partnumber",_id=table+"_partnumber",_class="string"),
                       "fieldcat":0})
        fields_lst.append({"fieldname":"pricetype","label":T('Type'),
                       "widget":SELECT([OPTION("", _value=""),OPTION(T("price"), _value="price"),
                                        OPTION(T("discount"), _value="discount")
                                        ], _id=table+"_pricetype", _name="pricetype"),
                       "fieldcat":0})
        continue
      elif fname=="validfrom":
        fieldcat=0
      elif fname=="curr":
        fieldcat=0
      elif fname=="qty":
        fieldcat=0
      elif fname=="pricevalue":
        ns.db.price.pricevalue.label = T("Value/limit")
      elif fname=="calcmode":  
        ns.db.price.calcmode.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('calcmode')), 
                                                    ns.db.groups.groupvalue, '%(description)s')
    elif table=="product":
      if fname=="partnumber":
        fieldcat=0
      elif fname=="protype":  
        ns.db.product.protype.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('protype')), 
                                                    ns.db.groups.groupvalue, '%(groupvalue)s')
      elif fname=="tax_id":
        taxcode = ns.db(ns.db.tax.inactive==0).select(ns.db.tax.taxcode)
        widget=SELECT(*[OPTION(field.taxcode) for field in taxcode], _id="product_taxcode", _name="taxcode")
        widget.insert(0, OPTION(""))
        fields_lst.append({"fieldname":"taxcode","label":T('Tax'), "widget":widget, "fieldcat":1})
        continue
    elif table=="project":
      if fname=="pronumber":
        fieldcat=0
      elif fname=="customer_id":
        fields_lst.append({"fieldname":"custnumber","label":T('Customer No.'),
                       "widget":INPUT(_type="text",_value="",_name="custnumber",_id=table+"_custnumber",_class="string"),
                       "fieldcat":1})
        continue
    elif table=="rate":
      if fname == "ratetype":
        fieldcat=0
        ns.db.rate.ratetype.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('ratetype')), 
                                                    ns.db.groups.groupvalue, '%(groupvalue)s')
      elif fname in("ratedate","curr"):
        fieldcat=0
      elif fname=="place_id":
        fields_lst.append({"fieldname":"planumber","label":T('Place No.'),
                       "widget":INPUT(_type="text",_value="",_name="planumber",_id=table+"_planumber",_class="string"),
                       "fieldcat":0})
        continue
      elif fname == "rategroup":
        ns.db.rate.rategroup.requires = IS_EMPTY_OR(IS_IN_DB(ns.db((ns.db.groups.deleted==0)
          &ns.db.groups.groupname.like('rategroup')), ns.db.groups.groupvalue, '%(groupvalue)s'))
    elif table=="tax":
      if fname=="taxcode":
        fieldcat=0
    elif table=="tool":
      if fname=="serial":
        fieldcat=0
      elif fname=="product_id":
        fields_lst.append({"fieldname":"partnumber","label":T('Product No.'),
                       "widget":INPUT(_type="text",_value="",_name="partnumber",_id=table+"_partnumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname == "toolgroup":
        ns.db.tool.toolgroup.requires = IS_EMPTY_OR(IS_IN_DB(ns.db((ns.db.groups.deleted==0)
          &ns.db.groups.groupname.like('toolgroup')), ns.db.groups.groupvalue, '%(groupvalue)s'))
    elif table=="trans":
      if fname=="transnumber":
        fieldcat=0
      elif fname == "transtype":
        ns.db.trans.transtype.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('transtype')), 
                                                    ns.db.groups.groupvalue, '%(groupvalue)s')
      elif fname == "direction":
        ns.db.trans.direction.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('direction')), 
                                                    ns.db.groups.groupvalue, '%(groupvalue)s')
      elif fname == "paidtype":
        ns.db.trans.paidtype.requires = IS_EMPTY_OR(IS_IN_DB(ns.db((ns.db.groups.deleted==0)
          &ns.db.groups.groupname.like('paidtype')), ns.db.groups.groupvalue, '%(groupvalue)s'))
      elif fname == "department":
        ns.db.trans.department.requires = IS_EMPTY_OR(IS_IN_DB(ns.db((ns.db.groups.deleted==0)
          &ns.db.groups.groupname.like('department')), ns.db.groups.groupvalue, '%(groupvalue)s'))
      elif fname == "transtate":
        ns.db.trans.transtate.requires = IS_IN_DB(ns.db(ns.db.groups.groupname.like('transtate')), 
                                                    ns.db.groups.groupvalue, '%(groupvalue)s')
      elif fname=="customer_id":
        fields_lst.append({"fieldname":"custnumber","label":T('Customer No.'),
                       "widget":INPUT(_type="text",_value="",_name="custnumber",_id=table+"_custnumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="employee_id":
        fields_lst.append({"fieldname":"empnumber","label":T('Employee No.'),
                       "widget":INPUT(_type="text",_value="",_name="empnumber",_id=table+"_empnumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="project_id":
        fields_lst.append({"fieldname":"pronumber","label":T('Project No.'),
                       "widget":INPUT(_type="text",_value="",_name="pronumber",_id=table+"_pronumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="place_id":
        fields_lst.append({"fieldname":"planumber","label":T('Place No.'),
                       "widget":INPUT(_type="text",_value="",_name="planumber",_id=table+"_planumber",_class="string"),
                       "fieldcat":1})
        continue
      elif fname=="cruser_id":
        continue
    elif table=="fieldvalue":
      if fname=="fieldname":
        fields_lst.append({"fieldname":"fieldname","label":T('Fieldname'),
                       "widget":INPUT(_type="text",_value="",_name="fieldname",_id=table+"_fieldname",_class="string"),
                       "fieldcat":0})
        continue
      elif fname=="ref_id":
        fields_lst.append({"fieldname":"refnumber","label":T('Ref.No.'),
                       "widget":INPUT(_type="text",_value="",_name="refnumber",_id=table+"_refnumber",_class="string"),
                       "fieldcat":0})
        fields_lst.append({"fieldname":"rownumber","label":T('Row No.'),
                       "widget":INPUT(_type="text",_value="1",_name="rownumber",_id=table+"_rownumber",_class="integer"),
                       "fieldcat":0})
        continue
      elif fname=="fieldtype":
        ns.db.fieldvalue.fieldtype.requires = IS_IN_DB(ns.db((ns.db.groups.groupname.like('fieldtype'))
          &(ns.db.groups.groupvalue!="checkbox")&(ns.db.groups.groupvalue!="trans")), ns.db.groups.id, '%(groupvalue)s')
                                                      
    form = SQLFORM(ns.db[table])
    fields_lst.append({"fieldname":fname,"label":form.custom.label[fname],
                       "widget":form.custom.widget[fname],"fieldcat":fieldcat})
  
  if table in("address", "barcode", "contact", "currency", "customer", "employee", "event", "groups", "item", "link", "log", 
              "movement", "price", "place", "product", "project", "rate", "tax", "tool", "trans"):
    nervatype = ns.db((ns.db.groups.groupname=="nervatype")&(ns.db.groups.groupvalue==table)).select().as_list()[0]["id"]
    deffields = ns.db((ns.db.deffield.deleted==0)&(ns.db.deffield.visible==1)&(ns.db.deffield.nervatype==nervatype)
                      &(ns.db.deffield.readonly==0)&(ns.db.deffield.fieldtype==ns.db.groups.id)).select(
                        ns.db.deffield.fieldname,ns.db.groups.groupvalue,ns.db.deffield.description,ns.db.deffield.valuelist)
    for deffield in deffields:
      if deffield.groups.groupvalue=="bool":
        fields_lst.append({"fieldname":deffield.deffield.fieldname,"label":deffield.deffield.description,
                       "widget":INPUT(_type="checkbox",_value="on",_name=deffield.deffield.fieldname,_id=table+"_"+deffield.deffield.fieldname,_class="boolean"),
                       "fieldcat":2})
      elif deffield.groups.groupvalue=="integer":
        fields_lst.append({"fieldname":deffield.deffield.fieldname,"label":deffield.deffield.description,
                       "widget":INPUT(_type="text",_value="0",_name=deffield.deffield.fieldname,_id=table+"_"+deffield.deffield.fieldname,_class="integer"),
                       "fieldcat":2})
      elif deffield.groups.groupvalue=="float":
        fields_lst.append({"fieldname":deffield.deffield.fieldname,"label":deffield.deffield.description,
                       "widget":INPUT(_type="text",_value="0",_name=deffield.deffield.fieldname,_id=table+"_"+deffield.deffield.fieldname,_class="double"),
                       "fieldcat":2})
      elif deffield.groups.groupvalue=="date":
        fields_lst.append({"fieldname":deffield.deffield.fieldname,"label":deffield.deffield.description,
                       "widget":INPUT(_type="text",_value="",_name=deffield.deffield.fieldname,_id=table+"_"+deffield.deffield.fieldname,_class="date"),
                       "fieldcat":2})
      elif deffield.groups.groupvalue=="valuelist":
        widget = SELECT(*[OPTION(field) for field in deffield.deffield.valuelist.split("|")], _name=deffield.deffield.fieldname,_id=table+"_"+deffield.deffield.fieldname)
        widget.insert(0, OPTION("", _value=""))
        fields_lst.append({"fieldname":deffield.deffield.fieldname,"label":deffield.deffield.description,"widget":widget,"fieldcat":2})
      else:
        fields_lst.append({"fieldname":deffield.deffield.fieldname,"label":deffield.deffield.description,
                       "widget":INPUT(_type="text",_value="",_name=deffield.deffield.fieldname,_id=table+"_"+deffield.deffield.fieldname,_class="string"),
                       "fieldcat":2})
  return fields_lst
Ejemplo n.º 17
0
def create_backup():
    response.subtitle = T("Create a Backup")
    response.view = 'nas/index.html'
    alias = db(
        (db.databases.deleted == False)).select(db.databases.id,
                                                db.databases.alias,
                                                orderby=db.databases.alias)
    cmb_alias = SELECT(
        *[OPTION(field["alias"], _value=field["alias"]) for field in alias],
        _id="cmb_alias")
    if len(cmb_alias) == 0:
        cmb_alias.insert(0, OPTION("", _value=""))
    cmb_format = SELECT(
        [OPTION(T("backup"), _value="backup"),
         OPTION(T("XML"), _value="xml")],
        _id="cmb_format")
    if len(cmb_format) == 0:
        cmb_format.insert(0, OPTION("", _value=""))
    cmb_filename = SELECT([
        OPTION(T("Alias"), _value=""),
        OPTION(T("Download"), _value="download"),
        OPTION(T("Custom"), _value="custom")
    ],
                          _id="cmb_filename")
    if request.env.web2py_runtime_gae:
        cmb_filename = SELECT([OPTION(T("Download"), _value="download")],
                              _id="cmb_filename")
        cust_filename = ""
    else:
        cust_filename = INPUT(_type="text", _value="", _id="cust_filename")
    gform = DIV(
        HR(),
        P(
            SPAN(T('Nervatura backup: '), _style="color:brown;"), BR(),
            SPAN(T('NOM objects: '), _style="color:green;"),
            SPAN(
                "address, barcode, contact, currency, customer, deffield, employee, event, fieldvalue, groups, item, link, \
               log, movement, numberdef, pattern, payment, place, price, product, project, rate, tax, tool, trans"
            ), BR(), SPAN(T('Settings objects: '), _style="color:green;"),
            SPAN("ui_audit, ui_language, \
                ui_menu, ui_menufields, ui_message, ui_report, ui_reportfields, \
                ui_reportsources, ui_userconfig"), BR(),
            SPAN(T('Not included: '), _style="color:red;"),
            SPAN("ui_printqueue"), BR(), BR(),
            SPAN(T(
                "Independent from the database type and version of the NAS server."
            ),
                 _style="font-style: italic;")),
        DIV(
            DIV(
                SPAN(T('Database alias:'),
                     _style="padding-right: 15px;padding-left: 15px;"),
                cmb_alias),
            DIV(SPAN(T('Filename:'),
                     _style="padding-right: 15px;padding-left: 15px;"),
                cmb_filename,
                SPAN(" "),
                cust_filename,
                _style="padding-top: 10px;"),
            DIV(SPAN(T('Backup format:'),
                     _style="padding-right: 15px;padding-left: 15px;"),
                cmb_format,
                _style="padding-top: 10px;"),
            P(SPAN(T('Starting the process?'),
                   _id="msg_result",
                   _style="font-style: italic;"),
              ui.control.get_mobil_button(
                  label=T("Start"),
                  href="#",
                  onclick="createDataBackup();",
                  cformat=None,
                  icon="check",
                  theme="b",
                  style="width: 100px;",
                  title=ns.T('Start customer backup creation')),
              _style="padding-top: 5px;")),
        HR(),
        _style="font-weight: bold;",
        _align="left")
    return dict(form=gform)