Commit 639f0a73 authored by Ola Hermann Opheim's avatar Ola Hermann Opheim
Browse files

Merge branch 'feat/edit_project_offer' into 'master'

Feat/edit project offer

See merge request olahop/agreelance123!6
parents ce15bef8 85b3b502
......@@ -273,8 +273,47 @@
<h3>Last Offer </h3>
<h4 class="mt-3">{{offer.title}}</h4>
<p>Status: {{offer.get_status_display}}</p>
<p>Description: <br> {{offer.description}}</p>
<p>Price offered: {{offer.price}} </p>
{% if user == offer.offerer.user %}
{% if offer.status == 'p' %}
{% if offer.edit %}
<form method="post">
Description:
<textarea
type="text"
name="offer_description"
required
maxlength="500"
class="form-control"
>{{offer.description}}</textarea>
Price offered:
<textarea
type="number"
min = "0"
name="offer_price"
required
maxlength="200"
class="form-control"
>{{offer.price}}</textarea>
{% csrf_token %}
<input type="hidden" name="offer_id" value="{{offer.id}}">
<button class="btn btn-primary" name="edit_offer" type="submit">Save</button>
</form>
{% else %}
<form method="post">
<p>Description: <br> {{offer.description}}</p>
<p>Price offered: {{offer.price}} </p>
<input type="hidden" name="offer_id" value="{{offer.id}}">
{% csrf_token %}
<button class="btn btn-primary" name="edit_offer" type="submit" onclick="$('#modal').modal({'backdrop': 'static'});">Edit</button>
</form>
{% endif %}
{% endif %}
{% else %}
<p>Description: <br> {{offer.description}}</p>
<p>Price offered: {{offer.price}} </p>
{% endif %}
{%if offer.status == 'a' or offer.status == 'd' %}
<p class="mt-2">Feedback from project owner: <br> {{offer.feedback}}</p>
{% endif %}
......
......@@ -53,6 +53,12 @@ class TaskOfferResponseForm(forms.ModelForm):
model = TaskOffer
fields = ('status', 'feedback')
class EditTaskOfferForm(forms.ModelForm):
class Meta:
model = TaskOffer
fields = ('edit',)
class TaskDeliveryResponseForm(forms.ModelForm):
feedback = forms.Textarea()
......
# Generated by Django 2.1.7 on 2020-03-06 19:48
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('projects', '0004_project_edit'),
]
operations = [
migrations.AddField(
model_name='taskoffer',
name='edit',
field=models.BooleanField(default=False),
),
]
......@@ -171,6 +171,7 @@ class TaskOffer(models.Model):
title = models.CharField(max_length=200)
description = models.TextField(max_length=500)
price = models.IntegerField(default=0)
edit = models.BooleanField(default=False)
offerer = models.ForeignKey(Profile, on_delete=models.CASCADE)
ACCEPTED = 'a'
......
......@@ -3,7 +3,7 @@ from django.test import Client
from django.contrib.auth.models import User
from projects.templatetags.project_extras import get_all_taskoffers
from projects.models import Project, ProjectCategory, Task
from projects.models import Project, ProjectCategory, Task, TaskOffer
from projects.views import get_user_task_permissions
......@@ -44,32 +44,48 @@ class ProjectTest(unittest.TestCase):
feedback=''
)
self.edit_offer_test_offer = TaskOffer.objects.create(
task=self.testTask,
title='Test offer 1',
description='original',
price=20,
offerer=self.userNormal.profile,
edit=True
)
# Test project_view GET route
self.client.get('/projects/' + str(Project.objects.last().pk) + '/')
# Test project_view POST route submit project
self.client.login(username= 'Normal', password= 'top_secret')
response = self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'offer_submit': True,
'title': 'heititle',
'description': 'ja',
'price': 123,
'taskvalue': Project.objects.last().pk,
'title': 'offer title',
'description': 'test offer',
'price': 567,
'taskvalue': self.testTask.id,
})
# Test project_view POST route edit offer
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'edit_offer': '',
'offer_id': self.edit_offer_test_offer.id,
'offer_description': 'edited',
'offer_price': '30',
})
# Test project_view POST route offer response
self.client.login(username= 'Owner', password= 'top_secret')
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'offer_response': True,
'taskofferid': 0,
'taskofferid': self.edit_offer_test_offer.id,
'status': 'a',
'feedback': 'ja',
})
# Test project_view POST route edit project
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'edit_project': True,
#'edit': True,
})
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'edit_project': True,
......@@ -262,21 +278,67 @@ class SortingTest(unittest.TestCase):
self.assertEqual(response.context['projects'][1], self.project_c)
self.assertEqual(response.context['projects'][2], self.project_b)
class ProjectOfferTest(unittest.TestCase):
class EditTaskOfferTest(unittest.TestCase):
def setUp(self):
self.client = Client()
def test_project_offer_boundary_values(self):
#TODO
self.assertTrue(True)
self.edit_offer_category = ProjectCategory.objects.create(name='edit_offer_category')
def test_accepting_project_offer_output(self):
#TODO
self.assertTrue(True)
self.project_owner = User.objects.create_user(
username='POwner',
email='test@test.com',
password='top_secret'
)
def test_edit_project_offer_integration(self):
#TODO
self.assertTrue(True)
self.offerer = User.objects.create_user(
username='Offerer',
email='test@test.com',
password='top_secret'
)
self.edit_offer_test_project = Project.objects.create(
user=self.project_owner.profile,
title='Edit offer test project',
description='',
category=self.edit_offer_category,
status='o'
)
self.edit_offer_test_task = Task.objects.create(
project=self.edit_offer_test_project,
title='Test task 1',
description='',
budget=20,
status='o',
feedback=''
)
self.edit_offer_test_offer = TaskOffer.objects.create(
task=self.edit_offer_test_task,
title='Test offer 1',
description='original',
price=20,
offerer=self.offerer.profile,
edit=True
)
def test_edit_offer(self):
# Test init
self.assertEqual(self.edit_offer_test_offer.description, 'original')
self.assertEqual(self.edit_offer_test_offer.price, 20)
# Test edit
self.client.login(username= 'Offerer', password= 'top_secret')
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'edit_offer': '',
'offer_id': self.edit_offer_test_offer.id,
'offer_description': 'edited',
'offer_price': 30,
})
offer = TaskOffer.objects.get(id=self.edit_offer_test_offer.id)
self.assertEqual(offer.description, 'edited')
self.assertEqual(offer.price, 30)
class EditProjectTest(unittest.TestCase):
def setUp(self):
......@@ -346,4 +408,3 @@ class EditProjectTest(unittest.TestCase):
self.assertEqual(response.context['tasks'][0].budget, 40)
self.assertEqual(response.context['tasks'][1].description, 'edited task2')
self.assertEqual(response.context['tasks'][1].budget, 50)
\ No newline at end of file
from django.http import HttpResponse, HttpResponseRedirect
from user.models import Profile
from .models import Project, Task, TaskFile, TaskOffer, Delivery, ProjectCategory, Team, TaskFileTeam, directory_path
from .forms import EditProjectForm, ProjectForm, TaskFileForm, ProjectStatusForm, TaskOfferForm, TaskOfferResponseForm, TaskPermissionForm, DeliveryForm, TaskDeliveryResponseForm, TeamForm, TeamAddForm, SortForm
from .forms import EditTaskOfferForm, EditProjectForm, ProjectForm, TaskFileForm, ProjectStatusForm, TaskOfferForm, TaskOfferResponseForm, TaskPermissionForm, DeliveryForm, TaskDeliveryResponseForm, TeamForm, TeamAddForm, SortForm
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
......@@ -101,7 +101,6 @@ def project_view(request, project_id):
project = offer_response.task.project
project.participants.add(offer_response.offerer)
offer_response.save()
offer_response_form = TaskOfferResponseForm()
......@@ -116,7 +115,6 @@ def project_view(request, project_id):
task.save()
project.edit = not project.edit
project.save()
edit_project_form = EditProjectForm()
if request.method == 'POST' and 'status_change' in request.POST:
status_form = ProjectStatusForm(request.POST)
......@@ -132,7 +130,6 @@ def project_view(request, project_id):
'status_form': status_form,
'total_budget': total_budget,
'offer_response_form': offer_response_form,
'edit_project_form': edit_project_form,
})
......@@ -146,6 +143,17 @@ def project_view(request, project_id):
task_offer.save()
task_offer_form = TaskOfferForm()
if request.method == 'POST' and 'edit_offer' in request.POST:
edit_task_offer_form = EditTaskOfferForm(request.POST)
if edit_task_offer_form.is_valid():
offer = TaskOffer.objects.get(id=request.POST.get('offer_id'))
if offer.status == 'p' and request.user == offer.offerer.user:
if offer.edit:
offer.description = request.POST['offer_description']
offer.price = request.POST['offer_price']
offer.edit = not offer.edit
offer.save()
return render(request, 'projects/project_view.html', {
'project': project,
'tasks': tasks,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment