Exemplo n.º 1
0
 def handle_list_add(self, req: HTTPRequest, res: HTTPResponse):
     id = req.params["idl"]
     idfilm = req.params["idfilm"]
     if not self.db.userdata.add_to_list(idfilm, id):
         res.serve404()
     else:
         self.db.userdata.save()
Exemplo n.º 2
0
 def handle_list_get(self, req: HTTPRequest, res: HTTPResponse):
     id = req.params["idl"]
     x = self.db.userdata.list_get_by_id(id)
     if x:
         res.end(x.json_set(self.db), "application/json")
     else:
         res.serve404()
Exemplo n.º 3
0
    def handle_results(self, req: HTTPRequest, res: HTTPResponse):
        path = config.www("results.html")
        request = ""
        pagesize = AlloServer.RESULT_PER_PAGE
        if req.method == "POST":
            body = req.body_json()
            if "json" in body:
                bodyjson = json.loads(body["json"])
                if "nperpage" in bodyjson:
                    pagesize = int(bodyjson["nperpage"])
                request = json_to_request(bodyjson)
            elif "text" in body:
                request = "(select * where " + unquote_plus(
                    body["text"]) + " )"
            tmp = Request(self.db.execute(request))
            x = tmp.result
            x.pagesize = pagesize
            self.requests[x.id] = tmp
        else:
            if "id" in req.params and "page" in req.params and req.params[
                    "id"] in self.requests:
                x = self.requests[req.params["id"]].result
                x.page = int(req.params["page"]) - 1
            else:
                return res.serve400()

        self._check_query(req, x)
        res.serve_file_gen(path, x.moustache(self.userlist_object()))
Exemplo n.º 4
0
 def handle_import(self, req: HTTPRequest, res: HTTPResponse):
     f = req.multipart_next_file()
     #f.save(config.user("fanch"), forcePath=True)
     x = f.parse_content()
     js = json.loads(x)
     self.db.userdata.import_json(js["db"])
     res.serve301("/")
Exemplo n.º 5
0
 def handle_short(self, req: HTTPRequest, res: HTTPResponse):
     path = config.www("results.html")
     short = AlloServer.SHORT_REQUESTS[req.params["id"]]
     tmp = Request(self.db.execute(short[0]))
     x = tmp.result
     x.pagesize = 10
     self.requests[x.id] = tmp
     res.serve_file_gen(
         path, x.moustache(self.userlist_object({"name": short[1]})))
Exemplo n.º 6
0
 def handle_list_rename(self, req: HTTPRequest, res: HTTPResponse):
     id = req.params["idl"]
     name = req.params["name"]
     x = self.db.userdata.list_get_by_id(id)
     if x:
         x.name = name
         self.db.userdata.save()
     else:
         res.serve404()
Exemplo n.º 7
0
 def handle_list_down(self, req: HTTPRequest, res: HTTPResponse):
     id = req.params["idl"]
     idfilm = req.params["idfilm"]
     x = self.db.userdata.list_get_by_id(id)
     if x:
         x.down(idfilm)
         self.db.userdata.save()
     else:
         res.serve404()
Exemplo n.º 8
0
 def handle_run_request(self, req: HTTPRequest, res: HTTPResponse):
     path = config.www("results.html")
     name = req.params["name"]
     args = self.db.userdata.requests[name]["values"]
     request = json_to_request(args)
     tmp = Request(self.db.execute(request))
     x = tmp.result
     x.pagesize = args["nperpage"] if "nperpage" in args else 20
     self.requests[x.id] = tmp
     res.serve_file_gen(path, x.moustache(self.userlist_object()))
Exemplo n.º 9
0
 def handle_search_film(self, req: HTTPRequest, res: HTTPResponse):
     id = req.params["id"]
     if str(id) in self.db.ids:
         row = self.db.ids[str(id)]
         year = row.resolve("year")
         if not year or year <= 1900: year = None
         title = row.resolve("name")
         res.end(filmfinder.find_film(title, year), "application/json")
     else:
         res.serve404()
