Exemple #1
0
    def get_edit(self, request):
        username = request.getCookie('username')

        title = request.args.get('title', '')
        request.args['title'] = title

        if 'delete' in request.args and title != '':
            user_id = model.ensure_user_exists(self.__SessionMaker, username)
            model.remove_graph(self.__SessionMaker, user_id, title)

            request.setResponseCode(303)
            request.redirect('/')
            return ''

        data_sources = model.get_data_sources(self.__SessionMaker)

        for each_metric in data_sources.itervalues():
            each_metric.sort()

        active_components = \
                [each.split('|')[0] for each in request.args if '|' in each]

        graph_type = request.args.get('graph_type', '')

        template = self.__template_lookup.get_template('edit.mako')

        return template.render(kwargs=request.args, data_sources=data_sources,
                active_components=active_components, username=username,
                timescales=self.timescales,
                graph_types=self.graph_types).encode('utf8')
Exemple #2
0
    def get_index(self, request):
        username = request.getCookie('username')

        if 'edit' in request.args:
            edit = request.args['edit']
        else:
            edit = None

        session = self.__SessionMaker()

        rows = session.query(Data.component).group_by(Data.component).order_by(
                Data.component).all()

        session.close()

        keys = [each[0] for each in rows]

        # Look up custom graphs for this user
        if username is not None:
            user_id = model.ensure_user_exists(self.__SessionMaker, username)
            graphs = model.get_graphs(self.__SessionMaker, user_id)

        else:
            user_id = None
            graphs = None

        template = self.__template_lookup.get_template('index.mako')

        return template.render(components=keys, username=username, edit=edit,
                user_id=user_id, graphs=graphs).encode('utf8')
    def get_edit(self, request):
        username = request.getCookie("username")

        title = request.args.get("title", "")
        request.args["title"] = title

        if "delete" in request.args and title != "":
            user_id = model.ensure_user_exists(self.__SessionMaker, username)
            model.remove_graph(self.__SessionMaker, user_id, title)

            request.setResponseCode(303)
            request.redirect("/")
            return ""

        data_sources = model.get_data_sources(self.__SessionMaker)

        for each_metric in data_sources.itervalues():
            each_metric.sort()

        active_components = [each.split("|")[0] for each in request.args if "|" in each]

        graph_type = request.args.get("graph_type", "")

        template = self.__template_lookup.get_template("edit.mako")

        return template.render(
            kwargs=request.args,
            data_sources=data_sources,
            active_components=active_components,
            username=username,
            timescales=self.timescales,
            graph_types=self.graph_types,
        ).encode("utf8")
Exemple #4
0
    def get_edit(self, request):
        user_session = request.getSession()
        username = self.__user_sessions.get(user_session)

        title = request.args.get('title', '')
        request.args['title'] = title

        if 'delete' in request.args and title != '':
            user_id = model.ensure_user_exists(self.__SessionMaker, username)
            model.remove_graph(self.__SessionMaker, user_id, title)

            request.setResponseCode(303)
            request.redirect('/')
            request.finish()
            return

        graph_type = request.args.get('graph_type', '')

        data_sources = model.get_data_sources(self.__SessionMaker)

        for each_metric in data_sources.itervalues():
            each_metric.sort()

        template = self.__template_lookup.get_template('edit.mako')

        return template.render(kwargs=request.args, data_sources=data_sources,
                username=username, timescales=self.timescales,
                graph_types=self.graph_types)
Exemple #5
0
    def post_login(self, request):
        user_session = request.getSession()

        if request.args.get('username', None) is None:
            request.setResponseCode(400)
            request.redirect('/')
            request.finish()
            return

        username = request.args['username'].lower()
        self.__user_sessions[user_session] = username

        model.ensure_user_exists(self.__SessionMaker, username)

        referer = request.getHeader('Referer')
        if referer is None:
            referer = '/'

        request.setResponseCode(303)
        request.redirect(referer)
        request.finish()
        return
Exemple #6
0
    def post_login(self, request):
        if request.args.get('username', None) is None:
            request.setResponseCode(400)
            request.redirect('/')
            return ''

        username = request.args['username'].lower()

        # Save the username as a cookie
        current_utc_time = datetime.datetime.utcnow()
        current_utc_time += datetime.timedelta(days=365)
        expires_str = current_utc_time.strftime('%a, %d-%b-%Y %H:%M:%S GMT')

        request.addCookie('username', username, expires=expires_str)

        model.ensure_user_exists(self.__SessionMaker, username)

        referer = request.getHeader('Referer')
        if referer is None:
            referer = '/'

        request.setResponseCode(303)
        request.redirect(referer)
        return ''
Exemple #7
0
    def post_edit(self, request):
        user_session = request.getSession()
        username = self.__user_sessions.get(user_session)

        if request.args['title'] == '':
            request.args['error'] = 'no_title'
            redirect = '/edit?%s' % urllib.urlencode(request.args)

            request.setResponseCode(303)
            request.redirect(redirect)
            request.finish()
            return

        elif len(request.args) == 3:
            request.args['error'] = 'no_fields'
            redirect = '/edit?%s' % urllib.urlencode(request.args)

            request.setResponseCode(303)
            request.redirect(redirect)
            request.finish()
            return

        user_id = model.ensure_user_exists(self.__SessionMaker, username)
        title = request.args['title']
        timescale = request.args['timescale']
        graph_type = request.args['graph_type']

        keys = request.args.keys()
        index = keys.index('title')
        del keys[index]

        index = keys.index('graph_type')
        del keys[index]

        index = keys.index('timescale')
        del keys[index]

        model.update_graph(self.__SessionMaker, title, user_id, timescale, keys,
                graph_type)

        request.setResponseCode(303)
        request.redirect('/')
        request.finish()
        return
Exemple #8
0
    def post_graph_ordering(self, request):
        log.debug('post graph ordering %s', request.args)

        new_ordering = request.args.get('new_ordering', '')
        user_id = None

        username = request.getCookie('username')
        if username is not None:
            user_id = model.ensure_user_exists(self.__SessionMaker, username)

        if new_ordering == '' or user_id is None:
            request.setResponseCode(400)
            return ''

        new_ordering = simplejson.loads(new_ordering)

        model.update_ordering(self.__SessionMaker, user_id, new_ordering)

        request.setResponseCode(200)
        return ''
    def post_edit(self, request):
        username = request.getCookie("username")

        if request.args["title"] == "":
            request.args["error"] = "no_title"
            redirect = "/edit?%s" % urllib.urlencode(request.args)

            request.setResponseCode(303)
            request.redirect(redirect)
            return ""

        elif len(request.args) == 3:
            request.args["error"] = "no_fields"
            redirect = "/edit?%s" % urllib.urlencode(request.args)

            request.setResponseCode(303)
            request.redirect(redirect)
            return ""

        user_id = model.ensure_user_exists(self.__SessionMaker, username)
        title = request.args["title"]
        timescale = request.args["timescale"]
        graph_type = request.args["graph_type"]

        keys = request.args.keys()
        index = keys.index("title")
        del keys[index]

        index = keys.index("graph_type")
        del keys[index]

        index = keys.index("timescale")
        del keys[index]

        model.update_graph(self.__SessionMaker, title, user_id, timescale, keys, graph_type)

        request.setResponseCode(303)
        request.redirect("/")
        return ""