Exemplo n.º 1
0
class PrivateTitleFields(widgets.WidgetsList):
    import operator
    preferred_distributor = widgets.TextField()
    title_id = widgets.HiddenField()
    all_sections = [(l.id, l.sectionName) for l in list(Section.select())]
    all_sections.sort(key=operator.itemgetter(1))
    sections = widgets.CheckBoxList(options=all_sections, field_class='inline')
Exemplo n.º 2
0
 def section(self, section=None):
     the_section = Section.get(section)
     titles_in_section = [
         t for t in the_section.titles if t.copies_in_status("STOCK") > 0
     ]
     titles_in_section.sort(key=lambda x: x.booktitle)
     #titles_in_section=Title.select("kind_id=1 and title.id=section_title.title_id and titletag.tagvalue='History' and titletag.tagkey='section'",clauseTables=["section_title"],orderBy="booktitle",distinct=True)
     return dict(authorswidget=AuthorsWidget(),
                 titlelistwidget=TitleListWidget(),
                 the_section=the_section,
                 in_this_section=titles_in_section)
Exemplo n.º 3
0
 def edit_title(self,title_id,**kw):
     title=Title.get(title_id)
     if kw['preferred_distributor']:
         title.set_unique_tag(category='distribution',key='preferred',value=kw['preferred_distributor'])
     if kw.has_key('sections'):
         the_sections=kw['sections']
         if type(the_sections) != type([0,1]):
             the_sections=[the_sections]
         #title.set_tag_collection(category='inventory',key='section',values=the_sections)
         for s in title.sections:
             print "Removing %s" % s 
             title.removeSection(s)
         for s in the_sections:
             print "Adding %s" % s 
             title.addSection(Section.get(s))
         
     return self.title(title_id)
Exemplo n.º 4
0
    def edit_title(self, title_id, **kw):
        title = Title.get(title_id)
        if kw['preferred_distributor']:
            title.set_unique_tag(category='distribution',
                                 key='preferred',
                                 value=kw['preferred_distributor'])
        if kw.has_key('sections'):
            the_sections = kw['sections']
            if type(the_sections) != type([0, 1]):
                the_sections = [the_sections]
            #title.set_tag_collection(category='inventory',key='section',values=the_sections)
            for s in title.sections:
                print "Removing %s" % s
                title.removeSection(s)
            for s in the_sections:
                print "Adding %s" % s
                title.addSection(Section.get(s))

        return self.title(title_id)
