Esempio 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)
Esempio n. 2
0
def group(group='all'):
    res = ""
    if request.method == 'GET':
        if group == 'all':
            res = 'all'
        else:
            gr = Group.objects(abbr=group).first()
            res = gr.title + "<br />"
            lessons = gr.lessons
            res = res + u"Понидельник:" + "<br />"
            l = filter(lambda i: i.weekday == Weekday.MONDAY, lessons)
            res = res + u"<br />".join(
                map(
                    lambda i: i.title + u", " + i.lecturer.name + u", " + i.
                    room, sorted(l, key=lambda i: i.item_number)))
    return res
Esempio n. 3
0
    def _search_groups(self, query, count, a):
        try:
            groups = Group.objects(db.Q(title__icontains=query) | db.Q(description__icontains=query)).limit(count)
            if len(groups) == 0:
                r = self.get_excellent_dict()
                r["response"] = []
                return self.dump_dict(r)

            r = self.get_excellent_dict()
            r["response"] = []
            for i in groups:
                f = OrderedDict()
                f["abbr"] = i.abbr
                f["title"] = i.title
                f["description"] = i.description
                r["response"].append(f)

            return self.dump_dict(r)
        except Exception, e:
            # return str(e)
            return error(3)
Esempio n. 4
0
    def _search_groups(self, query, count, a):
        try:
            groups = Group.objects(
                db.Q(title__icontains=query)
                | db.Q(description__icontains=query)).limit(count)
            if len(groups) == 0:
                r = self.get_excellent_dict()
                r["response"] = []
                return self.dump_dict(r)

            r = self.get_excellent_dict()
            r["response"] = []
            for i in groups:
                f = OrderedDict()
                f["abbr"] = i.abbr
                f["title"] = i.title
                f["description"] = i.description
                r["response"].append(f)

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