Готовое ДЗ, страница 2
Описание файла
Документ из архива "Готовое ДЗ", который расположен в категории "". Всё это находится в предмете "технологии разработки программного обеспечения (по)" из 10 семестр (2 семестр магистратуры), которые можно найти в файловом архиве МГТУ им. Н.Э.Баумана. Не смотря на прямую связь этого архива с МГТУ им. Н.Э.Баумана, его также можно найти и в других разделах. Архив можно найти в разделе "курсовые/домашние работы", в предмете "технологии разработки по" в общих файлах.
Онлайн просмотр документа "Готовое ДЗ"
Текст 2 страницы из документа "Готовое ДЗ"
timetables = Timetable.objects.filter(teacher=uid)
return TimetableSet(timetables)
@staticmethod
def filter_by_discipline(uid):
timetables = Timetable.objects.filter(discipline=uid)
return TimetableSet(timetables)
@staticmethod
def filter_by_group(uid):
timetables = Timetable.objects.filter(group=uid)
return TimetableSet(timetables)
@staticmethod
def filter_by_cabinet(number):
timetables = Timetable.objects.filter(cabinet=number)
return TimetableSet(timetables)
@staticmethod
def filter_by_day(number):
timetables = Timetable.objects.filter(day=number)
return TimetableSet(timetables)
MapperEntities
class TeacherObj(object):
def __init__(self, teacher):
self.uid = teacher.id
self.name = teacher.name
self.phone = teacher.phone
self.address = teacher.address
self.status = teacher.status
class GroupObj(object):
def __init__(self, group):
self.uid = group.id
self.index = group.index
class DisciplineObj(object):
def __init__(self, discipline):
self.uid = discipline.id
self.name = discipline.name
self.hours = discipline.hours
class TimetableObj(object):
def __init__(self, timetable):
self.group = GroupObj(timetable.group)
self.teacher = TeacherObj(timetable.teacher)
self.discipline = DisciplineObj(timetable.discipline)
self.duration = timetable.duration
self.cabinet = timetable.cabinet
self.day = timetable.day
class TeacherSet(object):
def __init__(self, teachers):
self.teachers = []
for teacher in teachers:
self.teachers.append(TeacherObj(teacher))
class GroupSet(object):
def __init__(self, groups):
self.groups = []
for group in groups:
self.groups.append(GroupObj(group))
class DisciplineSet(object):
def __init__(self, disciplines):
self.disciplines = []
for d in disciplines:
self.disciplines.append(DisciplineObj(d))
class TimetableSet(object):
def __init__(self, timetables):
self.timetables = []
for t in timetables:
self.timetables.append(TimetableObj(t))
Views
def timetable(request):
t = TimetableModule.get_all_timetable()
groups = GroupModule.get_all_groups()
groups = sorted(groups.groups, key=lambda group: group.uid)
days = [u'Пн', u'Вт', u'Ср', u'Чт', u'Пт', u'Сб']
context = {'timetable': t, 'groups': groups, 'days': days, 'teachform': TeacherForm(),
'groupform': GroupForm(), 'discform': DisciplineForm()}
return render(request, 'timetable/timetable.html', context)
def timetable_by_teacher(request):
t = TimetableModule.get_all_timetable()
teachers = TeacherModule.get_all_teachers()
teachers = sorted(teachers.teachers, key=lambda teacher: teacher.uid)
days = [u'Пн', u'Вт', u'Ср', u'Чт', u'Пт', u'Сб']
context = {'timetable': t, 'teachers': teachers, 'days': days, 'teachform': TeacherForm(),
'groupform': GroupForm(), 'discform': DisciplineForm()}
return render(request, 'timetable/timetable-by-teacher.html', context)
def timetable_of_teacher(request, uid):
intuid = int(uid)
t = TimetableModule.get_timetable_of_teacherid(intuid)
teacher = TeacherModule.get_teacher_by_uid(intuid)
days = [u'Пн', u'Вт', u'Ср', u'Чт', u'Пт', u'Сб']
context = {'teacher': teacher, 'timetable': t, 'days': days, 'teachform': TeacherForm(),
'groupform': GroupForm(), 'discform': DisciplineForm()}
return render(request, 'timetable/timetable-of-teacher.html', context)
def timetable_of_group(request, uid):
intuid = int(uid)
t = TimetableModule.get_timetable_of_groupid(intuid)
group = GroupModule.get_group_by_uid(intuid)
days = [u'Пн', u'Вт', u'Ср', u'Чт', u'Пт', u'Сб']
context = {'group': group, 'timetable': t, 'days': days, 'teachform': TeacherForm(),
'groupform': GroupForm(), 'discform': DisciplineForm()}
return render(request, 'timetable/timetable-of-group.html', context)
def timetable_of_disc(request, uid):
intuid = int(uid)
t = TimetableModule.get_timetable_of_discid(intuid)
disc = DisciplineModule.get_discipline_by_uid(intuid)
days = [u'Пн', u'Вт', u'Ср', u'Чт', u'Пт', u'Сб']
context = {'disc': disc, 'timetable': t, 'days': days, 'teachform': TeacherForm(),
'groupform': GroupForm(), 'discform': DisciplineForm()}
return render(request, 'timetable/timetable-of-disc.html', context)
Выводы
В процессе разработки данного домашнего задания были использованы паттерны разработки “Модуль таблицы” и “Преобразователь данных”, благодаря которым код приобрёл следующие качества:
-
Устойчивость к ошибкам программирования
-
Читаемость для других разработчиков
-
Независимость базы данных от объектов программы
Большая часть времени была затрачена на организацию кода для удовлетворения паттернам, но этот фактор незначителен на фоне выигрываемого времени последующей разработки, а также вышеназванных преимуществ.