Exemplo n.º 1
0
 def save(self):
     user_id = g.user.pk
     rating = self.rating.data
     message = self.message.data
     feedback = Feedback(user_id=user_id, rating=rating, message=message)
     feedback.save()
     return feedback
Exemplo n.º 2
0
def add(request):
    user = request.user.id
    form = FeedbckForm()
    if request.method == 'POST':
        form = FeedbckForm(request.POST)
        if form.is_valid():
            message = form.cleaned_data.get('message')
            subject = form.cleaned_data.get('subject')
            print request.user
            from_user = request.user
            to_user = 2
            item = 1
            if message:
                feedback = Feedback(body = message , subject = subject , from_user=from_user , to_user_id=to_user , item_id = item)
                feedback.save()

    return render_to_response("items/add_feedback.html", {'form':form}, context_instance=RequestContext(request))
Exemplo n.º 3
0
def book(parking_id):
    form = ParkingBookForm()
    if form.validate_on_submit():
        form.save()
        flash(
            u'Successfully booked',
            'success'
        )
        feedback_count = Feedback.objects(user_id=g.user.pk).count()
        if not feedback_count:
            return redirect(url_for('feedbacks_app.feedback'))
        return redirect(url_for('parkings_app.search', parking_id=parking_id))

    pipeline = [
        {
            '$lookup': {
                'from': 'booking',
                'localField': '_id',
                'foreignField': 'parkingslot_id',
                'as': 'bookings'
            }
        }
    ]
    parking = Parking.objects.get(pk=parking_id)
    pipeline = [
        {
            '$match': {
                'parking_id': ObjectId(parking_id)
            }
        },
        {
            '$lookup': {
                'from': 'booking',
                'localField': '_id',
                'foreignField': 'parkingslot_id',
                'as': 'bookings'
            }
        }
    ]
    available_slots = ParkingSlot.objects.aggregate(pipeline)
    return render_template('parking/book.html', form=form, parking_slots=available_slots, parking=parking)
Exemplo n.º 4
0
def create(request, project_id):
    project = Project.objects.get(pk=project_id)
    if request.user not in project.collaborators.all():
        return HttpResponseForbidden(request)

    if request.method == "POST":
        form = FeedbackCreationForm(request.POST)
        form.fields["target"].queryset = project.collaborators.exclude(pk=request.user.id)
        if form.is_valid():
            data = form.cleaned_data
            f = Feedback()
            f.project = project
            f.target = data["target"]
            f.maker = request.user
            f.participation_rating = data["participation_rating"]
            f.contribution_rating = data["contribution_rating"]
            f.communication_rating = data["communication_rating"]
            f.ease_of_working_together_rating = data["ease_of_working_together_rating"]
            f.participation_rationale = data["participation_rationale"]
            f.contribution_rationale = data["contribution_rationale"]
            f.communication_rationale = data["communication_rationale"]
            f.ease_of_working_together_rationale = data["ease_of_working_together_rationale"]
            f.save()
            # TODO: add message saying feedback creation is successful
            return redirect("project_detail", id=project.id)
        else:
            return render(request, "feedbacks/create.html", {"form": form})
    elif request.method == "GET":
        form = FeedbackCreationForm()
        form.fields["target"].queryset = project.collaborators.exclude(pk=request.user.id)
        return render(request, "feedbacks/create.html", {"form": form})
Exemplo n.º 5
0
 def tearDown(self):
     User.drop_collection()
     Feedback.drop_collection()
Exemplo n.º 6
0
def create(request, project_id):
    project = Project.objects.get(pk=project_id)
    if request.user not in project.collaborators.all():
        return HttpResponseForbidden(request)

    if request.method == 'POST':
        form = FeedbackCreationForm(request.POST)
        form.fields['target'].queryset = project.collaborators.exclude(
            pk=request.user.id)
        if form.is_valid():
            data = form.cleaned_data
            f = Feedback()
            f.project = project
            f.target = data['target']
            f.maker = request.user
            f.participation_rating = data['participation_rating']
            f.contribution_rating = data['contribution_rating']
            f.communication_rating = data['communication_rating']
            f.ease_of_working_together_rating = data[
                'ease_of_working_together_rating']
            f.participation_rationale = data['participation_rationale']
            f.contribution_rationale = data['contribution_rationale']
            f.communication_rationale = data['communication_rationale']
            f.ease_of_working_together_rationale = data[
                'ease_of_working_together_rationale']
            f.save()
            # TODO: add message saying feedback creation is successful
            return redirect('project_detail', id=project.id)
        else:
            return render(request, 'feedbacks/create.html', {'form': form})
    elif request.method == 'GET':
        form = FeedbackCreationForm()
        form.fields['target'].queryset = project.collaborators.exclude(
            pk=request.user.id)
        return render(request, 'feedbacks/create.html', {'form': form})