def get(self, login_user=None, template_values={}): contact_key = self.request.get("key", None) assert contact_key con = Contact.get(contact_key) # access rights check if not write_access(con,login_user): self.error(500) return contact = encode_contact(con, login_user, include_attic=True) # render edit page template_values['contact'] = contact path = os.path.join(os.path.dirname(__file__), 'take2edit.html') self.response.out.write(template.render(path, template_values))
def get(self, login_user=None, template_values={}): """Function is called to update a take2 object or a contact. The function prepares the data for the form. After the form is completed, a save function will store the new data.""" instance = self.request.get("instance", "") instance_list = instance.split(",") contact_ref = self.request.get("contact_ref", None) # contact_ref points to the person to which the take2 entries in this form # belong to. assert contact_ref, "No contact_ref / key received." contact = Contact.get(contact_ref) # access rights check if not write_access (contact, login_user): self.error(500) return template_values['titlestr'] = "Address book entry for %s %s" % (contact.name, contact.lastname) # # Use beans to prepare form data # for (bean_name,bean_class) in (('Person',PersonBean),('Email',EmailBean),('Mobile',MobileBean), ('Address',AddressBean),('Web',WebBean),('Other',OtherBean)): if bean_name in instance_list: key = self.request.get('%s_key' % bean_name, None) if not key and not bean_name == 'Person': # We simply treat this as a new object obj = bean_class.new(contact_ref) else: obj = bean_class.load(key) template_values.update(obj.get_template_values()) # instances as list and as concatenated string template_values['instance_list'] = instance_list template_values['instance'] = instance template_values['contact_ref'] = contact_ref template_values['action'] = 'edit' path = os.path.join(os.path.dirname(__file__), 'take2form.html') self.response.out.write(template.render(path, template_values))
def attic_contact(self, login_user=None, template_values={}): key = self.request.get("key", "") contact = Contact.get(key) assert contact, "Object key: %s is not a Contact" % key # access check if not write_access(contact, login_user): self.error(500) return logging.debug("ContactAttic: %s key: %s" % (contact.name,key)) contact.attic = True; contact.put(); update_index(contact) # if the contact had a backwards refrence, direkt to the middleman if contact.middleman_ref: key = str(contact.middleman_ref.key()) self.redirect('/editcontact?key=%s' % key)
def deattic_take2(self, login_user=None, template_values={}): instance = self.request.get("instance", "") key = self.request.get("key", "") t2 = Take2.get(key) # consistency checks assert t2.class_name() == instance.title(), "Edit class name %s does not fit with object %s" % (instance,key) contact = t2.contact_ref assert contact.class_name() in ['Person','Contact'], "Object %s key: %s is not a Contact" % (contact.class_name(),str(contact.key())) # access check if not write_access(contact, login_user): self.error(500) return logging.debug("De-attic: %s instance: %s key: %s" % (contact.name,instance,key)) t2.attic = False; t2.put(); if t2.class_name() == 'Address': update_index(t2) self.redirect('/editcontact?key=%s' % str(contact.key()))
def post(self, login_user=None, template_values={}): instance = self.request.get("instance", "") instance_list = instance.split(",") contact_ref = self.request.get("contact_ref", None) # contact_ref points to the person to which the take2 entries in this form # belong to. # The only case that it won't exist in the input form is if a new contact # (Person) is saved. contact = None if contact_ref: contact = Contact.get(contact_ref) # access rights check if not write_access (contact, login_user): self.error(500) return template_values['titlestr'] = "Address book entry for %s %s" % (contact.name, contact.lastname) else: # otherwise for the login_user template_values['titlestr'] = "New address book entry for %s %s" % (login_user.me.name, login_user.me.lastname) template_values['errors'] = [] if 'Person' in instance_list: person = PersonBean.edit(login_user,self.request) template_values.update(person.get_template_values()) err = person.validate() if not err: person.put() else: template_values['errors'].extend(err) # This is now the person to which the take2 data relates contact = person.get_entity() # go through all take2 types for (bean_name,bean_class) in (('Email',EmailBean),('Mobile',MobileBean),('Address',AddressBean), ('Web',WebBean),('Other',OtherBean)): if bean_name in instance_list: obj = bean_class.edit(contact, self.request) template_values.update(obj.get_template_values()) err = obj.validate() if not err: obj.put() else: # If the object is there in conjunction with the person that # means it's just not filled in. We save only the person, that's fine if 'Person' in instance_list: continue template_values['errors'].extend(err) # if errors happened, re-display the form if template_values['errors']: template_values['instance_list'] = instance_list template_values['instance'] = instance template_values['contact_ref'] = contact_ref path = os.path.join(os.path.dirname(__file__), 'take2form.html') self.response.out.write(template.render(path, template_values)) return self.redirect('/editcontact?key=%s' % str(contact.key()))