Esempio n. 1
0
    def get(self, user):

        group_name = self.request.get("selected_group")

        group = Group.all().ancestor(ModelrParent.all().get())
        group = group.filter("name =", group_name).fetch(1)
        if (not group):
            self.redirect('/profile')
            return

        group = group[0]
        if group.admin != user.user_id:
            self.redirect('/profile')
            return

        users = []
        for user_id in group.allowed_users:
            u = User.all().ancestor(ModelrParent.all().get())\
                          .filter("user_id =", user_id)
            u = u.fetch(1)
            if u:
                users.append(u[0])

        params = self.get_base_params(user=user, users=users,
                                      group=group)
        template = env.get_template('manage_group.html')
        html = template.render(params)

        activity = "manage_group"
        ActivityLog(user_id=user.user_id,
                    activity=activity,
                    parent=ModelrParent.all().get()).put()
        self.response.out.write(html)
Esempio n. 2
0
    def post(self, user):

        # Output for successful post reception
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('All OK!!')

        name = self.request.get('name')
        group = self.request.get('group')
        logging.info(('name', name))
        data = self.request.get('json')

        logging.info(data)
        scenarios = Scenario.all()
        scenarios.ancestor(user)
        scenarios.filter("user ="******"name =", name)
        scenarios = scenarios.fetch(1)

        # Rewrite if the name exists, create new one if it doesn't
        if scenarios:
            scenario = scenarios[0]
        else:
            scenario = Scenario(parent=user)
            scenario.user = user.user_id
            scenario.name = name
            scenario.group = group

        # Save in Db
        scenario.data = data.encode()
        scenario.put()

        activity = "modified_scenario"
        ActivityLog(user_id=user.user_id,
                    activity=activity,
                    parent=ModelrParent.all().get()).put()
Esempio n. 3
0
    def delete(self, user):

        try:

            key = self.request.get('key')

            item = self.entity.get(key)

            if item.user != user.user_id:
                raise Exception

            # delete item and all its children
            deep_delete(item)

            activity = "removed_item"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()

            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('All OK!!')

        except Exception as e:
            print e
            self.error(502)
Esempio n. 4
0
    def get(self, user):

        activity = "signout"
        ActivityLog(user_id=user.user_id,
                    activity=activity,
                    parent=ModelrParent.all().get()).put()
        self.response.headers.add_header('Set-Cookie',
                                         'user=""; Path=/')
        self.redirect('/')
Esempio n. 5
0
    def post(self, user):
        group_name = self.request.get("group")
        group = Group.all().ancestor(ModelrParent.all().get())
        group = group.filter("name =", group_name).fetch(1)[0]

        # remove a user
        rm_user = self.request.get("user")

        if rm_user:
            u = User.all().ancestor(ModelrParent.all().get())
            u = u.filter("user_id =", int(rm_user)).fetch(1)

            if u and group_name in u[0].group:
                u[0].group.remove(group_name)
                u[0].put()
                group.allowed_users.remove(int(rm_user))
                group.put()
            self.redirect('/manage_group?selected_group=%s'
                          % group.name)

            activity = "removed_user"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()
            return

        # abolish a group
        if (self.request.get("abolish") == "abolish"):
            for uid in group.allowed_users:
                u = User.all().ancestor(ModelrParent.all().get())
                u = u.filter("user_id =", uid).fetch(1)
                if u and group.name in u[0].group:
                    u[0].group.remove(group.name)
                    u[0].put()
            group.delete()
            activity = "abolished_group"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()
            self.redirect('/profile')
            return
Esempio n. 6
0
    def get(self):

        user = self.verify()
        template_params = self.get_base_params(user=user)
        template = env.get_template('privacy.html')
        html = template.render(template_params)
        activity = "privacy"

        if user:
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()

        self.response.out.write(html)
Esempio n. 7
0
    def post(self, user):
        # Adds a rock to the database, will throw an error
        # if the rock name already exists
        try:
            name = self.request.get("name")
            rocks = get_items_by_name_and_user(self.entity, name, user)

            # Rewrite if the rock exists
            if rocks:
                # write out error message
                raise
            else:
                rock = Rock(parent=user)
                rock.user = user.user_id

            # Populate the object
            rock.vp = float(self.request.get('vp'))
            rock.vs = float(self.request.get('vs'))
            rock.rho = float(self.request.get('rho'))

            rock.vp_std = float(self.request.get('vp_std'))
            rock.vs_std = float(self.request.get('vs_std'))
            rock.rho_std = float(self.request.get('rho_std'))

            rock.porosity = float(self.request.get('porosity'))
            rock.vclay = float(self.request.get('vclay'))

            rock.description = self.request.get('description')
            rock.name = self.request.get('name')
            rock.group = self.request.get('group')

            fluid_key = self.request.get("rock-fluid")

            if fluid_key != "None":
                rock.fluid_key = Fluid.get(str(fluid_key)).key()

            # Save in the database
            rock.put()

            activity = "added_rock"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('All OK!!')

        except Exception as e:
            # send error
            print e
            self.error(502)
