Esempio n. 1
0
def suggest():
  config = loadConfig()
  var = {}
  var['build'] = BUILD
  # check for input
#  query = cgi.FieldStorage()
  lang = request.values.get("lang","en")[:2]
  var['lang'] = lang
  code = request.values.get("scod",None)
  if code:
    var['scod'] = str(cleanCode(code)).lower()
  else:
    var['showerr'] = True
    var['showform'] = False
    var['scod'] = "----"
    var['error'] = "Please provide a code to make a suggestion."
  # check input validity
  desc = request.values.get("sdesc","[Suggestion]")
  var['sdesc'] = formClean(desc)
  rationale = request.values.get("srat","[Rationale]")
  var['srat'] = formClean(rationale)
  style = request.values.get("style",None)
  if style: var['style'] = style
  style = chooseStyle(style)
  if style: var['custom'] = url_for('static', filename=style + ".css")
  if "site" not in config:
    config['site'] = "Manatee"
  var['title'] = "Suggest a Category"
  # if no input, display form
  if desc[0] == '[': var['showform'] = True
  # ccode
  if var['scod'] == "xxxx" or str(var['scod']).find('y') != -1:
    var['showform'] = False
    var['showerr'] = True
    var['error'] = "You have entered an invalid CCOW code. You may not suggest new names for the top-level category or explanation categories. Please try again."
  # make a connection
  # category already assigned?
  # maybe a field for reasoning?
  # suggested category text
  # if it's all good, insert a row into the suggestions table
  # if bad input, display form
# """
  return render_template("suggest.jtl", config=config, var=var)
Esempio n. 2
0
def main():
  """Run if the program is called from the shell, of course."""
  print "Content-Type: text/html\n\n",
  config = loadConfig()
  var = {}

  here = os.path.dirname(os.path.abspath(__file__))
  env = Environment(loader=FileSystemLoader(here))
  template = env.get_template(os.path.join("templates",'ccowhelp.jtl'))

  # Create connection to SQL server (currently MySQL)
  engine = create_engine("%(host)s/%(base)s" % {'host':config["host"],'base':config["base"] } )
  sqlconn = engine.connect()
  # Grab GET data from URL
  query = cgi.FieldStorage()
  lang = query.getvalue("lang","en")[:2]
  var['lang'] = lang
  langarg = query.getvalue("lang",None) # needed for query present, language not
  code = query.getvalue("cowc","XXXX")
  code = str(cleanCode(code))
  style = query.getvalue("style",None)
  if style: var['style'] = "style=" + style
  style = chooseStyle(style)
  if style: var['custom'] = style
  if "site" not in config:
    config['site'] = "Manatee"
  # check for query string
  if len(query) == 0 or langarg == None:
    # if no query, offer lang selection
    var['title'] = "Select Language"
  else:
  # if query provided, show a page...
    var['code'] = code
    var['title'] = var['code']
    var['dosnip'] = True
    showsubs = False
    stage = getStage(var['code'])
    cat00 = str(code[:stage])
    if stage > 0:
      var['cattrim'] = cat00
    if stage < 4:
      showsubs = True
      for i in range(4 - stage): cat00 += '0'
      var['catmul'] = cat00
      var['muldesc'] = glot(cat00,sqlconn,lang,4) # the multiplicity topic desc will be stage 4.
    var['catname'] = glot(code,sqlconn,lang,stage)
    if code[0] == 'y': # Explanation key
      if code[3] == 'x': # explain subcats
        var['expl'] = True
        var['catname'] = glot("sxpl",sqlconn,lang)
        stage = 3 # the subcat explanations are stage 4, so we need to consider yxxx to be stage 3.
      else: # explain a single subcat type
        del var['catmul']
        var['cattrim'] = '*' + code[3]
        stage = 4 # make sure we don't show subcats
        del var['dosnip']
        showsubs = False
    var['stage'] = stage
    var['catinf'] = os.path.join("cats",lang,code)
    var['crumbs'] = glotCrumbs(sqlconn,code,stage,lang)
    if len(var['crumbs']) > 0 and code[0] != 'X' and code[0] != 'x': var['crumbdiv'] = True
    var['border'] = cat00[:3]
    if showsubs:
      var['subcats'] = glotSubs(sqlconn,code,stage,lang)
  var['progress'] = glot("spro",sqlconn,lang)
#  print "<!-- Code: " + var['code'] + " stage " + str(var['stage']) + " language: " + var['lang'] + " -->"

  print template.render({'config': config, 'var': var}).encode("utf-8")
  sqlconn.close()
  exit(0)