Ejemplo n.º 1
0
    def post(self):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url())

        system_name = self.request.get("name")
        system_description = self.request.get("description")
        system = System(id=system_name, description=system_description)
        key = system.put()

        # This is correct but is a hack, other solution is to use a sleep()
        must_stop = False
        systems = []

        while not must_stop:
            systems = System.query().fetch()
            for system in systems:
                if system.key.id() == system_name:
                    must_stop = True

        systems = System.query().fetch()
        template_values = {
            "systems": systems,
            "message": {
                "type": "success",
                "payload": "Created system #{0}".format(key.id())
            },
            "user": user,
            "users": users
        }
        template = JINJA_ENVIRONMENT.get_template("templates/list_system.html")
        self.response.write(template.render(template_values))
        return
Ejemplo n.º 2
0
    def post(self):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url())

        system_id = self.request.get("system")

        if not system_id:
            template = JINJA_ENVIRONMENT.get_template(
                "templates/not_found.html")
            template_values = {
                "user": user,
                "users": users,
                "not_found_msg": "Please select a system"
            }
            self.response.write(template.render(template_values))
            return

        sys = System.get_by_id(system_id)
        if sys is None:
            template = JINJA_ENVIRONMENT.get_template(
                "templates/not_found.html")
            template_values = {
                "user": user,
                "users": users,
                "not_found_msg": "The system #{0} not exists".format(system_id)
            }
            self.response.write(template.render(template_values))
            return

        sys.key.delete()

        # Hack to not use sleep solution
        found = True
        systems = []

        while found:
            found = False
            systems = System.query().fetch()
            print(systems)
            for system in systems:
                print(system.key.id(), sys.key.id())
                if system.key.id() == sys.key.id():
                    found = True
                    break

        systems = System.query().fetch()
        template_values = {
            "systems": systems,
            "message": {
                "type": "success",
                "payload": "Deleted system #{0}".format(system_id)
            },
            "user": user,
            "users": users
        }
        template = JINJA_ENVIRONMENT.get_template("templates/list_system.html")
        self.response.write(template.render(template_values))
        return
Ejemplo n.º 3
0
    def get(self):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url())

        systems = System.query().fetch()
        template_values = {
            "systems": systems,
            "message": {
                "type": "success",
                "payload": ""
            },
            "user": user,
            "users": users
        }
        template = JINJA_ENVIRONMENT.get_template("templates/list_system.html")
        self.response.write(template.render(template_values))
        return
Ejemplo n.º 4
0
 def get(self):
     user = users.get_current_user()
     systems = System.query().fetch()
     template_values = {"systems": systems, "user": user, "users": users}
     template = JINJA_ENVIRONMENT.get_template("templates/index.html")
     self.response.write(template.render(template_values))