Ejemplo n.º 1
0
    def get(self, login_user=None, template_values={}):
        instance = self.request.get("instance", "")
        instance_list = instance.split(",")
        # key
        contact_ref = self.request.get("contact_ref", None)

        if 'Person' in instance_list:
            # the presence of the key indicates that the new person shall be
            # created with reference (middleman_ref) to key.
            if contact_ref:
                person = PersonBean.new_person_via_middleman(login_user,middleman_ref=contact_ref)
            else:
                person = PersonBean.new_person(login_user)
            template_values.update(person.get_template_values())
        # 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.new(contact_ref)
                template_values.update(obj.get_template_values())

        if contact_ref:
            # if contact is specified, the new entry is for this person
            contact = Person.get(contact_ref)
            template_values['titlestr'] = "New address book entry for %s %s" % (contact.name, contact.lastname)
            template_values['contact_ref'] = contact_ref
        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['contact_ref'] = str(login_user.me.key())

        # instances as list and as concatenated string
        template_values['instance_list'] = instance_list
        template_values['instance'] = instance

        path = os.path.join(os.path.dirname(__file__), 'take2form.html')
        self.response.out.write(template.render(path, template_values))
Ejemplo n.º 2
0
    def get(self):
        """processes the signup form"""
        authenticated_user = users.get_current_user()
        login_user = get_login_user()
        template_values = get_current_user_template_values(login_user,self.request.uri)

        # not logged in
        if not authenticated_user:
            self.redirect('/login')
            return

        # already connected
        if login_user and login_user.me:
            self.redirect('/')
            return

        template_values['errors'] = []

        person = PersonBean.edit(None,self.request)
        template_values.update(person.get_template_values())
        err = person.validate()
        terms=self.request.get("terms", None)
        if not terms:
            err.append("You must also acknowledge the terms and conditions.")

        if not err:
            try:
                db.run_in_transaction(initial_user_setup, authenticated_user, person)
            except:
                # an error occured in storing the data
                logging.exception('Transaction failed while storing LoginUser and Person')
                template_values['errors'].append('Database error. Sorry.')
        else:
            template_values['errors'].extend(err)

        if len(template_values['errors']):
            path = os.path.join(os.path.dirname(__file__), "take2welcome.html")
            self.response.out.write(template.render(path, template_values))
            return

        # create search index which is usually done by the PersonBean but not here
        # because the index table is not in the entity group
        update_index(person.entity)

        self.redirect('/')
Ejemplo n.º 3
0
    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()))