Beispiel #1
0
class OtherBean(Take2Bean):
    @classmethod
    def new(cls,contact_ref):
        return OtherBean(contact_ref)

    @classmethod
    def load(cls, key):
        entity = Other.get(key)
        other = OtherBean(entity.contact_ref)
        other.entity = entity
        other.text = entity.text
        if entity.tag:
            other.tag = entity.tag.tag
        return other

    @classmethod
    def edit(cls,contact_ref,request):
        key = request.get('Other_key', None)
        if key:
            other = cls.load(key)
        else:
            other = OtherBean(contact_ref)
        other.text = request.get('text')
        other.tag = request.get('tag')
        return other

    def __init__(self,contact_ref):
        super(OtherBean,self).__init__(contact_ref)
        self.contact_ref = contact_ref
        self.text = ""
        self.tag = ""

    def validate(self):
        return []

    def get_template_values(self):
        super(OtherBean,self).get_template_values()
        self.template_values['text'] = self.text
        self.template_values['tag'] = self.tag
        self.template_values['taglist'] = prepare_list_of_other_tags()
        return self.template_values

    def put(self):
        if len(self.tag) > 0:
            tag = OtherTag.all().filter("tag =", self.tag).filter("owned_by =", self.contact_ref.owned_by).get()
            # If tag name is not in DB it is added
            if not tag:
                tag = OtherTag(tag=self.tag, owned_by=self.contact_ref.owned_by)
                tag.put()
        else:
            tag = None
        try:
            self.entity.tag = tag
            self.entity.text = self.text
            self.entity.put()
        except AttributeError:
            # prepare database object for new person
            self.entity = Other(contact_ref=self.contact_ref, text=self.text, tag=tag)
            self.entity.put()
Beispiel #2
0
 def load(cls, key):
     entity = Other.get(key)
     other = OtherBean(entity.contact_ref)
     other.entity = entity
     other.text = entity.text
     if entity.tag:
         other.tag = entity.tag.tag
     return other
Beispiel #3
0
 def put(self):
     if len(self.tag) > 0:
         tag = OtherTag.all().filter("tag =", self.tag).filter("owned_by =", self.contact_ref.owned_by).get()
         # If tag name is not in DB it is added
         if not tag:
             tag = OtherTag(tag=self.tag, owned_by=self.contact_ref.owned_by)
             tag.put()
     else:
         tag = None
     try:
         self.entity.tag = tag
         self.entity.text = self.text
         self.entity.put()
     except AttributeError:
         # prepare database object for new person
         self.entity = Other(contact_ref=self.contact_ref, text=self.text, tag=tag)
         self.entity.put()