Esempio n. 8
0
    def get(self, user):

        groups = []
        for group in user.group:
            g = Group.all().ancestor(ModelrParent.all().get())\
                           .filter("name =", group)
            g = g.fetch(1)
            if g:
                groups.append(g[0])

        template_params = self.get_base_params(user=user, groups=groups,
                                               stripe_key=stripe_public_key)

        if self.request.get("createfailed"):
            create_error = "Group name exists"
            template_params.update(create_error=create_error)
        if self.request.get("joinfailed"):
            join_error = "Group does not exists"
            template_params.update(join_error=join_error)

        # Get the user permission requests
        req = GroupRequest.all().ancestor(ModelrParent.all().get())\
                                .filter("user ="******"admin =", user.user_id)
        admin_groups = admin_groups.fetch(100)
        req = []
        for group in admin_groups:
            # Check for a request
            g_req = GroupRequest.all().ancestor(ModelrParent.all().get())
            g_req = g_req.filter("group =", group.name).fetch(100)
            req = req + [{'group': group.name,
                          'user': User.all().filter("user_id =", i.user).get()}
                         for i in g_req]

        template_params.update(admin_req=req)
        template = env.get_template('profile.html')
        html = template.render(template_params)

        activity = "profile_view"
        ActivityLog(user_id=user.user_id,
                    activity=activity,
                    parent=ModelrParent.all().get()).put()
        self.response.out.write(html)
Esempio n. 9
0
    def get(self, subpage):

        if subpage:
            page = subpage
        else:
            page = 'help'
        page += '.html'

        user = self.verify()
        template_params = self.get_base_params(user=user)
        template = env.get_template(page)
        html = template.render(template_params)
        activity = "help"

        if user:
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()

        self.response.out.write(html)
Esempio n. 10
0
    def delete(self, user):

        name = self.request.get('name')
        scenarios = Scenario.all()
        scenarios.ancestor(user)
        scenarios.filter("user ="******"name =", name)
        scenarios = scenarios.fetch(100)

        for scenario in scenarios:
            scenario.delete()

        activity = "removed_scenario"
        ActivityLog(user_id=user.user_id,
                    activity=activity,
                    parent=ModelrParent.all().get()).put()

        # Output for successful post reception
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('All OK!!')
Esempio n. 11
0
    def post(self, user):

        try:
            name = self.request.get("name")

            fluids = get_items_by_name_and_user(self.entity, name, user)

            # Rewrite if the rock exists
            if fluids:
                raise Exception
            else:
                fluid = Fluid(parent=user)
                fluid.user = user.user_id

            fluid.rho_w = float(self.request.get('rho_w'))
            fluid.rho_hc = float(self.request.get('rho_hc'))

            fluid.kw = float(self.request.get('kw'))
            fluid.khc = float(self.request.get('khc'))

            fluid.sw = float(self.request.get('sw'))

            fluid.name = name
            fluid.description = self.request.get("description")
            fluid.group = self.request.get("group")
            fluid.put()

            activity = "added_fluid"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()

        except Exception as e:
            # Handle error
            print e
            self.error(502)

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('All OK!!')
Esempio n. 12
0
    def get(self):
        self.response.headers['Content-Type'] = 'application/json'

        # Get the user but don't redirect. Anyone can play with public
        # scenarios.
        user = self.verify()
        name = self.request.get('name')

        if user:
            scenarios = Scenario.all()
            scenarios.ancestor(user)
            scenarios.filter("user ="******"name =", name)
            scenarios = scenarios.fetch(1)
        else:
            scenarios = []

        # Get Evan's default scenarios (created with the admin)
        scen = Scenario.all()\
                       .ancestor(ModelrParent.all().get())\
                       .filter("user_id =", admin_id)
        scen = Scenario.all().filter("name =", name).fetch(100)
        if scen:
            scenarios += scen

        if scenarios:
            logging.info(scenarios[0])
            logging.info(scenarios[0].data)
            scenario = scenarios[0]
            self.response.out.write(scenario.data)
        else:
            self.response.out.write('null')

        activity = "fetched_scenario"
        if user:
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()
        return