Exemplo n.º 5
0
class Gen:
    # create a timetable to schedule lectures

    timeslots = [
        TimeSlot('8:00', '10:00'),
        TimeSlot('10:00', '12:00'),
        TimeSlot('12:00', '14:00'),
        TimeSlot('14:00', '16:00'),
        TimeSlot('16:00', '18:00')
    ]

    csv.register_dialect('myDialect', delimiter=',', skipinitialspace=True)
    lectures = []
    rooms = []

    # items = FlatTimeTableModel.return_all_raw()
    # for i in items:
    #     lecturer = Lecturer(
    #         i.first_examiner,
    #         None,
    #         i.lecturer_title
    #     )
    #     course = (
    #         i.course_name,
    #         i.department_code,
    #         i.course_code,
    #         i.teaching,
    #         i.practicals,
    #         i.credit,
    #         i.tutorial,
    #     )
    #
    #     section = Section(
    #         i.section_department,
    #         i.year,
    #         None,
    #         i.size,
    #     )
    #     c_item = CurriculumItem(section, course, lecturer)
    #     lecture = Lecture(c_item, 120)
    #     lectures.append(lecture)

    with open('../objects/curriculum.csv', 'r') as csvFile:
        reader = csv.DictReader(csvFile, dialect='myDialect')
        for row in reader:
            r = (dict(row))
            lecturer = Lecturer(r['Lecturer name'].strip(),
                                r['Lecturer Id'].strip(),
                                r['Lecturer Title'].strip())
            # lec = LecturerModel()
            # lec.name = lecturer.name
            # lec.stuff_id = r['Lecturer Id'].strip() or None
            # lec.title = r['Lecturer Title'].strip()

            course = Course(r['Course name'].strip(),
                            r['Department code'].strip(),
                            r['Course code'].strip(), r['T'].strip(),
                            r['P'].strip(), r['C'].strip(),
                            r['Tutorial'].strip())
            section = Section(r['Section department'].strip(),
                              r['Year'].strip(), r['Section code'].strip(),
                              int(r['Class size'].strip()))
            # flm = FlatTimeTableModel()
            # flm.course_code = course.course_code,
            c_item = CurriculumItem(section, course, lecturer)
            lecture = Lecture(c_item, 120)
            lectures.append(lecture)

    csvFile.close()
    with open('../objects/rooms.csv', 'r') as csvFile:
        reader = csv.DictReader(csvFile, dialect='myDialect')
        for row in reader:
            r = (dict(row))
            room = Classroom(r['Name'].strip(), int(r['Capacity'].strip()),
                             r['Building'].strip(), r['Allowance'].strip())
            rooms.append(room)
    csvFile.close()

    days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
    day_tables = []

    for day in days:
        day_tables.append(DayTimetable(rooms, timeslots, day))
    timetable = Timetable(days, day_tables)
    # print(timetable)
    # create a list of lectures to be scheduled
    lecturer = Lecturer('Benjamin Kommey', 4564541, 'Mr')
    # course = Course('Opearating Systems','COE 361')

    # section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
    # c_item = CurriculumItem(section,course,lecturer)
    #
    # lecture = Lecture(c_item,60)
    # lectures = [lecture]
    #
    # lecturer = Lecturer('Yao Ming',4564541,'Mr')
    # #course = Course('Control Systems','COE 63')
    #
    # section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
    # #c_item = CurriculumItem(section,course,lecturer)
    #
    # lectures.append(Lecture(c_item,60))
    #
    # lecturer = Lecturer('J Yankey',4564541,'Mr')
    # course = Course('Software Systems','COE 371')
    #
    # section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
    # c_item = CurriculumItem(section,course,lecturer)
    #
    # lectures.append(Lecture(c_item,120))
    #
    # lecturer = Lecturer('Helle Rubie',4564541,'Mr')
    # course = Course('Embedded Systems','COE 381')
    #
    # section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
    # c_item = CurriculumItem(section,course,lecturer)
    #
    # lectures.append(Lecture(c_item,120))

    # create a timetable generator initialized to both

    generator = TimeTableGenerator(timetable, lectures)

    # #print(generator.unscheduled)

    generator.generate_timetable()

    def json(self):
        dicts = []
        days = self.generator.timetable.days
        table = self.generator.timetable.timetable
        for d in days:
            obj = table[d]
            for i in self.rooms:
                for k in obj.table[i]:
                    print(k.lecture)
                    if k.lecture is not None:
                        ci = k.lecture.curriculum_item
                        print(d)
                        print(str(k.room.name))
                        print(
                            str(ci.section.department) + ' ' +
                            str(ci.section.year))
                        print(str(ci.course))
                        print(str(ci.lecturer))
                        dt = dict(day=d,
                                  room=str(k.room.name),
                                  course=str(ci.course),
                                  section=str(ci.section.department) + ' ' +
                                  str(ci.section.year),
                                  lecturer=str(ci.lecturer),
                                  time=str(k.time_slot))
                        dicts.append(dt)
        return dicts


# if __name__ == '__main__':
#     g = Gen()
#     g.json()
Exemplo n.º 6
0
 def section(self,section=None):
     the_section=Section.get(section)
     titles_in_section=[t for t in the_section.titles if t.copies_in_status("STOCK")>0]   
     titles_in_section.sort(key=lambda x: x.booktitle)
     #titles_in_section=Title.select("kind_id=1 and title.id=section_title.title_id and titletag.tagvalue='History' and titletag.tagkey='section'",clauseTables=["section_title"],orderBy="booktitle",distinct=True)
     return dict(authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget(),the_section=the_section,in_this_section=titles_in_section)
Exemplo n.º 7
0
 def sections(self):
     return dict(authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget(),sections=Section.select("1=1",orderBy="section_name"),the_sections=False)
Exemplo n.º 8
0
 def section(self,section_id,**kw):
     section=Section.get(section_id)
     return dict(section=section)
Exemplo n.º 9
0
 def sections(self):
     return dict(authorswidget=AuthorsWidget(),
                 titlelistwidget=TitleListWidget(),
                 sections=Section.select("1=1", orderBy="section_name"),
                 the_sections=False)
Exemplo n.º 10
0
 def section(self, section_id, **kw):
     section = Section.get(section_id)
     return dict(section=section)