Ejemplo n.º 1
0
    def _get_lessons_group(self, week, weekday, item_number, a):
        try:

            group_abbr = a.get("group_abbr", "")

            if group_abbr == "":
                return error(14)

            group = Group.objects(abbr=group_abbr).first()
            if group == None:
                return error(15)

            group_id = group.id

            r = self.get_excellent_dict()
            r["response"] = OrderedDict()
            r["response"]["abbr"] = group.abbr
            r["response"]["title"] = group.title

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

            lessons = group.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:
                l = OrderedDict()

                l["title"] = i.title
                l["room"] = i.room
                l["lecturer"] = i.lecturer.name
                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

                try:
                    sb = filter(lambda o: o.group.id == group_id, i.subgroups)[0].subgroup
                    l["subgroup"] = [sb] if sb == SubgroupHelper.ALL else SubgroupHelper.get_numbers(sb)
                except:
                    pass

                r["response"]["lessons"].append(l)

            return self.dump_dict(r)
        except Exception, e:
            # return str(e)
            return error(3)
Ejemplo n.º 2
0
    def _get_lessons(self, e, a):
        handle_func = self.ENTITYS_GET_LESSONS[e]
        week = to_int(a.get("week", Week.ALL))
        weekday = to_int(a.get("weekday", Weekday.ALL))
        item_number = to_int(a.get("item_number", ItemNumberHelper.ALL))

        if not Week.is_correct(week):
            return error(11)

        if not Weekday.is_correct(weekday):
            return error(12)

        if not ItemNumberHelper.is_correct(item_number):
            return error(13)

        return handle_func(week, weekday, item_number, a)
Ejemplo n.º 3
0
    def _get_lessons(self, e, a):
        handle_func = self.ENTITYS_GET_LESSONS[e]
        week = to_int(a.get("week", Week.ALL))
        weekday = to_int(a.get("weekday", Weekday.ALL))
        item_number = to_int(a.get("item_number", ItemNumberHelper.ALL))

        if not Week.is_correct(week):
            return error(11)

        if not Weekday.is_correct(weekday):
            return error(12)

        if not ItemNumberHelper.is_correct(item_number):
            return error(13)

        return handle_func(week, weekday, item_number, a)
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_group(self, week, weekday, item_number, a):
        try:

            group_abbr = a.get("group_abbr", "")

            if group_abbr == "":
                return error(14)

            group = Group.objects(abbr=group_abbr).first()
            if group == None:
                return error(15)

            group_id = group.id

            r = self.get_excellent_dict()
            r["response"] = OrderedDict()
            r["response"]["abbr"] = group.abbr
            r["response"]["title"] = group.title

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

            lessons = group.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:
                l = OrderedDict()

                l["title"] = i.title
                l["room"] = i.room
                l["lecturer"] = i.lecturer.name
                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

                try:
                    sb = filter(lambda o: o.group.id == group_id,
                                i.subgroups)[0].subgroup
                    l["subgroup"] = [
                        sb
                    ] if sb == SubgroupHelper.ALL else SubgroupHelper.get_numbers(
                        sb)
                except:
                    pass

                r["response"]["lessons"].append(l)

            return self.dump_dict(r)
        except Exception, e:
            #return str(e)
            return error(3)
Ejemplo n.º 6
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)