예제 #1
0
class NotificationTest(TestCase):
    def create_test_user(self, username):
        user = AuroraUser(username=username)
        user.email = '%[email protected].' % username
        user.first_name = 'Firstname_%s' % username
        user.last_name = 'Lastname_%s' % username
        user.nickname = 'Nickname_%s' % username
        user.is_staff = False
        user.is_superuser = False
        password = username
        user.set_password(password)
        user.matriculation_number = username + '2857289'
        user.save()
        return user

    def create_test_users(self, amount):
        self.users = []
        for i in range(amount):
            self.users.append(self.create_test_user("s%s" % i))

    def create_course(self):
        self.course = Course(
            title='test_title',
            short_title='test_short_title',
            description='test_description',
            course_number='test_course_number',
        )
        self.course.save()
        for user in self.users:
            CourseUserRelation(course=self.course, user=user).save()

    def setUp(self):
        self.create_test_users(4)
        self.create_course()

    def test_text(self):
        user = self.users[0]
        text = Notification.truncate_text("test")
        obj, created = Notification.objects.get_or_create(
            user=user,
            course=self.course,
            text=text,
            image_url='test_image_url',
            link='test_link')
        assert obj.text == text
        assert len(obj.text) <= 100

    def test_text_too_long(self):
        user = self.users[0]
        text = Notification.truncate_text("test" * 100)
        obj, created = Notification.objects.get_or_create(
            user=user,
            course=self.course,
            text=text,
            image_url='test_image_url',
            link='test_link')
        assert obj.text == text
        assert len(obj.text) <= 100
        assert text[-3:] == '...'
예제 #2
0
파일: tests.py 프로젝트: ralokt/aurora
 def create_course(self):
     self.course = Course(
         title='test_title',
         short_title='test_short_title',
         description='test_description',
         course_number='test_course_number',
     )
     self.course.save()
     for user in self.users:
         CourseUserRelation(course=self.course, user=user).save()
예제 #3
0
파일: views.py 프로젝트: daelin/aurora
def livecast(request, lecture_id=None, course_short_title=None):
    course = Course.get_or_raise_404(course_short_title)
    lectures = _get_contentbar_data(course)
    lecture = get_object_or_404(Lecture,
                                id=lecture_id,
                                course=course,
                                active=True)
    if not _livecast_now(lecture):
        url = reverse('Slides:studio_lecture',
                      args=(course_short_title, lecture_id))
        return redirect(url)

    update_slides_url = reverse('Slides:livecast_update_slide',
                                args=(course_short_title, 0))
    # the last part of the url, i.e. the timestamp, should be set by js so should be removed
    # from the base url js gets for using
    update_slides_url = re.sub('0/$', '', update_slides_url)
    render_dict = {
        'slidecasting_mode': 'livecast',
        'course': course,
        'lectures': lectures,
        'lecture': lecture,
        'last_update': int(time.time()),
        'update_slides_url': update_slides_url
    }
    return render_to_response('livecast.html',
                              render_dict,
                              context_instance=RequestContext(request))
예제 #4
0
파일: views.py 프로젝트: martflu/aurora
def api_new_issue(request, course_short_title):
    """
    API callback to create a new issue.
    """

    course = Course.get_or_raise_404(course_short_title)
    lanes = Lane.objects.all().filter(hidden=False).order_by('order')

    data = json.loads(request.body.decode('utf-8'))
    user = RequestContext(request)['user']

    # You can't create an issue without a title, type or a body.
    if 'title' not in data or 'type' not in data or 'body' not in data:
        return HttpResponseForbidden()

    if len(lanes) == 0:
        return HttpResponseServerError

    issue = Issue(
        author=user,
        course=course,
        lane=lanes[0],
        type=data['type'],
        title=data['title'],
        body=data['body'],
        user_agent=request.META['HTTP_USER_AGENT'],
    )

    issue.save()
    return JsonResponse(issue.get_serializable(request.user.is_staff))
예제 #5
0
파일: views.py 프로젝트: bobschi/aurora
def plagcheck_suspects(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    show_filtered = int(request.GET.get('show_filtered', 0))
    if show_filtered is 1:
        suspect_list = Suspect.objects.all()
    else:
        suspect_list = Suspect.objects.exclude(state=SuspectState.AUTO_FILTERED.value)

    paginator = Paginator(suspect_list, 25)

    page = request.GET.get('page')
    try:
        suspects = paginator.page(page)
    except PageNotAnInteger:
        suspects = paginator.page(1)
    except EmptyPage:
        suspects = paginator.page(paginator.num_pages)

    context = {
        'course': course,
        'suspects': suspects,
        'suspect_states': SuspectState.choices(),
        'show_filtered': show_filtered,
    }

    return render_to_response('evaluation.html', {
            'overview': render_to_string('plagcheck_suspects.html', context, RequestContext(request)),
            'course': course,
        },
        context_instance=RequestContext(request))
예제 #6
0
파일: views.py 프로젝트: daelin/aurora
def home(request, course_short_title=None):

    user = request.user
    course = Course.get_or_raise_404(course_short_title)
    data = get_points(request, user, course)
    data = create_stat_data(course,data)
    data['user_is_top_reviewer'] = False
    data['number_of_extra_reviews'] = user.number_of_extra_reviews(course)
    data['reviews_until_next_extra_point'] = user.number_of_reviews_until_next_extra_point(course)
    data['extra_points_earned_with_reviews'] = user.extra_points_earned_with_reviews(course)
    if user.is_top_reviewer(course):
        # data['number_of_extra_reviews'] = user.number_of_extra_reviews(course)
        # data['reviews_until_next_extra_point'] = user.number_of_reviews_until_next_extra_point(course)
        # data['extra_points_earned_with_reviews'] = user.extra_points_earned_with_reviews(course)
        data['user_is_top_reviewer'] = True
        # Expensive function, therefor only execute if user is top reviewer
        data = get_extra_review_data(user, course, data)

    data['extra_points_earned_with_comments'] = user.extra_points_earned_with_comments(course)
    data['extra_points_earned_by_rating_reviews'] = user.extra_points_earned_by_rating_reviews(course)
    data['total_extra_points_earned'] = user.total_extra_points_earned(course)
    faq_list = Faq.get_faqs(course_short_title)
    context = RequestContext(request, {'newsfeed': data['course'], 'faq_list': faq_list})

    return render_to_response('home.html', data, context)
예제 #7
0
파일: views.py 프로젝트: aljaz/aurora
def plagcheck_suspicions(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    suspicion_list = Suspicion.objects.filter(
        state=SuspicionState.SUSPECTED.value,
        #suspect_doc__submission_time__range=(course.start_date, course.end_date),
        suspect_doc__submission_time__gt=course.start_date,
    )

    count = suspicion_list.count()

    context = {
        'course': course,
        'suspicions': suspicion_list,
        'suspicion_states': SuspicionState.choices(),
        'suspicions_count': count,
    }

    request.session['selection'] = 'plagcheck_suspicions'
    request.session['count'] = count

    return render_to_response('evaluation.html', {
            'overview': render_to_string('plagcheck_suspicions.html', context, RequestContext(request)),
            'course': course,
            'stabilosiert_plagcheck_suspicions': 'stabilosiert',
            'count_plagcheck_suspicions': count,
            'selection': request.session['selection'],
        },
        context_instance=RequestContext(request))
예제 #8
0
파일: views.py 프로젝트: flozzone/aurora
def back(request, course_short_title=None):
    selection = request.session.get('selection', 'error')
    course = Course.get_or_raise_404(short_title=course_short_title)

    if selection == "search":
        return HttpResponse()
    if selection == "missing_reviews":
        elaborations = Elaboration.get_missing_reviews(course)
    if selection == "top_level_tasks":
        elaborations = Elaboration.get_top_level_tasks(course)
    if selection == "non_adequate_work":
        elaborations = Elaboration.get_non_adequate_work(course)
    if selection == "complaints":
        elaborations = Elaboration.get_complaints(course)
    if selection == "awesome":
        elaborations = Elaboration.get_awesome(course)
    if selection == "evaluated_non_adequate_work":
        elaborations = Elaboration.get_evaluated_non_adequate_work(course)

    # update overview
    if type(elaborations) == list:
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    else:
        elaborations = elaborations.order_by('submission_time')
    request.session['elaborations'] = serializers.serialize(
        'json', elaborations)

    return evaluation(request, course_short_title)
예제 #9
0
def submit_elaboration(request, course_short_title):
   if not 'challenge_id' in request.POST:
       return HttpResponse("missing parameter challenge_id", status=400)
   challenge = Challenge.objects.get(id=request.POST['challenge_id'])
   if not challenge.currently_active:
       return HttpResponse("challenge is currently not active", status=400)

   user = request.user
   course = Course.get_or_raise_404(short_title=course_short_title)
   if not challenge.is_enabled_for_user(user):
       return HttpResponse("challenge not enabled for user", status=400)
   if challenge.is_final_challenge() and challenge.is_in_lock_period(user, course):
       return HttpResponse("user is currently locked", status=400)
   elaboration, created = Elaboration.objects.get_or_create(challenge=challenge, user=user)

   if elaboration.is_submitted():
       return HttpResponse("elaboration already submitted", status=400)

   elaboration.elaboration_text = request.POST['elaboration_text'] # sanitze here
   elaboration.revised_elaboration_text = elaboration.elaboration_text

   if elaboration.elaboration_text or UploadFile.objects.filter(elaboration=elaboration).exists():
       elaboration.submission_time = datetime.now()
       elaboration.save()

       plagcheck_elaboration(elaboration)

       return HttpResponse()
예제 #10
0
파일: models.py 프로젝트: Mr-Phoebe/BOJ-V2
    def addProblem(cls, uid, prob_priv, prob_title, prob_time, 
            prob_memory, prob_codelength, prob_desc, is_spj,
            data_count, course_id, case_info):
        try:
            p = Problem()
            if (cls.isLegalTitle(prob_title)):
                p.prob_title = prob_title
            else:
                raise Exception(cls.TITLE_ERRMSG)
            if (cls._isLegalDesc(prob_desc)):
                p.prob_desc = prob_desc
            else:
                raise Exception(cls.DESC_ERRMSG)

            p.prob_priv = prob_priv
            p.prob_title = prob_title
            p.prob_time = prob_time
            p.prob_memory = prob_memory
            p.prob_codelength = prob_codelength
            p.is_spj = is_spj
            p.author = User.getById(uid)
            p.data_count = data_count
            p.course = Course.getById(course_id)
            p.case_info = case_info

            p.save()
            return p
        except Exception as e:
            raise e
예제 #11
0
파일: models.py 프로젝트: Mr-Phoebe/BOJ-V2
    def updateProblem(self, uid, prob_priv, prob_title, prob_time,
            prob_memory, prob_codelength, prob_desc, is_spj,
            data_count, course_id, case_info):
        try:
            if (Problem.isLegalTitle(prob_title)):
                self.prob_title = prob_title
            else:
                raise Exception(Problem.TITLE_ERRMSG)
            if (Problem._isLegalDesc(prob_desc)):
                self.prob_desc = prob_desc
            else:
                raise Exception(Problem.DESC_ERRMSG)

            self.prob_priv = prob_priv
            self.prob_title = prob_title
            self.prob_time = prob_time
            self.prob_memory = prob_memory
            self.prob_codelength = prob_codelength
            self.is_spj = is_spj
           #self.author = User.getById(uid) #will change the author...
            self.data_count = data_count
            self.course = Course.getById(course_id)
            self.case_info = case_info

            self.save()
            return True
        except Exception as e:
            raise e
예제 #12
0
파일: views.py 프로젝트: flozzone/aurora
def missing_reviews(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    elaborations = Elaboration.get_missing_reviews(course)

    # sort elaborations by submission time
    if type(elaborations) == list:
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    else:
        elaborations = elaborations.order_by("submission_time")

    # store selected elaborations in session
    request.session["elaborations"] = serializers.serialize("json", elaborations)
    request.session["selection"] = "missing_reviews"
    request.session["count"] = len(elaborations)

    return render_to_response(
        "evaluation.html",
        {
            "overview": render_to_string(
                "overview.html", {"elaborations": elaborations, "course": course}, RequestContext(request)
            ),
            "count_missing_reviews": request.session.get("count", "0"),
            "stabilosiert_missing_reviews": "stabilosiert",
            "selection": request.session["selection"],
            "course": course,
        },
        context_instance=RequestContext(request),
    )
예제 #13
0
파일: views.py 프로젝트: flozzone/aurora
def questions(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    challenges = Challenge.get_questions(course)

    # store selected challenges in session
    request.session["challenges"] = serializers.serialize("json", challenges)

    # store selected elaborations in session
    elaborations = []
    request.session["elaborations"] = elaborations
    request.session["selection"] = "questions"
    request.session["count"] = len(challenges)

    return render_to_response(
        "evaluation.html",
        {
            "challenges": challenges,
            "overview": render_to_string(
                "questions.html", {"challenges": challenges, "course": course}, RequestContext(request)
            ),
            "count_questions": request.session.get("count", "0"),
            "stabilosiert_questions": "stabilosiert",
            "selection": request.session["selection"],
            "course": course,
        },
        context_instance=RequestContext(request),
    )
예제 #14
0
파일: views.py 프로젝트: flozzone/aurora
def complaints(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    elaborations = list(Elaboration.get_complaints(course))

    # sort elaborations by last comment time
    elaborations.sort(key=lambda elaboration: elaboration.get_last_post_date())

    # store selected elaborations in session
    request.session["elaborations"] = serializers.serialize("json", elaborations)
    request.session["selection"] = "complaints"
    request.session["count"] = len(elaborations)

    return render_to_response(
        "evaluation.html",
        {
            "overview": render_to_string(
                "overview.html",
                {"elaborations": elaborations, "course": course, "complaints": "true"},
                RequestContext(request),
            ),
            "count_complaints": request.session.get("count", "0"),
            "stabilosiert_complaints": "stabilosiert",
            "selection": request.session["selection"],
            "course": course,
        },
        context_instance=RequestContext(request),
    )
예제 #15
0
def challenges(request, course_short_title=None):
    data = {}

    course = Course.get_or_raise_404(short_title=course_short_title)
    data['course'] = course

    user = RequestContext(request)['user']
    course_stacks = Stack.objects.all().filter(course=course)
    data['course_stacks'] = []
    for stack in course_stacks:
        submitted = stack.get_final_challenge().submitted_by_user(user)
        submission_time = None
        if submitted:
            print(submitted)
            submission_time = stack.get_final_challenge().get_elaboration(
                user).submission_time
        data['course_stacks'].append({
            'stack': stack,
            'submitted': submitted,
            'submission_time': submission_time,
            'status': stack.get_status_text(user),
            'points': stack.get_points_earned(user)
        })
    return render_to_response('challenges.html',
                              data,
                              context_instance=RequestContext(request))
예제 #16
0
파일: views.py 프로젝트: martflu/aurora
def final_evaluation_new(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    elaborations = Elaboration.get_final_evaluation_top_level_tasks(course)

    # sort elaborations by submission time
    if type(elaborations) == list:
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    else:
        elaborations = elaborations.order_by('submission_time')

    # store selected elaborations in session
    request.session['elaborations'] = serializers.serialize(
        'json', elaborations)
    request.session['selection'] = 'final_evaluation_new'
    request.session['final_evaluation_count'] = len(elaborations)

    return render_to_response('evaluation.html',
                              {'overview': render_to_string('overview_new.html', {'elaborations': elaborations, 'course': course},
                                                            RequestContext(request)),
                               'count_final_evaluation_new': request.session.get('final_evaluation_count', '0'),
                               'stabilosiert_final_evaluation_new': 'stabilosiert',
                               'selection': request.session['selection'],
                               'course': course
                               },
                              context_instance=RequestContext(request))
예제 #17
0
파일: views.py 프로젝트: bountin/aurora
def create_context_challenge(request, course_short_title):
    data = {}
    course = Course.get_or_raise_404(short_title=course_short_title)
    data['course'] = course

    if 'id' in request.GET:
        try:
            challenge = Challenge.objects.get(pk=request.GET.get('id'))
        except:
            raise Http404
        user = RequestContext(request)['user']
        data['challenge'] = challenge
        data['review_questions'] = []
        for review_question in ReviewQuestion.objects.filter(challenge=challenge, visible_to_author=True).order_by("order"):
            data['review_questions'].append(review_question.text)

        # Create the elaboration to be able to upload files immediately
        Elaboration.objects.get_or_create(challenge=challenge, user=user)

        if Elaboration.objects.filter(challenge=challenge, user=user).exists():
            elaboration = Elaboration.objects.get(challenge=challenge, user=user)
            data['elaboration'] = elaboration
            data['accepted'] = elaboration.is_started()
            data['success'] = elaboration.get_success_reviews()
            data['nothing'] = elaboration.get_nothing_reviews()
            data['fail'] = elaboration.get_fail_reviews()
            if Evaluation.objects.filter(submission=elaboration).exists():
                data['evaluation'] = Evaluation.objects.filter(submission=elaboration)[0]

        if challenge.is_final_challenge():
            data['blocked'] = not challenge.is_enabled_for_user(user)
            if challenge.is_in_lock_period(RequestContext(request)['user'], course):
                data['lock'] = challenge.is_in_lock_period(RequestContext(request)['user'], course)
    return data
예제 #18
0
파일: views.py 프로젝트: bobschi/aurora
def submit_elaboration(request, course_short_title):
   if not 'challenge_id' in request.POST:
       raise Http404
   challenge = Challenge.objects.get(id=request.POST['challenge_id'])
   if not challenge.currently_active:
       raise Http404

   user = RequestContext(request)['user']
   course = Course.get_or_raise_404(short_title=course_short_title)
   if not challenge.is_enabled_for_user(user):
       raise Http404
   if challenge.is_final_challenge() and challenge.is_in_lock_period(user, course):
       raise Http404
   elaboration, created = Elaboration.objects.get_or_create(challenge=challenge, user=user)

   if elaboration.is_submitted():
       raise Http404

   elaboration.elaboration_text = request.POST['elaboration_text'] # sanitze here
   elaboration.revised_elaboration_text = elaboration.elaboration_text

   if elaboration.elaboration_text or UploadFile.objects.filter(elaboration=elaboration).exists():
       elaboration.submission_time = datetime.now()
       elaboration.save()
       return HttpResponse()
예제 #19
0
def awesome(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    selected_challenge = request.session.get('selected_challenge', 'task...')
    if selected_challenge != 'task...':
        selected_challenge = selected_challenge[:(selected_challenge.rindex('(') - 1)]
        challenge = Challenge.objects.get(title=selected_challenge, course=course)
        elaborations = Elaboration.get_awesome_challenge(course, challenge)
    else:
        elaborations = Elaboration.get_awesome(course)

    # sort elaborations by submission time
    if type(elaborations) == list:
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    else:
        elaborations = elaborations.order_by('submission_time')

    # store selected elaborations in session
    request.session['elaborations'] = serializers.serialize('json', elaborations)
    request.session['selection'] = 'awesome'
    request.session['selected_challenge'] = 'task...'
    request.session['count'] = len(elaborations)

    return render_to_response('evaluation.html',
                              {'overview': render_to_string('overview.html', {'elaborations': elaborations, 'course': course},
                                                            RequestContext(request)),
                               'count_awesome': request.session.get('count', '0'),
                               'selected_task': selected_challenge,
                               'stabilosiert_awesome': 'stabilosiert',
                               'selection': request.session['selection'],
                               'course': course
                              },
                              context_instance=RequestContext(request))
예제 #20
0
파일: views.py 프로젝트: bobschi/aurora
def challenges(request, course_short_title=None):
    data = {}

    course = Course.get_or_raise_404(short_title=course_short_title)
    data['course'] = course

    user = RequestContext(request)['user']
    course_stacks = Stack.objects.all().filter(course=course)
    # raise Exception(course_stacks)
    data['course_stacks'] = []
    for stack in course_stacks:
        submitted = stack.get_final_challenge().submitted_by_user(user)
        submission_time = None
        currently_active = stack.currently_active()
        if submitted:
            print(submitted)
            submission_time = stack.get_final_challenge().get_elaboration(user).submission_time
        data['course_stacks'].append({
            'stack': stack,
            'submitted': submitted,
            'submission_time': submission_time,
            'currently_active': currently_active,
            'status': stack.get_status_text(user),
            'points': stack.get_points_earned(user)
        })
    return render_to_response('challenges.html', data, context_instance=RequestContext(request))
예제 #21
0
def sort(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    elaborations = []
    for serialized_elaboration in serializers.deserialize('json', request.session.get('elaborations', {})):
        elaborations.append(serialized_elaboration.object)

    if request.GET.get('data', '') == "date_asc":
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    if request.GET.get('data', '') == "date_desc":
        elaborations.sort(key=lambda elaboration: elaboration.submission_time, reverse=True)
    if request.GET.get('data', '') == "elab_asc":
        elaborations.sort(key=lambda elaboration: elaboration.challenge.title)
    if request.GET.get('data', '') == "elab_desc":
        elaborations.sort(key=lambda elaboration: elaboration.challenge.title, reverse=True)
    if request.GET.get('data', '') == "post_asc":
        elaborations.sort(key=lambda elaboration: elaboration.get_last_post_date())
    if request.GET.get('data', '') == "post_desc":
        elaborations.sort(key=lambda elaboration: elaboration.get_last_post_date(), reverse=True)

    # store selected elaborations in session
    request.session['elaborations'] = serializers.serialize('json', elaborations)
    request.session['count'] = len(elaborations)

    data = {
        'overview_html': render_to_string('overview.html', {'elaborations': elaborations, 'course': course}, RequestContext(request)),
        'menu_html': render_to_string('menu.html', {
            'count_' + request.session.get('selection', ''): request.session.get('count', '0'),
            'stabilosiert_' + request.session.get('selection', ''): 'stabilosiert', 'course': course,
        }, RequestContext(request)),
        'selection': request.session['selection']
    }

    return HttpResponse(json.dumps(data))
예제 #22
0
파일: views.py 프로젝트: bobschi/aurora
def back(request, course_short_title=None):
    selection = request.session.get('selection', 'error')
    course = Course.get_or_raise_404(short_title=course_short_title)

    if selection == "search":
        return HttpResponse()
    if selection == "missing_reviews":
        elaborations = Elaboration.get_missing_reviews(course)
    if selection == "top_level_tasks":
        elaborations = Elaboration.get_top_level_tasks(course)
    if selection == "non_adequate_work":
        elaborations = Elaboration.get_non_adequate_work(course)
    if selection == "complaints":
        elaborations = Elaboration.get_complaints(course)
    if selection == "awesome":
        elaborations = Elaboration.get_awesome(course)
    if selection == "evaluated_non_adequate_work":
        elaborations = Elaboration.get_evaluated_non_adequate_work(course)

    # update overview
    if type(elaborations) == list:
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    else:
        elaborations = elaborations.order_by('submission_time')
    request.session['elaborations'] = serializers.serialize('json', elaborations)

    return evaluation(request, course_short_title)
예제 #23
0
def plagcheck_suspicions(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    suspicion_list = Suspicion.suspicion_list_by_request(request, course)

    count = suspicion_list.count()

    context = {
        'course': course,
        'suspicions': suspicion_list,
        'suspicion_states': SuspicionState.choices(),
        'current_suspicion_state_filter': int(request.GET.get('state', -1)),
        'suspicions_count': count,
        'open_new_window': False,
        'enable_state_filter': True,
    }

    request.session['selection'] = 'plagcheck_suspicions'
    request.session['count'] = count

    return render_to_response('evaluation.html', {
            'overview': render_to_string('plagcheck_suspicions.html', context, RequestContext(request)),
            'course': course,
            'stabilosiert_plagcheck_suspicions': 'stabilosiert',
            'count_plagcheck_suspicions': count,
            'selection': request.session['selection'],
        },
        context_instance=RequestContext(request))
예제 #24
0
파일: views.py 프로젝트: bobschi/aurora
def plagcheck_compare(request, course_short_title=None, suspect_id=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    suspect = Suspect.objects.get(pk=suspect_id)

    docA = Elaboration.objects.get(pk=suspect.doc_id)
    docB = Elaboration.objects.get(pk=suspect.similar_to_id)

    table = difflib.HtmlDiff(wrapcolumn=70).make_table(docA.elaboration_text.splitlines(),
                                                        docB.elaboration_text.splitlines())

    show_filtered = int(request.GET.get('show_filtered', 0))
    (prev_suspect_id, next_suspect_id) = suspect.get_prev_next(show_filtered)

    context = {
        'course': course,
        'diff_table': table,
        'suspect': suspect,
        'suspect_states': SuspectState.states(),
        'next_suspect_id': next_suspect_id,
        'prev_suspect_id': prev_suspect_id,
    }

    return render_to_response('evaluation.html', {
            'overview': render_to_string('plagcheck_compare.html', context, RequestContext(request)),
            'course': course
        },
        context_instance=RequestContext(request))
예제 #25
0
def plagcheck_compare(request, course_short_title=None, suspicion_id=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    suspicion = Suspicion.objects.get(pk=suspicion_id)

    (prev_suspicion_id, next_suspicion_id) = suspicion.get_prev_next(
        state=SuspicionState.SUSPECTED.value,
        #suspect_doc__submission_time__range=(course.start_date, course.end_date),
        suspect_doc__submission_time__gt=course.start_date,
    )

    context = {
        'course': course,
        'suspicion': suspicion,
        'suspicion_states': SuspicionState.states(),
        'suspicion_states_class': SuspicionState.__members__,
        'next_suspicion_id': next_suspicion_id,
        'prev_suspicion_id': prev_suspicion_id,
        'similar_has_elaboration': suspicion.similar_doc.was_submitted_during(course),
        'suspect_has_elaboration': suspicion.suspect_doc.was_submitted_during(course)
    }

    # number of suspicious documents
    suspicions_count = Suspicion.objects.filter(state=SuspicionState.SUSPECTED.value).count()

    return render_to_response('evaluation.html', {
            'detail_html': render_to_string('plagcheck_compare.html', context, RequestContext(request)),
            'course': course,
            'stabilosiert_plagcheck_suspicions': 'stabilosiert',
            'count_plagcheck_suspicions': suspicions_count,
        },
        context_instance=RequestContext(request))
예제 #26
0
파일: views.py 프로젝트: martflu/aurora
def index(request, course_short_title):
    """
    index renders a simple html page, adds the react frontend code and some
    initial data, so that users don't have to make additional request to see
    the issues.
    """

    # Pass some values directly as js variables, so that the client doesn't
    # has to make additional requests.
    course = Course.get_or_raise_404(course_short_title)

    lanes = None
    if request.user.is_staff:
        lanes = Lane.objects.all().order_by('order')
    else:
        # Only staff is allowed to see hidden lanes.
        lanes = Lane.objects.filter(hidden=False).order_by('order')

    if len(lanes) == 0:
        return render(request, 'Feedback/empty.html', {'course': course})

    # Separately get the issues from the last lane and all the others, since
    # the last lane is the archive lane, and we'll only get issues from the
    # last two weeks and show less information for them.
    last_lane = lanes[len(lanes) - 1]
    issues = Issue.objects.exclude(lane=last_lane)

    start_date = datetime.now() - timedelta(days=14)
    archived = Issue.objects.filter(lane=last_lane) \
        .filter(post_date__range=(start_date, datetime.now()))

    issues = chain(issues, archived)

    lanes = list(map(lambda lane: lane.serializable, lanes))

    issue_data = []
    for issue in issues:
        # Filter out any security issues, if the current user is not the owner
        # or an admin.
        if issue.type != 'security' or issue.author == request.user \
                or request.user.is_staff:
            data = issue.get_serializable(request.user.is_staff)
            issue_data.append(data)

    data = {
        'lanes': lanes,
        'issues': issue_data,
        'current_user': {
            'is_staff': request.user.is_staff,
            'id': request.user.id,
        }
    }

    return render(
        request, 'Feedback/index.html',
        {
            'course': course,
            'data': json.dumps(data)
        }
    )
예제 #27
0
파일: views.py 프로젝트: flozzone/aurora
def top_level_tasks(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    elaborations = Elaboration.get_top_level_tasks(course)

    # sort elaborations by submission time
    if type(elaborations) == list:
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    else:
        elaborations = elaborations.order_by('submission_time')

    # store selected elaborations in session
    request.session['elaborations'] = serializers.serialize(
        'json', elaborations)
    request.session['selection'] = 'top_level_tasks'
    request.session['count'] = len(elaborations)

    return render_to_response('evaluation.html', {
        'overview':
        render_to_string('overview.html', {
            'elaborations': elaborations,
            'course': course
        }, RequestContext(request)),
        'count_top_level_tasks':
        request.session.get('count', '0'),
        'stabilosiert_top_level_tasks':
        'stabilosiert',
        'selection':
        request.session['selection'],
        'course':
        course
    },
                              context_instance=RequestContext(request))
예제 #28
0
파일: views.py 프로젝트: martflu/aurora
def challenges(request, course_short_title=None):
    data = {}

    course = Course.get_or_raise_404(short_title=course_short_title)
    data['course'] = course
    user = AuroraAuthenticationBackend.get_user(AuroraAuthenticationBackend(), request.user.id)
    data['user_enlisted_and_active'] = user.enlisted_and_active_for_course(course)

    course_stacks = Stack.objects.all().filter(course=course).order_by("chapter")
    # raise Exception(course_stacks)
    data['course_stacks'] = []
    for stack in course_stacks:
        submitted = stack.get_final_challenge().submitted_by_user(user)
        submission_time = None
        currently_active = stack.currently_active()
        if submitted:
            submission_time = stack.get_final_challenge().get_elaboration(user).submission_time
        data['course_stacks'].append({
            'stack': stack,
            'user_can_enter_final_challenge': user.can_enter_final_challenge(stack),
            'submitted': submitted,
            'submission_time': submission_time,
            'currently_active': currently_active,
            'status': stack.get_status_text(user),
            'points': stack.get_points_earned(user),
            'possible': stack.get_points_available(),
            'is_started': stack.is_started(user),
        })
    return render_to_response('challenges.html', data, context_instance=RequestContext(request))
예제 #29
0
파일: views.py 프로젝트: flozzone/aurora
def complaints(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    elaborations = list(Elaboration.get_complaints(course))

    # sort elaborations by last comment time
    elaborations.sort(key=lambda elaboration: elaboration.get_last_post_date())

    # store selected elaborations in session
    request.session['elaborations'] = serializers.serialize(
        'json', elaborations)
    request.session['selection'] = 'complaints'
    request.session['count'] = len(elaborations)

    return render_to_response('evaluation.html', {
        'overview':
        render_to_string('overview.html', {
            'elaborations': elaborations,
            'course': course,
            'complaints': 'true'
        }, RequestContext(request)),
        'count_complaints':
        request.session.get('count', '0'),
        'stabilosiert_complaints':
        'stabilosiert',
        'selection':
        request.session['selection'],
        'course':
        course
    },
                              context_instance=RequestContext(request))
예제 #30
0
def livecast_new_slide(request, course_short_title=None):
    if not request.method == 'POST' or not request.POST['secret'] == SLIDE_SECRET:
        return HttpResponse('must post')

    try:
        now = datetime.datetime.now()
        course = Course.get_or_raise_404(course_short_title)
        if 'lecture_id' in request.POST:
            lecture = Lecture.objects.get(course=course, active=True, id=request.POST['lecture_id'])
            tags = ''
        else:
            if _livecast_now(course):
                lecture = Lecture.objects.get(start__lte=now, end__gte=now, course=course, active=True)
                tags = ""
            else:
                lecture = Lecture.objects.filter(end__gte=now, course=course, active=True).order_by('start')[0]
                tags = ".preparation"

        if 'pub_date' in request.POST:
            pub_date = datetime.datetime.fromtimestamp(int(request.POST['pub_date']))
        else:
            pub_date = now

        slide = Slide(title=request.POST['title'], pub_date=pub_date, filename=request.POST['filename'],
                      lecture=lecture, tags=tags)
        slide.save()
        return HttpResponse(str(slide.id))
    except ValueError:
        return HttpResponse('time error')
    except (Course.DoesNotExist, Course.MultipleObjectsReturned):
        return HttpResponse('course error.')
    except (Lecture.DoesNotExist, Lecture.MultipleObjectsReturned, IndexError):
        return HttpResponse('lecture error.')
예제 #31
0
파일: views.py 프로젝트: flozzone/aurora
def questions(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    challenges = Challenge.get_questions(course)

    # store selected challenges in session
    request.session['challenges'] = serializers.serialize('json', challenges)

    # store selected elaborations in session
    elaborations = []
    request.session['elaborations'] = elaborations
    request.session['selection'] = 'questions'
    request.session['count'] = len(challenges)

    return render_to_response('evaluation.html', {
        'challenges':
        challenges,
        'overview':
        render_to_string('questions.html', {
            'challenges': challenges,
            'course': course
        }, RequestContext(request)),
        'count_questions':
        request.session.get('count', '0'),
        'stabilosiert_questions':
        'stabilosiert',
        'selection':
        request.session['selection'],
        'course':
        course
    },
                              context_instance=RequestContext(request))
예제 #32
0
파일: views.py 프로젝트: martflu/aurora
def similarities(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    elaboration_id = request.session.get('elaboration_id', '')

    doc = Document.get_doc_from_elaboration_id(elaboration_id)
    not_checked = False
    if doc:
        if Result.objects.filter(doc_id=doc.id).count() == 0:
            not_checked = True
    else:
        not_checked = True

    suspicion_list = Suspicion.suspicion_list_by_request(request, course)\
        .filter(suspect_doc__elaboration_id=elaboration_id)

    count = suspicion_list.count()

    context = {
        'not_checked': not_checked,
        'course': course,
        'suspicions': suspicion_list,
        'suspicion_states': SuspicionState.choices(),
        'current_suspicion_state_filter': int(request.GET.get('state', -1)),
        'suspicions_count': count,
        'enable_state_filter': False,
        'open_new_window': True,
    }

    return render_to_response('plagcheck_suspicions.html', context, RequestContext(request))
예제 #33
0
파일: views.py 프로젝트: martflu/aurora
def create_context_myreview(request, course_short_title):
        data = {}

        if 'id' not in request.GET:
            return data

        user = AuroraAuthenticationBackend.get_user(AuroraAuthenticationBackend(), request.user.id)

        data['challenge'] = Challenge.objects.get(pk= request.GET.get('id'))
        challenge = Challenge.objects.get(pk= request.GET.get('id'))

        data['user_reviews'] = []
        for review in challenge.get_reviews_written_by_user(user):
           review_data = {}
           review_data['review_id'] = review.id
           review_data['review'] = review
           review_data['extra_review_question_answer'] = review.extra_review_question_answer
           review_data['appraisal'] = review.get_appraisal_display()
           evaluation = ReviewEvaluation.objects.filter(review=review)
           review_data['evaluation'] = ''
           if evaluation:
                review_data['evaluation'] = evaluation[0].appraisal
           data['user_reviews'].append(review_data)


        data['course'] = Course.get_or_raise_404(course_short_title)
        return data
예제 #34
0
파일: views.py 프로젝트: ralokt/aurora
def refresh(request, course_short_title=None):
    user = request.user
    course = Course.get_or_raise_404(course_short_title)
    notifications = Notification.objects.filter(user=user,
                                                course=course,
                                                read=False)
    return HttpResponse(len(notifications))
예제 #35
0
def get_sibling_sections(request, course_id):
    """POST /api/courses/:course:id/sections"""
    category = request.POST['category']
    term = request.POST['term']
    type = request.POST['type']
    section_id = request.POST['section_id']

    ret = Course.get_course_by_id(course_id)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    o_course = ret.body

    ret = Section.get_sections_by_course(o_course)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    sections = ret.body

    section_list = []
    for section in sections:
        if section.category == category and section.term == term and section.type == type and section.id != section_id:
            section_list.append(dict(
                sibling=section.to_dict(),
                self_id=section_id,
            ))
    return response(body=section_list)
예제 #36
0
def change_color_by_category(request):
    course_id = request.POST['course_id']
    category = request.POST['category']
    color = request.POST['color']
    bg_color = request.POST['bg_color']
    term = request.POST['term']

    ret = get_user_from_session(request)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    o_user = ret.body

    ret = Course.get_course_by_id(course_id)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    o_course = ret.body

    ret = SelectSection.get_selected_section_by_user(o_user)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    select_sections = ret.body

    select_section_list = []
    for select_section in select_sections:
        if select_section.section.course == o_course and select_section.section.category == category and select_section.section.term == term:
            select_section.bgcolor = bg_color
            select_section.color = color
            select_section.save()
            select_section_list.append(select_section.to_dict())

    return response(body=select_section_list)
예제 #37
0
def delete_section_by_category(request):
    """DELETE /api/selectsections"""
    course_id = request.POST['course_id']
    category = request.POST['category']
    term = request.POST['term']

    ret = get_user_from_session(request)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    o_user = ret.body

    ret = Course.get_course_by_id(course_id)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    o_course = ret.body

    ret = SelectSection.get_selected_section_by_user(o_user)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    select_sections = ret.body

    for select_section in select_sections:
        if select_section.section.course == o_course and select_section.section.category == category and select_section.section.term == term:
            select_section.delete()
    return response()
예제 #38
0
def search(request, course_short_title=None):
    """
    Searches all SlideStacks and Slides for the given text
    :param request:
    :return: a view of all SlideStacks, which contain the search text
    in a variable, or has a Slide assigned that fits the search criteria.
    """

    query = request.GET.get("q")
    if query:

        query_words = query.split(' ')

        queryset_ss = SlideStack.objects.filter(
            reduce(lambda x, y: x & y,
                   [Q(title__icontains=word) for word in query_words])
            | reduce(lambda x, y: x & y,
                     [Q(tags__icontains=word) for word in query_words])
            | reduce(lambda x, y: x & y,
                     [Q(categories__icontains=word)
                      for word in query_words])).distinct()

        queryset_slides = Slide.objects.filter(
            reduce(lambda x, y: x & y,
                   [Q(title__icontains=word) for word in query_words])
            | reduce(lambda x, y: x & y,
                     [Q(text_content__icontains=word) for word in query_words])
            | reduce(lambda x, y: x & y,
                     [Q(tags__icontains=word) for word in query_words])
            | reduce(
                lambda x, y: x & y,
                [Q(lecturer_comment__icontains=word)
                 for word in query_words])).distinct()

        complete_set = set(queryset_ss)
        for slide in queryset_slides:
            complete_set.add(slide.slide_stack)

        # filter for course
        course_filtered_list = []
        for item in complete_set:
            if item.course.short_title == course_short_title:
                course_filtered_list.append(item)

        # check date
        filter_future_dates(course_filtered_list)

        complete_list = sort_list_by_id(course_filtered_list)

        title = 'nothing found'
        if len(complete_list) != 0:
            title = 'results found:'

    context = {
        "title": title,
        "found_slides": complete_list,
        "course": Course.get_or_raise_404(course_short_title),
    }

    return render(request, "search.html", context)
예제 #39
0
def get_meetings_by_section(request, course_id, section_id):
    """GET /api/courses/:course_id/sections/:section_id/meetings"""
    ret = Course.get_course_by_id(course_id)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    o_course = ret.body

    ret = Section.get_section_by_id(section_id)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    o_section = ret.body

    ret = o_section.belong_to(o_course)
    if ret.error is not Error.OK:
        return error_response(ret.error)

    ret = TimeSlot.get_meetings_by_section(o_section)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    meetings = ret.body

    meeting_list = []
    for meeting in meetings:
        meeting_list.append(meeting.to_dict())
    return response(body=meeting_list)
예제 #40
0
def login(request, course_short_title=None):

    if 'next_url' in request.session and request.session[
            'next_url'] is not None:
        next_url = request.session['next_url']
    else:
        next_url = reverse('home', args=(course_short_title, ))

    sso_uri = settings.SSO_URI.replace("%%NEXT_URL%%", next_url)

    data = {
        'course': Course.get_or_raise_404(course_short_title),
        'signin_url': reverse('User:signin', args=(course_short_title, )),
        'next': next_url,
        'sso_uri': sso_uri
    }

    if 'error_message' in request.GET:
        data.update({'error_message': request.GET['error_message']})
        return render_to_response('login.html',
                                  data,
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('login.html',
                                  data,
                                  context_instance=RequestContext(request))
예제 #41
0
파일: views.py 프로젝트: martflu/aurora
def notifications(request, course_short_title=None):
    data = {}
    user = request.user
    course = Course.get_or_raise_404(course_short_title)

    # check if rss token was already generated, if not generate it
    FeedToken.get_or_create_token(user)

    if 'id' in request.GET:
        try:
            notification = Notification.objects.get(pk=request.GET['id'])
            if not notification.user == user:
                raise Http404
        except:
            raise Http404

        notification.read = True
        notification.save()

        if 'link' in request.GET:
            return redirect(request.GET['link'])

        return redirect('Notification:list', course_short_title=course_short_title)
    notifications = Notification.objects.filter(user=user, course=course).order_by('-creation_time')
    data['notifications'] = notifications
    data['course'] = course

    try:
        data['feed_token'] = FeedToken.objects.get(user=request.user)
    except FeedToken.DoesNotExist:
        data['feed_token'] = None

    return render_to_response('notifications.html', data, context_instance=RequestContext(request))
예제 #42
0
파일: views.py 프로젝트: daelin/aurora
def create_context_myreview(request, course_short_title):
    data = {}

    if 'id' not in request.GET:
        return data

    user = request.user

    data['challenge'] = Challenge.objects.get(pk=request.GET.get('id'))
    challenge = Challenge.objects.get(pk=request.GET.get('id'))

    data['user_reviews'] = []
    for review in challenge.get_reviews_written_by_user(user):
        review_data = {}
        review_data['review_id'] = review.id
        review_data['review'] = review
        review_data['appraisal'] = review.get_appraisal_display()
        evaluation = ReviewEvaluation.objects.filter(review=review)
        review_data['evaluation'] = ''
        if evaluation:
            review_data['evaluation'] = evaluation[0].appraisal
        data['user_reviews'].append(review_data)

    data['course'] = Course.get_or_raise_404(course_short_title)
    return data
예제 #43
0
def get_course_info(request, course_id):
    """GET /api/courses/:course_id"""
    ret = Course.get_course_by_id(course_id)
    if ret.error is not Error.OK:
        return error_response(ret.error)
    o_course = ret.body
    return response(body=o_course.to_dict())
예제 #44
0
def plagcheck_compare(request, course_short_title=None, suspicion_id=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    suspicion = Suspicion.objects.get(pk=suspicion_id)

    (prev_suspicion_id, next_suspicion_id) = suspicion.get_prev_next(
        state=SuspicionState.SUSPECTED.value,
        #suspect_doc__submission_time__range=(course.start_date, course.end_date),
        suspect_doc__submission_time__gt=course.start_date,
    )

    context = {
        'course': course,
        'suspicion': suspicion,
        'suspicion_states': SuspicionState.states(),
        'suspicion_states_class': SuspicionState.__members__,
        'next_suspicion_id': next_suspicion_id,
        'prev_suspicion_id': prev_suspicion_id,
        'similar_has_elaboration': suspicion.similar_doc.was_submitted_during(course),
        'suspect_has_elaboration': suspicion.suspect_doc.was_submitted_during(course)
    }

    # number of suspicious documents
    suspicions_count = Suspicion.objects.filter(state=SuspicionState.SUSPECTED.value).count()

    return render_to_response('evaluation.html', {
            'detail_html': render_to_string('plagcheck_compare.html', context, RequestContext(request)),
            'course': course,
            'stabilosiert_plagcheck_suspicions': 'stabilosiert',
            'count_plagcheck_suspicions': suspicions_count,
        },
        context_instance=RequestContext(request))
예제 #45
0
파일: views.py 프로젝트: daelin/aurora
def challenges(request, course_short_title=None):
    data = {}

    course = Course.get_or_raise_404(short_title=course_short_title)
    data['course'] = course
    user = request.user
    data['user_enlisted_and_active'] = user.enlisted_and_active_for_course(
        course)

    course_stacks = Stack.objects.all().filter(course=course)
    # raise Exception(course_stacks)
    data['course_stacks'] = []
    for stack in course_stacks:
        submitted = stack.get_final_challenge().submitted_by_user(user)
        submission_time = None
        currently_active = stack.currently_active()
        if submitted:
            print(submitted)
            submission_time = stack.get_final_challenge().get_elaboration(
                user).submission_time
        data['course_stacks'].append({
            'stack': stack,
            'submitted': submitted,
            'submission_time': submission_time,
            'currently_active': currently_active,
            'status': stack.get_status_text(user),
            'points': stack.get_points_earned(user),
            'is_started': stack.is_started(user),
        })
    return render_to_response('challenges.html',
                              data,
                              context_instance=RequestContext(request))
예제 #46
0
def sort(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    elaborations = []
    for serialized_elaboration in serializers.deserialize('json', request.session.get('elaborations', {})):
        elaborations.append(serialized_elaboration.object)

    if request.GET.get('data', '') == "date_asc":
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    if request.GET.get('data', '') == "date_desc":
        elaborations.sort(key=lambda elaboration: elaboration.submission_time, reverse=True)
    if request.GET.get('data', '') == "elab_asc":
        elaborations.sort(key=lambda elaboration: elaboration.challenge.title)
    if request.GET.get('data', '') == "elab_desc":
        elaborations.sort(key=lambda elaboration: elaboration.challenge.title, reverse=True)
    if request.GET.get('data', '') == "post_asc":
        elaborations.sort(key=lambda elaboration: elaboration.get_last_post_date())
    if request.GET.get('data', '') == "post_desc":
        elaborations.sort(key=lambda elaboration: elaboration.get_last_post_date(), reverse=True)

    # store selected elaborations in session
    request.session['elaborations'] = serializers.serialize('json', elaborations)
    request.session['count'] = len(elaborations)

    data = {
        'overview_html': render_to_string('overview.html', {'elaborations': elaborations, 'course': course}, RequestContext(request)),
        'menu_html': render_to_string('menu.html', {
            'count_' + request.session.get('selection', ''): request.session.get('count', '0'),
            'stabilosiert_' + request.session.get('selection', ''): 'stabilosiert', 'course': course,
        }, RequestContext(request)),
        'selection': request.session['selection']
    }

    return HttpResponse(json.dumps(data))
예제 #47
0
def plagcheck_suspicions(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)

    suspicion_list = Suspicion.suspicion_list_by_request(request, course)

    count = suspicion_list.count()

    context = {
        'course': course,
        'suspicions': suspicion_list,
        'suspicion_states': SuspicionState.choices(),
        'current_suspicion_state_filter': int(request.GET.get('state', -1)),
        'suspicions_count': count,
        'open_new_window': False,
        'enable_state_filter': True,
    }

    request.session['selection'] = 'plagcheck_suspicions'
    request.session['count'] = count

    return render_to_response('evaluation.html', {
            'overview': render_to_string('plagcheck_suspicions.html', context, RequestContext(request)),
            'course': course,
            'stabilosiert_plagcheck_suspicions': 'stabilosiert',
            'count_plagcheck_suspicions': count,
            'selection': request.session['selection'],
        },
        context_instance=RequestContext(request))
예제 #48
0
def awesome(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    selected_challenge = request.session.get('selected_challenge', 'task...')
    if selected_challenge != 'task...':
        selected_challenge = selected_challenge[:(selected_challenge.rindex('(') - 1)]
        challenge = Challenge.objects.get(title=selected_challenge, course=course)
        elaborations = Elaboration.get_awesome_challenge(course, challenge)
    else:
        elaborations = Elaboration.get_awesome(course)

    # sort elaborations by submission time
    if type(elaborations) == list:
        elaborations.sort(key=lambda elaboration: elaboration.submission_time)
    else:
        elaborations = elaborations.order_by('submission_time')

    # store selected elaborations in session
    request.session['elaborations'] = serializers.serialize('json', elaborations)
    request.session['selection'] = 'awesome'
    request.session['selected_challenge'] = 'task...'
    request.session['count'] = len(elaborations)

    return render_to_response('evaluation.html',
                              {'overview': render_to_string('overview.html', {'elaborations': elaborations, 'course': course},
                                                            RequestContext(request)),
                               'count_awesome': request.session.get('count', '0'),
                               'selected_task': selected_challenge,
                               'stabilosiert_awesome': 'stabilosiert',
                               'selection': request.session['selection'],
                               'course': course
                              },
                              context_instance=RequestContext(request))
예제 #49
0
파일: views.py 프로젝트: daelin/aurora
def submit_elaboration(request, course_short_title):
    if not 'challenge_id' in request.POST:
        return HttpResponse("missing parameter challenge_id", status=400)
    challenge = Challenge.objects.get(id=request.POST['challenge_id'])
    if not challenge.currently_active:
        return HttpResponse("challenge is currently not active", status=400)

    user = request.user
    course = Course.get_or_raise_404(short_title=course_short_title)
    if not challenge.is_enabled_for_user(user):
        return HttpResponse("challenge not enabled for user", status=400)
    if challenge.is_final_challenge() and challenge.is_in_lock_period(
            user, course):
        return HttpResponse("user is currently locked", status=400)
    elaboration, created = Elaboration.objects.get_or_create(
        challenge=challenge, user=user)

    if elaboration.is_submitted():
        return HttpResponse("elaboration already submitted", status=400)

    elaboration.elaboration_text = request.POST[
        'elaboration_text']  # sanitze here
    elaboration.revised_elaboration_text = elaboration.elaboration_text

    if elaboration.elaboration_text or UploadFile.objects.filter(
            elaboration=elaboration).exists():
        elaboration.submission_time = datetime.now()
        elaboration.save()

        plagcheck_elaboration(elaboration)

        return HttpResponse()
예제 #50
0
def statistics(request, course_short_title=None):
    data = {}
    course = Course.get_or_raise_404(course_short_title)
    data = create_stat_data(course, data)
    return render_to_response('statistics.html',
                              data,
                              context_instance=RequestContext(request))
예제 #51
0
파일: views.py 프로젝트: flozzone/aurora
def notifications(request, course_short_title=None):
    data = {}
    user = RequestContext(request)['user']
    course = Course.get_or_raise_404(course_short_title)

    if 'id' in request.GET:
        try:
            notification = Notification.objects.get(pk=request.GET['id'])
            if not notification.user == user:
                raise Http404
        except:
            raise Http404

        notification.read = True
        notification.save()

        if 'link' in request.GET:
            return redirect(request.GET['link'])

        return redirect('Notification:list',
                        course_short_title=course_short_title)
    notifications = Notification.objects.filter(
        user=user, course=course).order_by('-creation_time')
    data['notifications'] = notifications
    data['course'] = course
    return render_to_response('notifications.html',
                              data,
                              context_instance=RequestContext(request))
예제 #52
0
    def addProblem(cls, uid, prob_priv, prob_title, prob_time, prob_memory,
                   prob_codelength, prob_desc, is_spj, data_count, course_id,
                   case_info):
        try:
            p = Problem()
            if (cls.isLegalTitle(prob_title)):
                p.prob_title = prob_title
            else:
                raise Exception(cls.TITLE_ERRMSG)
            if (cls._isLegalDesc(prob_desc)):
                p.prob_desc = prob_desc
            else:
                raise Exception(cls.DESC_ERRMSG)

            p.prob_priv = prob_priv
            p.prob_title = prob_title
            p.prob_time = prob_time
            p.prob_memory = prob_memory
            p.prob_codelength = prob_codelength
            p.is_spj = is_spj
            p.author = User.getById(uid)
            p.data_count = data_count
            p.course = Course.getById(course_id)
            p.case_info = case_info

            p.save()
            return p
        except Exception as e:
            raise e
예제 #53
0
    def updateProblem(self, uid, prob_priv, prob_title, prob_time, prob_memory,
                      prob_codelength, prob_desc, is_spj, data_count,
                      course_id, case_info):
        try:
            if (Problem.isLegalTitle(prob_title)):
                self.prob_title = prob_title
            else:
                raise Exception(Problem.TITLE_ERRMSG)
            if (Problem._isLegalDesc(prob_desc)):
                self.prob_desc = prob_desc
            else:
                raise Exception(Problem.DESC_ERRMSG)

            self.prob_priv = prob_priv
            self.prob_title = prob_title
            self.prob_time = prob_time
            self.prob_memory = prob_memory
            self.prob_codelength = prob_codelength
            self.is_spj = is_spj
            #self.author = User.getById(uid) #will change the author...
            self.data_count = data_count
            self.course = Course.getById(course_id)
            self.case_info = case_info

            self.save()
            return True
        except Exception as e:
            raise e
예제 #54
0
def thread(request, course_short_title, thread_id):
    course = Course.get_or_raise_404(course_short_title)
    thread_object = get_object_or_404(Thread, pk=thread_id)

    if thread_object.course != course:
        raise Http404("Thread does not exist")

    user_group = UserGroup.objects.filter(group__thread=thread_object, user=request.user).first()

    if user_group:
        thread_object.filter_group_id = user_group.group_id
    else:
        return redirect('diskurs:choose_group', course_short_title=course_short_title, thread_id=thread_id)

    user_history = UserHistory.objects.filter(user=request.user, thread=thread_object).first()

    if not user_history:
        user_history = UserHistory()
        user_history.thread = thread_object
        user_history.user = request.user
        user_history.save()

    viewed_posts = user_history.userhistorypost_set.values_list('post_id', flat=True)

    for post in thread_object.filtered_first_post.filtered_post_set.all():
        if post.id not in viewed_posts:
            user_history.add_post_id_to_history(post.id)

    return render(request, 'diskurs/thread.html', {'thread': thread_object,
                                                   'expanded_posts': [thread_object.filtered_first_post.id],
                                                   'last_post_id': thread_object.filtered_first_post.id,
                                                   'viewed_posts': viewed_posts, 'course': course})
예제 #55
0
def profile(request, course_short_title):
    user = request.user
    selected_course = Course.get_or_raise_404(course_short_title)
    return render_to_response('profile.html', {
        'user': user,
        'course': selected_course
    },
                              context_instance=RequestContext(request))
예제 #56
0
def autocomplete_challenge(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    term = request.GET.get('term', '')
    challenges = Challenge.objects.all().filter(title__istartswith=term, course=course)
    titles = [challenge.title + ' (' + str(challenge.get_sub_elab_count()) + '/' + str(challenge.get_elab_count()) + ')'
              for challenge in challenges]
    response_data = json.dumps(titles, ensure_ascii=False)
    return HttpResponse(response_data, content_type='application/json; charset=utf-8')
예제 #57
0
파일: feed.py 프로젝트: martflu/aurora
    def get_object(self, request, *args, **kwargs):

        feed = {
            'user': FeedToken.get_user_by_token_or_raise_404(kwargs['token']),
            'course': Course.get_or_raise_404(kwargs['course_short_title'])
        }

        return feed
예제 #58
0
파일: views.py 프로젝트: martflu/aurora
def overview(request, course_short_title=None):
    course = Course.get_or_raise_404(short_title=course_short_title)
    elaboration = Elaboration.objects.get(pk=request.GET.get('elaboration_id'))
    user = elaboration.user
    stack = elaboration.challenge.get_stack()
    stack_challenges = stack.get_challenges()

    next_elaboration = None
    try:
        # elaborations = Elaboration.get_final_evaluation_top_level_tasks(course) | Elaboration.objects.filter(id=elaboration.id)
        # all_elaborations = list(elaborations.order_by('submission_time'))

        elaborations = []
        for serialized_elaboration in serializers.deserialize('json', request.session.get('elaborations', {})):
            elaborations.append(serialized_elaboration.object)

        next_index = elaborations.index(elaboration) + 1
        if next_index < len(elaborations):
            next_elaboration = elaborations[next_index]
        else:
            next_elaboration = None
    except ValueError:
        next_elaboration = None

    challenges = []
    for challenge in stack_challenges:
        challenge_data = {}
        challenge_data['challenge'] = challenge
        challenge_data['final'] = challenge.is_final_challenge()

        elaboration =  challenge.get_elaboration(user)
        challenge_data['elaboration'] = elaboration
        challenge_data['reviews'] = challenge.get_reviews_written_by_user(user)
        challenge_data['reveiced_reviews'] = Review.objects.filter(elaboration=elaboration, submission_time__isnull=False)
        challenges.append(challenge_data)

    data = {}
    data['course'] = course
    data['elaboration_user'] = user
    data['stack'] = stack
    data['challenges'] = challenges
    data['elaboration'] = elaboration
    data['next_elaboration'] = next_elaboration

    evaluation = None
    lock = False

    if Evaluation.objects.filter(submission=elaboration):
        evaluation = Evaluation.objects.get(submission=elaboration)
        if evaluation.tutor != request.user and not evaluation.is_older_15min():
            lock = True

    data['evaluation'] = evaluation
    data['evaluation_locked'] = lock

    return render_to_response('evaluation_overview.html',
                              data,
                              context_instance=RequestContext(request))