Ejemplo n.º 1
0
def create_group(abbr, course, sem, subg, user):
    info = get_group_info(abbr, course, sem)
    group = False
    if ((int(subg) in (1, 2, 0)) and info):

        group = Group(group_info=info, subgroup=subg, user_create=user)
        group.save()
    return group
Ejemplo n.º 2
0
    def copy_group(self, old_group, new_groupset):
        assert new_groupset.groups.filter(name=old_group.name).count(
        ) <= 1, "More than one group with name {0} found".format(
            old_group.name)
        if new_groupset.groups.filter(name=old_group.name).count() == 0:
            # Create new group
            new_group = Group(name=old_group.name,
                              short_name=old_group.short_name,
                              size=old_group.size,
                              groupset=new_groupset)
            # Get parent
            if old_group.parent != None:
                new_parent = self.copy_group(old_group.parent, new_groupset)
                new_group.parent = new_parent
            new_group.save()
        elif new_groupset.groups.filter(name=old_group.name).count() == 1:
            # Return old group
            # print "Returning old group"
            new_group = new_groupset.groups.get(name=old_group.name)

        if old_group.parent is not None and new_group.parent is None:
            new_parent = self.copy_group(old_group.parent, new_groupset)
            print(new_parent)
            print("Napaka")
            new_group.parent = new_parent
            new_group.save()

        return new_group
Ejemplo n.º 3
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.º 4
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
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)