Newer
Older
Digital_Repository / Old / pysocks / the_form.py
nstanger on 12 Nov 2005 1 KB - Second attempt at importing!
  1. class The_Form:
  2. __attributes = {'username':None, 'passwd':None, 'function':'default',
  3. 'action':None, 'authors':None, 'pub_date':None,
  4. 'short_desc':None, 'long_desc':None, 'title':None, 'filename':None,
  5. 'filename_name':None}
  6. __keys = __attributes.keys()
  7. def __init__(self, vals=None, extra_attrs=None):
  8. '''\
  9. init object
  10. has two optional parameters both dictionaries
  11. vals is a set of vals to put into the object and
  12. extra_attrs is a list of attributes with defaults that can be
  13. added
  14. '''
  15. if extra_attrs:
  16. for i in extra_attrs.keys():
  17. self.__attributes[i] = extra_attrs[i]
  18. self.__keys = self.__attributes.keys()
  19. if vals:
  20. for i in vals.keys():
  21. if i in self.__keys:
  22. self.__attributes[i] = vals[i]
  23. else:
  24. self.__invalid_item = 1
  25.  
  26. def error(self):
  27. if self.__invalid_item:
  28. return 1
  29. else:
  30. return 0
  31.  
  32. def get_values_from_form(self, form):
  33. for i in self.__keys:
  34. if form.has_key(i):
  35. if i == 'filename':
  36. # print 'content-type: text/html'
  37. # print
  38. # print 'filename:', form[i].filename
  39. # print form[i]
  40. self.__attributes['filename_name'] = form[i].filename
  41.  
  42. self.__attributes[i] = form[i].value
  43.  
  44. def __setattr__(self, attr, val):
  45. if attr in self.__keys:
  46. self.__attributes[attr] = val
  47.  
  48. def __getattr__(self, attr):
  49. if attr in self.__keys:
  50. return self.__attributes[attr]