コード例 #1
0
ファイル: librating.py プロジェクト: almet/bv.server
    def rate_user(self, user, tempreport_id, post_data):
        """Rate an user

        Rate the specified user.
        
        Check that logged user is one of the two registred in temporary report, 
        that the mak process is open, and that logged user havn't already give
        his mark.
        
        """
        tempreport = get_object_or_404(TempReport, pk=tempreport_id)
        if (tempreport.user1.id is not user.id
                and tempreport.user2.id is not user.id):
            raise InvalidUser()

        if not tempreport.is_opened():
            raise TempReportIsntOpen()

        if (tempreport.user1.id is user.id
                and tempreport.report1_mark is not None):
            raise MarkAlreadyExists()
            
        if (tempreport.user2.id is user.id
                and tempreport.report2_mark is not None):
            raise MarkAlreadyExists()
        
        form = ReportForm(post_data)
        if form.is_valid():
            if user.id is tempreport.user1.id:
                tempreport.report1_creation_date = datetime.date.today()
                tempreport.report1_mark = form.cleaned_data['mark']
                tempreport.report1_comment = form.cleaned_data['comment']
            else:
                tempreport.report2_creation_date = datetime.date.today()
                tempreport.report2_mark = form.cleaned_data['mark']
                tempreport.report2_comment = form.cleaned_data['comment']
            tempreport.save()
            if tempreport.report1_mark and tempreport.report2_mark:
                # both user are evaluated
                tempreport.transform()
        else:
            raise InvalidReportForm()
        
        return tempreport; 
コード例 #2
0
    def rate_user(self, user, tempreport_id, post_data):
        """Rate an user

        Rate the specified user.
        
        Check that logged user is one of the two registred in temporary report, 
        that the mak process is open, and that logged user havn't already give
        his mark.
        
        """
        tempreport = get_object_or_404(TempReport, pk=tempreport_id)
        if (tempreport.user1.id is not user.id
                and tempreport.user2.id is not user.id):
            raise InvalidUser()

        if not tempreport.is_opened():
            raise TempReportIsntOpen()

        if (tempreport.user1.id is user.id
                and tempreport.report1_mark is not None):
            raise MarkAlreadyExists()

        if (tempreport.user2.id is user.id
                and tempreport.report2_mark is not None):
            raise MarkAlreadyExists()

        form = ReportForm(post_data)
        if form.is_valid():
            if user.id is tempreport.user1.id:
                tempreport.report1_creation_date = datetime.date.today()
                tempreport.report1_mark = form.cleaned_data['mark']
                tempreport.report1_comment = form.cleaned_data['comment']
            else:
                tempreport.report2_creation_date = datetime.date.today()
                tempreport.report2_mark = form.cleaned_data['mark']
                tempreport.report2_comment = form.cleaned_data['comment']
            tempreport.save()
            if tempreport.report1_mark and tempreport.report2_mark:
                # both user are evaluated
                tempreport.transform()
        else:
            raise InvalidReportForm()

        return tempreport
コード例 #3
0
ファイル: views.py プロジェクト: almet/bv.server
def rate_user(request, tempreport_id):
    """Rate an user

    Rate the user, then, if both carpoolers have rated the other one, redirect
    them to the temporary report list
    
    Check that logged user is one of the two registred in temporary report, 
    that the mak process is open, and that logged user havn't already give
    his mark.
    
    This view is accessible via GET or POST.

    GET displays the form
    POST get and process data.
    On errors, display again the form (via GET)

    This view is only accessible by connected users
    """
    tempreport = get_object_or_404(TempReport, pk=tempreport_id)
    if (tempreport.user1.id is not request.user.id
            and tempreport.user2.id is not request.user.id):
        raise Http404

    if not tempreport.is_opened():
        raise Http404

    if (tempreport.user1.id is request.user.id
            and tempreport.report1_mark is not None):
        raise Http404
    if (tempreport.user2.id is request.user.id
            and tempreport.report2_mark is not None):
        raise Http404

    if request.method == 'POST':
        form = ReportForm(request.POST)
        if form.is_valid():
            if request.user.id is tempreport.user1.id:
                tempreport.report1_creation_date = datetime.date.today()
                tempreport.report1_mark = form.cleaned_data['mark']
                tempreport.report1_comment = form.cleaned_data['comment']
            else:
                tempreport.report2_creation_date = datetime.date.today()
                tempreport.report2_mark = form.cleaned_data['mark']
                tempreport.report2_comment = form.cleaned_data['comment']
            tempreport.save()
            if tempreport.report1_mark and tempreport.report2_mark:
                # both user are evaluated
                tempreport.transform()
            return HttpResponseRedirect(reverse(
                'rating:list_temp_reports',args=[1]))
    else:
        form = ReportForm()
    response_dict = {
        'current_item': 14,
        'current_nav_item': 3,
        'form': form,
        'tempreport': tempreport,
    }

    template = loader.get_template('rating/rate_user.html')
    context = RequestContext(request, response_dict)
    return HttpResponse(template.render(context))
コード例 #4
0
def rate_user(request, tempreport_id):
    """Rate an user

    Rate the user, then, if both carpoolers have rated the other one, redirect
    them to the temporary report list
    
    Check that logged user is one of the two registred in temporary report, 
    that the mak process is open, and that logged user havn't already give
    his mark.
    
    This view is accessible via GET or POST.

    GET displays the form
    POST get and process data.
    On errors, display again the form (via GET)

    This view is only accessible by connected users
    """
    tempreport = get_object_or_404(TempReport, pk=tempreport_id)
    if (tempreport.user1.id is not request.user.id
            and tempreport.user2.id is not request.user.id):
        raise Http404

    if not tempreport.is_opened():
        raise Http404

    if (tempreport.user1.id is request.user.id
            and tempreport.report1_mark is not None):
        raise Http404
    if (tempreport.user2.id is request.user.id
            and tempreport.report2_mark is not None):
        raise Http404

    if request.method == 'POST':
        form = ReportForm(request.POST)
        if form.is_valid():
            if request.user.id is tempreport.user1.id:
                tempreport.report1_creation_date = datetime.date.today()
                tempreport.report1_mark = form.cleaned_data['mark']
                tempreport.report1_comment = form.cleaned_data['comment']
            else:
                tempreport.report2_creation_date = datetime.date.today()
                tempreport.report2_mark = form.cleaned_data['mark']
                tempreport.report2_comment = form.cleaned_data['comment']
            tempreport.save()
            if tempreport.report1_mark and tempreport.report2_mark:
                # both user are evaluated
                tempreport.transform()
            return HttpResponseRedirect(
                reverse('rating:list_temp_reports', args=[1]))
    else:
        form = ReportForm()
    response_dict = {
        'current_item': 14,
        'current_nav_item': 3,
        'form': form,
        'tempreport': tempreport,
    }

    template = loader.get_template('rating/rate_user.html')
    context = RequestContext(request, response_dict)
    return HttpResponse(template.render(context))