Example #1
0
    def _search_faculties(self, query, count, a):
        try:
            faculties = Faculty.objects(
                db.Q(title__icontains=query)
                | db.Q(description__icontains=query)).limit(count)
            if len(faculties) == 0:
                r = self.get_excellent_dict()
                r["response"] = []
                return self.dump_dict(r)

            r = self.get_excellent_dict()
            r["response"] = []
            for i in faculties:
                f = OrderedDict()
                f["abbr"] = i.abbr
                f["title"] = i.title
                f["description"] = i.description
                f["img"] = "http://{}{}{}.gif".format(self.ROOT, self.IMG_PATH,
                                                      i.abbr)
                r["response"].append(f)

            return self.dump_dict(r)
        except Exception, e:
            #return str(e)
            return error(3)
Example #2
0
def test_json():
    cs = {}
    knt = Faculty.objects(abbr="cs").first()
    cs["title"] = knt.title
    cs["abbr"] = knt.abbr
    cs["description"] = knt.description
    cs["groups"] = []
    for g in knt.groups:
        cs["groups"].append({"title": g.title, "abbr": g.abbr, "description": g.description})
    return json.dumps(cs, ensure_ascii=False, indent=4)
Example #3
0
def test_json():
    cs = {}
    knt = Faculty.objects(abbr="cs").first()
    cs["title"] = knt.title
    cs["abbr"] = knt.abbr
    cs["description"] = knt.description
    cs["groups"] = []
    for g in knt.groups:
        cs["groups"].append({
            "title": g.title,
            "abbr": g.abbr,
            "description": g.description
        })
    return json.dumps(cs, ensure_ascii=False, indent=4)
Example #4
0
    def _search_faculties(self, query, count, a):
        try:
            faculties = Faculty.objects(db.Q(title__icontains=query) | db.Q(description__icontains=query)).limit(count)
            if len(faculties) == 0:
                r = self.get_excellent_dict()
                r["response"] = []
                return self.dump_dict(r)

            r = self.get_excellent_dict()
            r["response"] = []
            for i in faculties:
                f = OrderedDict()
                f["abbr"] = i.abbr
                f["title"] = i.title
                f["description"] = i.description
                f["img"] = "http://{}{}{}.gif".format(self.ROOT, self.IMG_PATH, i.abbr)
                r["response"].append(f)

            return self.dump_dict(r)
        except Exception, e:
            # return str(e)
            return error(3)