예제 #1
0
class WebBean(Take2Bean):
    @classmethod
    def new(cls,contact_ref):
        return WebBean(contact_ref)

    @classmethod
    def load(cls, key):
        entity = Web.get(key)
        web = WebBean(entity.contact_ref)
        web.entity = entity
        web.web = entity.web
        return web

    @classmethod
    def edit(cls,contact_ref,request):
        key = request.get('Web_key', None)
        if key:
            web = cls.load(key)
        else:
            web = WebBean(contact_ref)
        web.web = request.get('web')
        return web

    def __init__(self,contact_ref):
        super(WebBean,self).__init__(contact_ref)
        self.web = ""

    def validate(self):
      validate = URLValidator(verify_exists=True)
      try:
          validate(self.web)
      except ValidationError:
        return ['Invalid web address']

    def get_template_values(self):
        super(WebBean,self).get_template_values()
        self.template_values['web'] = self.web
        return self.template_values

    def put(self):
        try:
            self.entity.web = self.web
            self.entity.put()
        except AttributeError:
            # prepare database object for new person
            self.entity = Web(contact_ref=self.contact_ref, web=self.web)
            self.entity.put()
예제 #2
0
 def put(self):
     try:
         self.entity.web = self.web
         self.entity.put()
     except AttributeError:
         # prepare database object for new person
         self.entity = Web(contact_ref=self.contact_ref, web=self.web)
         self.entity.put()
예제 #3
0
 def load(cls, key):
     entity = Web.get(key)
     web = WebBean(entity.contact_ref)
     web.entity = entity
     web.web = entity.web
     return web