Пример #1
0
 def post(self):
     content = self.request.post("content")
     key = self.request.post("key")
     if content and key:
         comment = Comment(content=content, timeslot=Timeslot.get(key))
         comment.put()
     self.redirect(self.request.path)
Пример #2
0
 def get(self):
     key = self.request.get('key')
     if key:
         timeslot = Timeslot.get(key)
         if timeslot:
             template = engine.jinja_environment.get_template('timetables/timeslot.html')
             template_values = engine.globals
             template_values["timeslot"] = timeslot
             template_values["comments"] = Comment.all().filter('timeslot =', timeslot)
             self.response.out.write(template.render(template_values)) 
             
         else:
             print dir(self.request)
Пример #3
0
def selected_lesson(request, group_title, day_of_week, time, week_type):
    res_dict = {}
    # попытка получить по group_title объект группы
    try:
        group_title = UniversityGroup.objects.get(title_en=group_title.upper())
    except ObjectDoesNotExist:
        group_title = None
        traceback.print_exc()

    # попытка превратить day_of_week в число и получить по этому числу объект дня недели
    try:
        day_of_week = int(day_of_week)
        day_of_week = WeekDay.objects.get(pk=day_of_week)
    except (ValueError, ObjectDoesNotExist):
        day_of_week = None
        traceback.print_exc()

    # попытка превратить time в число и получить по этому числу объект времени урока
    try:
        time = int(time)
        time = LessonTime.objects.get(number=time)
    except (ValueError, ObjectDoesNotExist):
        time = None
        traceback.print_exc()

    if week_type not in ('top', 'bottom', 'both'):
        week_type = None

    if group_title and day_of_week and time and week_type:
        try:
            res_lesson = Lesson.objects.filter(group=group_title).filter(weekday=day_of_week).filter(time=time).get(
                week=week_type)
            res_dict['lesson'] = res_lesson
        except ObjectDoesNotExist:
            traceback.print_exc()
            raise Http404("Не корректные данные")
        except MultipleObjectsReturned:
            traceback.print_exc()
            raise Http404
    else:
        raise Http404("Не корректные данные")

    if request.user.is_authenticated() and request.method == 'POST':
        subject = request.POST['subject']
        comment = request.POST['comment']
        new_comment = Comment(subject=subject, comment=comment, date_time=datetime.now(), sender=request.user,
                              lesson=res_lesson)
        # if subject and comment:
        new_comment.save()
        return HttpResponseRedirect('')

    teachers_comments = Comment.objects.filter(lesson=res_lesson).filter(
        Q(sender__user_type=1) | Q(sender__user_type=0)).order_by('date_time')
    res_dict['teacher_comments'] = teachers_comments
    students_comments = Comment.objects.filter(lesson=res_lesson).filter(
        Q(sender__user_type=2) | Q(sender__user_type=3)).order_by('date_time')
    res_dict['students_comments'] = students_comments
    # sorted(teachers_comments,reverse=True)
    # sorted(students_comments)
    if request.user.is_authenticated() and request.user.is_staff:
        res_dict['is_staff'] = True
    if request.user.is_authenticated() and not request.user.is_staff:
        res_dict['not_staff'] = True
    res_dict['null_res'] = "уточнить на кафедре"
    return render_to_response('selected_lesson.html', res_dict, context_instance=RequestContext(request))