Commit 8d1836aa authored by Ola Hermann Opheim's avatar Ola Hermann Opheim
Browse files

autopep

parent 4ca13177
......@@ -26,7 +26,7 @@ SECRET_KEY = '$n%^#g%qx#82w6t^dvjqwv)q*1cy+fwh1ohku7-rbjqcei2^jr'
ADMINS = [('APU', 'tdt4242apu@gmail.com')]
ALLOWED_HOSTS = ['127.0.0.1','localhost','0.0.0.0']
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '0.0.0.0']
# Application definition
......@@ -61,7 +61,14 @@ ROOT_URLCONF = 'agreelance.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'core'), os.path.join(BASE_DIR, 'templates'), ],
'DIRS': [
os.path.join(
BASE_DIR,
'core'),
os.path.join(
BASE_DIR,
'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -146,7 +153,7 @@ if not TEST and not is_prod:
DEBUG = True
try:
from agreelance.local_settings import *
except:
except BaseException:
print("#########")
print("")
print("")
......
......@@ -3,11 +3,13 @@ from projects.models import Project, Task, TaskOffer
register = template.Library()
@register.filter
def check_nr_pending_offers(project):
result = offer_status_counter(project, None)
return result[1]
@register.filter
def check_nr_user_offers(project, user):
result = offer_status_counter(project, user)
......@@ -19,6 +21,7 @@ def check_nr_user_offers(project, user):
return offers
def offer_status_counter(project, user):
pending_offers = 0
declined_offers = 0
......@@ -31,13 +34,14 @@ def offer_status_counter(project, user):
taskoffers = task.taskoffer_set.all()
for taskoffer in taskoffers:
if taskoffer.status == TaskOffer.PENDING:
pending_offers+=1
pending_offers += 1
elif taskoffer.status == TaskOffer.ACCEPTED:
accepted_offers+=1
accepted_offers += 1
elif taskoffer.status == TaskOffer.DECLINED:
declined_offers+=1
declined_offers += 1
return declined_offers, pending_offers, accepted_offers
@register.filter
def task_status(task):
status = "You are awaiting delivery"
......@@ -49,14 +53,17 @@ def task_status(task):
status = "You have sent payment"
return status
@register.filter
def get_task_statuses(project):
return task_status_counter(project, None)
@register.filter
def all_tasks(project):
return project.tasks.all()
@register.filter
def offers(task):
task_offers = task.taskoffer_set.all()
......@@ -66,16 +73,18 @@ def offers(task):
x = 0
msg = "You have "
for t in task_offers:
x+=1
x += 1
if t.status == 'a':
return "You have accepted an offer for this task"
msg += str(x) + " pending offers"
return msg
@register.filter
def get_user_task_statuses(project, user):
return task_status_counter(project, user)
def task_status_counter(project, user):
task_statuses = {}
......@@ -97,15 +106,15 @@ def task_status_counter(project, user):
if task_offer and task_offer.offerer != user.profile:
continue
if task.status == Task.AWAITING_DELIVERY:
awaiting_delivery+=1
awaiting_delivery += 1
elif task.status == Task.PENDING_ACCEPTANCE:
pending_acceptance+=1
pending_acceptance += 1
elif task.status == Task.PENDING_PAYMENT:
pending_payment+=1
pending_payment += 1
elif task.status == Task.PAYMENT_SENT:
payment_sent+=1
payment_sent += 1
elif task.status == Task.DECLINED_DELIVERY:
declined_delivery+=1
declined_delivery += 1
task_statuses['awaiting_delivery'] = awaiting_delivery
task_statuses['pending_acceptance'] = pending_acceptance
......
......@@ -4,11 +4,16 @@ from django.contrib.auth.models import User
from projects.models import Project, Task
from home.templatetags.home_extras import (check_nr_pending_offers, check_nr_user_offers,
task_status, get_task_statuses, get_user_task_statuses)
from home.templatetags.home_extras import (
check_nr_pending_offers,
check_nr_user_offers,
task_status,
get_task_statuses,
get_user_task_statuses)
from test_helpers import (create_test_user, delete_test_data,
create_multiple_test_data, create_task_status_data)
from test_helpers import (create_test_user, delete_test_data,
create_multiple_test_data, create_task_status_data)
class OfferCountingRegressionTest(unittest.TestCase):
def setUp(self):
......@@ -30,6 +35,7 @@ class OfferCountingRegressionTest(unittest.TestCase):
self.assertEquals(result['pending'], 1)
self.assertEquals(result['accepted'], 1)
class TaskStatusRegressionTest(unittest.TestCase):
def setUp(self):
create_task_status_data()
......@@ -40,7 +46,7 @@ class TaskStatusRegressionTest(unittest.TestCase):
def test_task_pending_acc(self):
result = task_status(Task.objects.get(title="Task5"))
self.assertEquals(result, "You have deliveries waiting for acceptance")
def test_task_pending_pay(self):
result = task_status(Task.objects.get(title="Task6"))
self.assertEquals(result, "You have deliveries waiting for payment")
......@@ -53,6 +59,7 @@ class TaskStatusRegressionTest(unittest.TestCase):
result = task_status(Task.objects.get(title="Task1"))
self.assertEquals(result, "You are awaiting delivery")
class GetTaskStatusesRegressionTest(unittest.TestCase):
def setUp(self):
create_multiple_test_data()
......
......@@ -3,6 +3,7 @@ from django.test import Client
from test_helpers import create_test_user, delete_test_data
class HomeViewRegressionTest(unittest.TestCase):
def setUp(self):
self.client = Client()
......@@ -12,10 +13,10 @@ class HomeViewRegressionTest(unittest.TestCase):
delete_test_data()
def test_authenticated_user(self):
self.client.login(username= 'User', password= 'top_secret')
self.client.login(username='User', password='top_secret')
response = self.client.get('/', follow=True)
self.assertTrue(('/projects/', 302) not in response.redirect_chain)
def test_unauthenticated_user(self):
response = self.client.get('/', follow=True)
self.assertTrue(('/projects/', 302) in response.redirect_chain)
\ No newline at end of file
self.assertTrue(('/projects/', 302) in response.redirect_chain)
......@@ -3,11 +3,13 @@ from pprint import pprint
from projects.models import Project
def home(request):
if (request.user.is_authenticated):
user = request.user
user_projects = Project.objects.filter(user = user.profile)
customer_projects = list(Project.objects.filter(participants__id=user.id).order_by().distinct())
user_projects = Project.objects.filter(user=user.profile)
customer_projects = list(Project.objects.filter(
participants__id=user.id).order_by().distinct())
for team in user.profile.teams.all():
customer_projects.append(team.task.project)
cd = {}
......@@ -15,17 +17,19 @@ def home(request):
cd[customer_project.id] = customer_project
customer_projects = cd.values()
given_offers_projects = Project.objects.filter(pk__in=get_given_offer_projects(user)).distinct()
given_offers_projects = Project.objects.filter(
pk__in=get_given_offer_projects(user)).distinct()
return render(
request,
'index.html',
{
'user_projects': user_projects,
'customer_projects': customer_projects,
'given_offers_projects': given_offers_projects,
})
request,
'index.html',
{
'user_projects': user_projects,
'customer_projects': customer_projects,
'given_offers_projects': given_offers_projects,
})
return redirect('projects')
def get_given_offer_projects(user):
project_ids = set()
......
from django.apps import AppConfig
class PaymentConfig(AppConfig):
name = 'payment'
from django import forms
from .models import Payment
class PaymentForm(forms.Form):
cardnumber = forms.CharField(max_length=20, label="Card Number")
expirymonth = forms.CharField(max_length=2, label="Expiry Month")
......
......@@ -14,7 +14,12 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Payment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID')),
],
),
]
......@@ -18,16 +18,24 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='payment',
name='payer',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payer', to='user.Profile'),
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='payer',
to='user.Profile'),
),
migrations.AddField(
model_name='payment',
name='receiver',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='receiver', to='user.Profile'),
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='receiver',
to='user.Profile'),
),
migrations.AddField(
model_name='payment',
name='task',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.Task'),
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to='projects.Task'),
),
]
......@@ -3,10 +3,18 @@ from django.db import models
from projects.models import Task
from user.models import Profile
class Payment(models.Model):
payer = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name="payer")
receiver = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name="receiver")
payer = models.ForeignKey(
Profile,
on_delete=models.CASCADE,
related_name="payer")
receiver = models.ForeignKey(
Profile,
on_delete=models.CASCADE,
related_name="receiver")
task = models.ForeignKey(Task, on_delete=models.CASCADE)
def __str__(self):
return self.payer.user.username + " " + self.receiver.user.username + " " + str(self.task.budget)
return self.payer.user.username + " " + \
self.receiver.user.username + " " + str(self.task.budget)
......@@ -7,6 +7,7 @@ from payment.models import Payment
from test_helpers import delete_test_data, create_multiple_test_data
class PaymentRegressionTest(unittest.TestCase):
def setUp(self):
self.client = Client()
......@@ -19,11 +20,20 @@ class PaymentRegressionTest(unittest.TestCase):
project = Project.objects.get(title="Project1")
task = Task.objects.get(title="Task2")
self.client.login(username= 'User1', password= 'top_secret')
response = self.client.post(f'/payment/{project.pk}/{task.id}', follow=True)
self.client.login(username='User1', password='top_secret')
response = self.client.post(
f'/payment/{project.pk}/{task.id}', follow=True)
task_payment = Payment.objects.get(task=task)
self.assertEquals(task_payment.payer, User.objects.get(username="User1").profile)
self.assertEquals(task_payment.receiver, User.objects.get(username="User2").profile)
self.assertEquals(
task_payment.payer,
User.objects.get(
username="User1").profile)
self.assertEquals(
task_payment.receiver,
User.objects.get(
username="User2").profile)
self.assertEquals(Task.objects.get(title="Task2").status, 'ps')
self.assertTrue((f'/payment/{project.pk}/{task.id}/receipt/', 302) in response.redirect_chain)
self.assertTrue(
(f'/payment/{project.pk}/{task.id}/receipt/',
302) in response.redirect_chain)
......@@ -17,16 +17,17 @@ def payment(request, project_id, task_id):
receiver = get_accepted_task_offer(task).offerer
payment = Payment(payer=sender, receiver=receiver, task=task)
payment.save()
task.status = Task.PAYMENT_SENT # Set task status to payment sent
task.status = Task.PAYMENT_SENT # Set task status to payment sent
task.save()
return redirect('receipt', project_id=project_id, task_id=task_id)
form = PaymentForm()
return render(request,
'payment/payment.html', {
'form': form,
})
'payment/payment.html', {
'form': form,
})
@login_required
def receipt(request, project_id, task_id):
......@@ -35,8 +36,8 @@ def receipt(request, project_id, task_id):
taskoffer = get_accepted_task_offer(task)
return render(request,
'payment/receipt.html', {
'project': project,
'task': task,
'taskoffer': taskoffer,
})
'payment/receipt.html', {
'project': project,
'task': task,
'taskoffer': taskoffer,
})
from django.contrib import admin
from .models import Project, Task, TaskFile, Delivery, ProjectCategory, Team, TaskFileTeam
from .models import (
Project,
Task,
TaskFile,
Delivery,
ProjectCategory,
Team,
TaskFileTeam)
class TaskInline(admin.TabularInline):
model = Task
verbose_name_plural = 'Tasks'
class ProjectAdmin(admin.ModelAdmin):
inlines = (TaskInline, )
......@@ -14,6 +23,7 @@ class ProjectAdmin(admin.ModelAdmin):
return super(ProjectAdmin, self).get_inline_instances(request, obj)
return list()
admin.site.register(Project, ProjectAdmin)
admin.site.register(Task)
admin.site.register(TaskFile)
......
from django.apps import AppConfig
class ProjectConfig(AppConfig):
name = 'projects'
from django import forms
from user.models import Profile
from .models import Project, TaskFile, TaskOffer, Delivery, ProjectCategory, Team, Projects
from .models import (
Project,
TaskFile,
TaskOffer,
Delivery,
ProjectCategory,
Team,
Projects)
from django.contrib.auth.models import User
class SortForm(forms.ModelForm):
class Meta:
model = Projects
fields = ('sort_by',)
class ProjectForm(forms.ModelForm):
title = forms.CharField(max_length=200)
description = forms.Textarea()
category_id = forms.ModelChoiceField(queryset=ProjectCategory.objects.all())
category_id = forms.ModelChoiceField(
queryset=ProjectCategory.objects.all())
class Meta:
model = Project
fields = ('title', 'description', 'category_id')
class EditProjectForm(forms.ModelForm):
class Meta:
model = Project
fields = ('edit',)
class TaskFileForm(forms.ModelForm):
file = forms.FileField()
......@@ -31,12 +43,14 @@ class TaskFileForm(forms.ModelForm):
model = TaskFile
fields = ('file',)
class ProjectStatusForm(forms.ModelForm):
class Meta:
model = Project
fields = ('status',)
class TaskOfferForm(forms.ModelForm):
title = forms.CharField(max_length=200)
description = forms.Textarea()
......@@ -46,6 +60,7 @@ class TaskOfferForm(forms.ModelForm):
model = TaskOffer
fields = ('title', 'description', 'price',)
class TaskOfferResponseForm(forms.ModelForm):
feedback = forms.Textarea()
......@@ -53,12 +68,14 @@ 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()
......@@ -68,14 +85,16 @@ class TaskDeliveryResponseForm(forms.ModelForm):
PERMISSION_CHOICES = (
('Read','Read'),
('Read', 'Read'),
('Write', 'Write'),
('Modify','Modify'),
('Modify', 'Modify'),
)
class TaskPermissionForm(forms.Form):
user = forms.ModelChoiceField(queryset=User.objects.all())
permission = forms.ChoiceField( choices=PERMISSION_CHOICES)
permission = forms.ChoiceField(choices=PERMISSION_CHOICES)
class DeliveryForm(forms.ModelForm):
comment = forms.Textarea()
......@@ -83,7 +102,8 @@ class DeliveryForm(forms.ModelForm):
class Meta:
model = Delivery
fields = ('comment','file')
fields = ('comment', 'file')
class TeamForm(forms.ModelForm):
name = forms.CharField(max_length=50)
......@@ -92,8 +112,11 @@ class TeamForm(forms.ModelForm):
model = Team
fields = ('name',)
class TeamAddForm(forms.ModelForm):
members = forms.ModelMultipleChoiceField(queryset=Profile.objects.all(), label='Members with read')
members = forms.ModelMultipleChoiceField(
queryset=Profile.objects.all(),
label='Members with read')
class Meta:
model = Team
......
......@@ -13,8 +13,25 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Projects',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_by', models.CharField(choices=[('t', 'Title A-Z'), ('!t', 'Title Z-A'), ('o', 'Owner A-Z'), ('!o', 'Owner Z-A')], default='t', max_length=11)),
('id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID')),
('sort_by',
models.CharField(
choices=[
('t',
'Title A-Z'),
('!t',
'Title Z-A'),
('o',
'Owner A-Z'),
('!o',
'Owner Z-A')],
default='t',
max_length=11)),
],
),
]
......@@ -14,11 +14,34 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='project',
name='timestamp',
field=models.DateTimeField(default=datetime.datetime(2020, 3, 13, 15, 53, 54, 128210)),
field=models.DateTimeField(
default=datetime.datetime(
2020,
3,
13,
15,
53,
54,
128210)),
),
migrations.AlterField(
model_name='projects',
name='sort_by',
field=models.CharField(choices=[('t', 'Title A-Z'), ('!t', 'Title Z-A'), ('d', 'Date A-Z'), ('!d', 'Date Z-A'), ('o', 'Owner A-Z'), ('!o', 'Owner Z-A')], default='t', max_length=11),
field=models.CharField(
choices=[
('t',
'Title A-Z'),
('!t',
'Title Z-A'),
('d',
'Date A-Z'),
('!d',
'Date Z-A'),
('o',
'Owner A-Z'),
('!o',
'Owner Z-A')],
default='t',
max_length=11),
),
]
......@@ -14,6 +14,14 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='project',