Ejemplo n.º 1
0
def lecturer(lecturer='all'):
    lect = []
    if request.method == 'GET':

        if lecturer == 'all':
            lect = map(lambda i: i.name, Lecturer.objects.all())

        else:
            lect = map(lambda i: i.name, Lecturer.objects(id=lecturer).all())

        return str(lecturer) + " " + "<br />".join(lect)
    else:
        return "Post"
Ejemplo n.º 2
0
    def _search_lecturers(self, query, count, a):
        try:
            lecturers = Lecturer.objects(db.Q(name__icontains=query) | db.Q(degree__icontains=query)).limit(count)
            if len(lecturers) == 0:
                r = self.get_excellent_dict()
                r["response"] = []
                return self.dump_dict(r)

            r = self.get_excellent_dict()
            r["response"] = []
            for i in lecturers:
                f = OrderedDict()
                f["id"] = str(i.id)
                f["name"] = i.name
                f["degree"] = i.degree
                r["response"].append(f)

            return self.dump_dict(r)
        except Exception, e:
            return str(e)
            return error(3)
Ejemplo n.º 3
0
    def _search_lecturers(self, query, count, a):
        try:
            lecturers = Lecturer.objects(
                db.Q(name__icontains=query)
                | db.Q(degree__icontains=query)).limit(count)
            if len(lecturers) == 0:
                r = self.get_excellent_dict()
                r["response"] = []
                return self.dump_dict(r)

            r = self.get_excellent_dict()
            r["response"] = []
            for i in lecturers:
                f = OrderedDict()
                f["id"] = str(i.id)
                f["name"] = i.name
                f["degree"] = i.degree
                r["response"].append(f)

            return self.dump_dict(r)
        except Exception, e:
            return str(e)
            return error(3)
Ejemplo n.º 4
0
    def _get_lessons_lecturer(self, week, weekday, item_number, a):
        try:

            lecturer_id = a.get("lecturer_id", "")
            if lecturer_id == "":
                return error(16)

            lecturer = None
            try:
                lecturer = Lecturer.objects(id=lecturer_id).first()
            except Exception:
                pass
            if lecturer == None:
                return error(17)

            r = self.get_excellent_dict()
            r["response"] = OrderedDict()
            r["response"]["id"] = str(lecturer.id)
            r["response"]["name"] = lecturer.name

            r["response"]["lessons"] = []

            lessons = lecturer.lessons

            if week != Week.ALL:
                lessons = filter(lambda i: i.week == week, lessons)

            if weekday != Weekday.ALL:
                lessons = filter(lambda i: i.weekday == weekday, lessons)

            if item_number != ItemNumberHelper.ALL:
                lessons = filter(lambda i: i.item_number == item_number, lessons)

            for i in lessons:
                try:
                    l = OrderedDict()
                    l["title"] = i.title
                    l["room"] = i.room
                    l["item_number"] = i.item_number
                    l["weekday_number"] = i.weekday
                    l["weekday"] = Weekday.get_string(i.weekday)
                    l["week_number"] = i.week
                    l["week"] = Week.get_string(i.week)
                    l["description"] = i.description

                    l["groups"] = []

                    for j in i.subgroups:
                        try:
                            s = OrderedDict()
                            s["abbr"] = j.group.abbr
                            s["title"] = j.group.title
                            l["groups"].append(s)
                        except Exception:
                            pass

                    r["response"]["lessons"].append(l)
                except Exception:
                    pass

            return self.dump_dict(r)
        except Exception, e:
            # return str(e)
            return error(3)
Ejemplo n.º 5
0
    def _get_lessons_lecturer(self, week, weekday, item_number, a):
        try:

            lecturer_id = a.get("lecturer_id", "")
            if lecturer_id == "":
                return error(16)

            lecturer = None
            try:
                lecturer = Lecturer.objects(id=lecturer_id).first()
            except Exception:
                pass
            if lecturer == None:
                return error(17)

            r = self.get_excellent_dict()
            r["response"] = OrderedDict()
            r["response"]["id"] = str(lecturer.id)
            r["response"]["name"] = lecturer.name

            r["response"]["lessons"] = []

            lessons = lecturer.lessons

            if week != Week.ALL:
                lessons = filter(lambda i: i.week == week, lessons)

            if weekday != Weekday.ALL:
                lessons = filter(lambda i: i.weekday == weekday, lessons)

            if item_number != ItemNumberHelper.ALL:
                lessons = filter(lambda i: i.item_number == item_number,
                                 lessons)

            for i in lessons:
                try:
                    l = OrderedDict()
                    l["title"] = i.title
                    l["room"] = i.room
                    l["item_number"] = i.item_number
                    l["weekday_number"] = i.weekday
                    l["weekday"] = Weekday.get_string(i.weekday)
                    l["week_number"] = i.week
                    l["week"] = Week.get_string(i.week)
                    l["description"] = i.description

                    l["groups"] = []

                    for j in i.subgroups:
                        try:
                            s = OrderedDict()
                            s["abbr"] = j.group.abbr
                            s["title"] = j.group.title
                            l["groups"].append(s)
                        except Exception:
                            pass

                    r["response"]["lessons"].append(l)
                except Exception:
                    pass

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