Esempio n. 13
0
    def post(self, user):

        err_string = []
        # Join a group
        join_group = self.request.get("join_group")
        if join_group:
            activity = "joined_group"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()
            try:
                group = Group.all().ancestor(ModelrParent.all().get())
                group = group.filter("name =", join_group).fetch(1)[0]
                if user.user_id in group.allowed_users:
                    if group.name not in user.group:
                        user.group.append(group.name)
                        user.put()
                else:
                    GroupRequest(user=user.user_id,
                                 group=group.name,
                                 parent=ModelrParent.all().get()).put()

            except IndexError:
                err_string.append("joinfailed=1")

        # Leave a group
        group = self.request.get("selected_group")
        if group in user.group:
            activity = "left_group"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()
            user.group.remove(group)
            user.put()

        # Create a group
        group = self.request.get("create_group")

        if group:
            if not Group.all().ancestor(ModelrParent.all().get())\
                              .filter("name =", group).fetch(1):
                Group(name=group, admin=user.user_id,
                      allowed_users=[user.user_id],
                      parent=ModelrParent.all().get()).put()
                user.group.append(group)
                user.put()
                activity = "created_group"
                ActivityLog(user_id=user.user_id,
                            activity=activity,
                            parent=ModelrParent.all().get()).put()
            else:
                err_string.append("createfailed=1")

        # Handle a group request
        request_user = self.request.get("request_user")
        if request_user:
            user_id = int(request_user)
            group = self.request.get("request_group")
            if self.request.get("allow") == "True":
                u = User.all().ancestor(ModelrParent.all().get())
                u = u.filter("user_id =", user_id).fetch(1)
                if u:
                    u[0].group.append(group)
                    g = Group.all().ancestor(ModelrParent.all().get())
                    g = g.filter("name =", group).fetch(1)[0]
                    g.allowed_users.append(u[0].user_id)
                    u[0].put()
                    g.put()
            activity = "request_response"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()

            g_req = GroupRequest.all().ancestor(ModelrParent.all().get())
            g_req = g_req.filter("user ="******"group =", group).fetch(100)
            for g in g_req:
                g.delete()

        err_string = '&'.join(err_string) if err_string else ''
        self.redirect('/profile?' + err_string)
Esempio n. 14
0
    def get(self, user):

        template_params = self.get_base_params(user=user)

        self.response.headers['Content-Type'] = 'text/html'

        # Get all the rocks
        rocks = Rock.all()
        rocks.ancestor(user)
        rocks.filter("user ="******"-date")

        default_rocks = Rock.all()
        default_rocks.filter("user ="******"group =", name).fetch(100)}
            rock_groups.append(dic)

        # Get all the fluids
        fluids = Fluid.all()
        fluids.ancestor(user)
        fluids.filter("user ="******"-date")

        default_fluids = Fluid.all()
        default_fluids.filter("user ="******"group =", name).fetch(100)}
            fluid_groups.append(dic)

        # Get all the user scenarios
        scenarios = Scenario.all()
        if not user.user_id == admin_id:
            scenarios.ancestor(user)
        else:
            scenarios.ancestor(ModelrParent.all().get())

        scenarios.filter("user ="******"-date")

        for s in scenarios.fetch(100):
            logging.info((s.name, s))

        if user.user_id != admin_id:
            default_image_models = ImageModel.all()\
                                             .filter("user ="******"user ="******"image": images.get_serving_url(i.image,
                                                           size=200,
                                                           crop=False,
                                                           secure_url=True),
                           "image_key": str(i.key()),
                           "editable": False,
                           "models": EarthModel.all().ancestor(i)
                           .filter("user ="******"image": images.get_serving_url(i.image,
                                                        size=200,
                                                        crop=False,
                                                        secure_url=True),
                        "image_key": str(i.key()),
                        "editable": True,
                        "models": EarthModel.all().ancestor(i)
                        .filter("user ="******"selected_rock"):
            rock_id = self.request.get("selected_rock")
            current_rock = Rock.get_by_id(int(rock_id),
                                          parent=user)
            template_params['current_rock'] = current_rock
        else:
            current_rock = Rock()
            current_rock.name = "name"
            current_rock.description = "description"
            current_rock.vp = 3000.0
            current_rock.vs = 1500.0
            current_rock.rho = 2500.0
            current_rock.vp_std = 50.0
            current_rock.vs_std = 50.0
            current_rock.rho_std = 50.0

            template_params['current_rock'] = current_rock

        # Check if a fluid is being edited
        if self.request.get("selected_fluid"):
            fluid_id = self.request.get("selected_fluid")
            current_fluid = Fluid.get_by_id(int(fluid_id),
                                            parent=user)
            template_params['current_fluid'] = current_fluid
        else:
            current_fluid = Fluid()
            current_fluid.name = "name"
            current_fluid.description = "description"
            current_fluid.vp = 1500.0
            current_fluid.K = 200.0

        template_params['current_fluid'] = current_fluid
        template = env.get_template('dashboard.html')
        html = template.render(template_params)

        activity = "dashboard"
        ActivityLog(user_id=user.user_id,
                    activity=activity,
                    parent=ModelrParent.all().get()).put()
        self.response.out.write(html)
Esempio n. 15
0
    def get(self):

        # Check for a user, but allow guests as well
        user = self.verify()

        self.response.headers['Content-Type'] = 'text/html'
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        hdrs = 'X-Request, X-Requested-With'
        self.response.headers['Access-Control-Allow-Headers'] = hdrs

        # Get the default rocks
        default_rocks = Rock.all().order('name')
        default_rocks.filter("user ="******"group =", group)
                group_rocks.append({"name": group.capitalize(),
                                    "rocks": g_rocks.fetch(100)})

            # Get the users scenarios
            scenarios = \
                Scenario.all().ancestor(user)\
                              .filter("user ="******"user ="******"viewed_scenario"
            ActivityLog(user_id=user.user_id,
                        activity=activity,
                        parent=ModelrParent.all().get()).put()
        self.response.out.write(html)