Exemplo n.º 10
0
 def handle_film(self, req: HTTPRequest, res: HTTPResponse):
     id = req.params["id"]
     if not id in self.db.ids: return res.serve404()
     path = config.www("film.html")
     tmp = Request(self.db.row_from_id(id))
     x = tmp.result
     x.pagesize = AlloServer.RESULT_PER_PAGE
     self.requests[x.id] = tmp
     self._check_query(req, x)
     res.serve_file_gen(path, x.moustache(self.userlist_object()))
Exemplo n.º 11
0
 def handle_actor(self, req: HTTPRequest, res: HTTPResponse):
     id = req.params["id"].replace("+", " ")
     if not id in self.db.actors: return res.serve404()
     path = config.www("results.html")
     tmp = Request(self.db.row_from_actor(id))
     x = tmp.result
     x.pagesize = AlloServer.RESULT_PER_PAGE
     self.requests[x.id] = tmp
     self._check_query(req, x)
     print(self.db.userdata.list_json())
     res.serve_file_gen(path, x.moustache(self.userlist_object({"name":
                                                                id})))
Exemplo n.º 12
0
    def handle_film_modify(self, req: HTTPRequest, res: HTTPResponse):
        id = req.params["id"]
        if not id in self.db.ids: return res.serve404()
        js = req.body_json()
        if not js: return res.serve400()

        row = self.db.ids[id]
        out = []
        for x in js:
            out.append((x, js[x]))

        row.set(out)
Exemplo n.º 13
0
    def handle_show_list(self, req: HTTPRequest, res: HTTPResponse):
        path = config.www("results.html")
        page = 0
        pagesize = AlloServer.RESULT_PER_PAGE
        if "page" in req.params: page = int(req.params["page"] - 1)
        id = req.params["id"]
        if id in self.db.userdata.lists:
            tmp = Request(self.db.userdata.lists[id].result_set(self.db))
            x = tmp.result
            x.pagesize = 50
            self.requests[x.listid] = tmp
            x.page = page

            self._check_query(req, x)
            res.serve_file_gen(path, x.moustache(self.userlist_object()))
        else:
            res.serve404()
Exemplo n.º 14
0
 def handle_results_export(self, req: HTTPRequest, res: HTTPResponse):
     if "id" in req.params and req.params["id"] in self.requests:
         x = self.requests[req.params["id"]].result
         data = ""
         format = req.params["format"]
         filename = req.params["filename"]
         if format == "csv":
             data = str(x)
             res.header("Content-Type", "text/csv")
         elif format == "json":
             data = x.moustache()
             res.header("Content-Type", "application/json")
         res.header("Content-Disposition",
                    "attachment; filename=\"%s\"" % filename)
         res.end(data)
     else:
         return res.serve400()
Exemplo n.º 15
0
 def handle_get_request(self, req: HTTPRequest, res: HTTPResponse):
     res.serve_file_gen(config.www("index.html"),
                        self.userlist_object({"run": req.params["name"]}))
Exemplo n.º 16
0
 def handle_list_create(self, req: HTTPRequest, res: HTTPResponse):
     name = req.params["name"]
     l = AlloList(name=name)
     self.db.userdata.lists[l.id] = l
     res.end(l.json(), "application/json")
     self.db.userdata.save()
Exemplo n.º 17
0
 def handle_autocomplete(self, req: HTTPRequest, res: HTTPResponse):
     type = req.params["type"]
     match = req.params["match"]
     max = int(req.params["max"]) if "max" in req.params else -1
     res.serveJson(self.db.autocomplete(match, type, max))
Exemplo n.º 18
0
 def handle_list_remove_item(self, req: HTTPRequest, res: HTTPResponse):
     id = req.params["idl"]
     idfilm = req.params["idfilm"]
     if not self.db.userdata.remove_to_list(idfilm, id):
         res.serve404()
Exemplo n.º 19
0
 def handle_list_all(self, req: HTTPRequest, res: HTTPResponse):
     x = self.db.userdata.list_json()
     res.end(x, "application/json")
Exemplo n.º 20
0
 def handle_export(self, req: HTTPRequest, res: HTTPResponse):
     self.db.userdata.save()
     res.serve_file(config.user("fanch"), forceDownload=True)