Пример #1
0
 def get(self):
     group = self.request.get("group")
     subgroup = self.request.get("subgroup", None)
     week_num = self.request.get("week", None)
     subgroup = bsuirparser.subgroup2int(subgroup)
     week_num = bsuirparser.week2int(week_num)
     if not group:  # main page
         self.redirect("/")
     else:
         groupdata = get_group_data(group)
         if not groupdata:
             path = os.path.join(os.path.dirname(__file__), "templates", "erroratbsuir.html")
             self.response.out.write(
                 template.render(path, {"group": group, "default_group": get_preferred_group_params(self.request)})
             )
             return
         study_week = groupdata[DICTDATA_SCHEDULE_KEY_NAME]
         if study_week:
             localised_date = pytz.utc.localize(groupdata["date"]).astimezone(minsk_tz)
             now_date = (datetime.datetime.now(tz=pytz.utc)).astimezone(minsk_tz)
             study_week = study_week.filter(subgroup, week_num)
             path = os.path.join(os.path.dirname(__file__), "templates", "schedule.html")
             self.response.out.write(
                 template.render(
                     path,
                     {
                         "week": study_week,
                         "group": group,
                         "subgroup": subgroup,
                         "selweek": week_num,
                         "weeknumbers": range(1, 5),
                         "default_group": get_preferred_group_params(self.request),
                         "fetcheddate": localised_date,
                         "current_week": bsuirparser.get_week_num(now_date.year, now_date.month, now_date.day),
                     },
                 )
             )
         else:
             self.response.headers["Content-Type"] = "text/plain"
             self.response.out.write(u"Что-то пошло не так")
             logging.debug(u"Ошибка при разборе расписания")
Пример #2
0
 def get(self):
     group = self.request.get("group")
     subgroup = self.request.get("subgroup", None)
     week_num = self.request.get("week", None)
     subgroup = bsuirparser.subgroup2int(subgroup)
     week_num = bsuirparser.week2int(week_num)
     if not group: #main page
         self.redirect("/")
     else:
         groupdata = get_group_data(group)
         if not groupdata:
             path = os.path.join(os.path.dirname(__file__),
                                 'templates', 'erroratbsuir.html')
             self.response.out.write(template.render(path,
                                     {'group': group,
                                     "default_group": get_preferred_group_params(self.request)
                                     }))
             return
         study_week = groupdata[DICTDATA_SCHEDULE_KEY_NAME]
         if study_week:
             localised_date = pytz.utc.localize(groupdata["date"]).astimezone(minsk_tz)
             now_date = (datetime.datetime.now(tz = pytz.utc)).astimezone(minsk_tz)
             study_week = study_week.filter(subgroup, week_num)
             path = os.path.join(os.path.dirname(__file__),
                                 'templates', 'schedule.html')
             self.response.out.write(template.render(path, {"week": study_week,
                                     "group": group, "subgroup": subgroup,
                                     "selweek": week_num,
                                     "weeknumbers": range(1, 5),
                                     "default_group": get_preferred_group_params(self.request),
             "fetcheddate": localised_date,
             "current_week" : bsuirparser.get_week_num(now_date.year, now_date.month, now_date.day)
                                     })
                                     )
         else:
             self.response.headers['Content-Type'] = 'text/plain'
             self.response.out.write(u"Что-то пошло не так")
             logging.debug(u"Ошибка при разборе расписания")
Пример #3
0
 def get_ajax_context(self, date=None, group=None, subgroup=None):
     group = self.request.POST.get("group", group)
     subgroup = bsuirparser.subgroup2int(self.request.POST.get("subgroup",subgroup))
     date_str=self.request.POST.get("date",date)
     try:
         if date_str == "today":
             date = (datetime.datetime.now(tz = pytz.utc)).astimezone(minsk_tz)
         elif date_str == "tomorrow":
             date = (datetime.datetime.now(tz = pytz.utc) + datetime.timedelta(days=1)).astimezone(minsk_tz)
         else:
             date = minsk_tz.localize(datetime.datetime.strptime(date_str, "%d-%m-%Y"))
     except Exception:
         # Wrong date
         return
     if not group:
         return
     else:
         group_data = get_group_data(group)
         if not group_data:
             return
             #error bsuir parser
     studyweek = group_data[DICTDATA_SCHEDULE_KEY_NAME]
     weeknum = bsuirparser.get_week_num(date.year, date.month, date.day)
     studyweek = studyweek.filter(subgroup, weeknum)
     if not weeknum:
         return
         #incorrectdate
     if studyweek:
         studyday = studyweek.get_day(date.weekday())
         return {
             "default_group": get_preferred_group_params(self.request),
             "studyday": studyday,
             "target_date": date,
             "weeknum": weeknum,
             "group": group,
             "subgroup": subgroup,
             "fetcheddate": pytz.utc.localize(group_data[DICTDATA_DATE_KEY_NAME]).astimezone(minsk_tz)
             }
Пример #4
0
 def get_ajax_context(self, date=None, group=None, subgroup=None):
     group = self.request.POST.get("group", group)
     subgroup = bsuirparser.subgroup2int(self.request.POST.get("subgroup", subgroup))
     date_str = self.request.POST.get("date", date)
     try:
         if date_str == "today":
             date = (datetime.datetime.now(tz=pytz.utc)).astimezone(minsk_tz)
         elif date_str == "tomorrow":
             date = (datetime.datetime.now(tz=pytz.utc) + datetime.timedelta(days=1)).astimezone(minsk_tz)
         else:
             date = minsk_tz.localize(datetime.datetime.strptime(date_str, "%d-%m-%Y"))
     except Exception:
         # Wrong date
         return
     if not group:
         return
     else:
         group_data = get_group_data(group)
         if not group_data:
             return
             # error bsuir parser
     studyweek = group_data[DICTDATA_SCHEDULE_KEY_NAME]
     weeknum = bsuirparser.get_week_num(date.year, date.month, date.day)
     studyweek = studyweek.filter(subgroup, weeknum)
     if not weeknum:
         return
         # incorrectdate
     if studyweek:
         studyday = studyweek.get_day(date.weekday())
         return {
             "default_group": get_preferred_group_params(self.request),
             "studyday": studyday,
             "target_date": date,
             "weeknum": weeknum,
             "group": group,
             "subgroup": subgroup,
             "fetcheddate": pytz.utc.localize(group_data[DICTDATA_DATE_KEY_NAME]).astimezone(minsk_tz),
         }