Beispiel #1
0
def convertRowListToHTMLConcursoObj(row):
  # the HTML nDoConc field must be an int number first of all, check this first
  try:
    value = row['nDoConc']
    try:
      value = int(value)
    except ValueError:
      return None
  except KeyError:
    return None
  concurso = ConcursoHTML()
  for fieldname in row.keys():
    value = row[fieldname]
    shouldBeType = fat.getFieldType(fieldname)
    if type(value) == shouldBeType:
      concurso[fieldname]=value
      continue
    # special case of 
    if fieldname == 'nDoConc':
      value = int(row[fieldname])
      concurso[fieldname]=value
      continue
    if fieldname.startswith('dezena'):
      value = int(row[fieldname])
      concurso[fieldname]=value
      continue
    if fieldname.startswith('ganhadoresDaQuadra'):
      value = int(row[fieldname])
      concurso[fieldname]=value
      continue
    if fieldname.startswith('ganhadoresDaQuina'):
      value = int(row[fieldname])
      concurso[fieldname]=value
      continue
    if fieldname.startswith('ganhadoresDaSena'):
      value = int(row[fieldname])
      concurso[fieldname]=value
      continue
    if fieldname == 'acumuladoSimNao':
      if value.lower().startswith('s'): # s = sim
        value = 1
      elif value.lower().startswith('n'): # n = não
        value = 0
      else:
        # dirty value
        raise ValueError, "dirty value in fieldname %s = %s" %(fieldname, str(value))
      concurso[fieldname]=value
      continue
    elif fieldname == 'dataDoSorteio':
      value = conv.convertToDatetimeDate(value)
      concurso[fieldname]=value
      continue
    elif shouldBeType == float:
      value = conv.convertToFloatAMoneyCurrencyNotInEnglishFormat(value)
      concurso[fieldname]=value
    else:
      # last try: see if it will enter as a string
      if type(value) == str:
        concurso[fieldname]=value
        continue
      raise ValueError, "could not enter value in a fieldname according the type rules :: value = %s type=%s" %(str(value), str(type(value)))
  return concurso
Beispiel #2
0
 def __setitem__(self, fieldname, value):
   shouldBeType = fat.getFieldType(fieldname)
   if type(value) != shouldBeType:
     raise TypeError, 'type error in __setitem__ attrName=%s and attrValue=%s type is %s, should be %s ' %(fieldname, str(value), str(type(value)), str(shouldBeType))
   self.concursoDict[fieldname] = value
   self.insertFieldnameInOrder(fieldname)