mirror of
https://github.com/ferdzo/serviceCRM.git
synced 2026-04-05 05:06:25 +00:00
Update 2
This commit is contained in:
@@ -9,13 +9,14 @@ class DateInput(forms.DateInput):
|
|||||||
class InputForm(forms.ModelForm):
|
class InputForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Insert
|
model = Insert
|
||||||
fields = {"name", "phone", "description", "date", "done"}
|
fields = {"name", "phone", "description", "date", "note"}
|
||||||
labels = {'name': "Name", 'phone': "Phone", 'date': "Date", 'description': "Description", 'done': "Done"}
|
labels = {'name': "Name", 'phone': "Phone", 'date': "Date", 'description': "Description", 'note': "Note"}
|
||||||
widgets = {
|
widgets = {
|
||||||
'name': forms.TextInput(attrs={'class': 'form-control'}),
|
'name': forms.TextInput(attrs={'class': 'form-control'}),
|
||||||
'phone': forms.TextInput(attrs={'class': 'form-control'}),
|
'phone': forms.TextInput(attrs={'class': 'form-control'}),
|
||||||
'date': DateInput(),
|
'date': DateInput(),
|
||||||
'description': forms.Textarea(attrs={'class': 'form-control'})
|
'description': forms.Textarea(attrs={'class': 'form-control'}),
|
||||||
|
'note': forms.TextInput(attrs={'class': 'form-control'})
|
||||||
}
|
}
|
||||||
|
|
||||||
field_order = ["name", "phone", "date", "description", "done"]
|
field_order = ["name", "phone", "date", "description", "done"]
|
||||||
|
|||||||
18
serviceCRM/migrations/0002_insert_repair.py
Normal file
18
serviceCRM/migrations/0002_insert_repair.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0.3 on 2024-03-19 19:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('serviceCRM', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='insert',
|
||||||
|
name='repair',
|
||||||
|
field=models.CharField(blank=True, default=None, max_length=300, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
23
serviceCRM/migrations/0003_insert_note_insert_plateno.py
Normal file
23
serviceCRM/migrations/0003_insert_note_insert_plateno.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.0.3 on 2024-03-19 20:49
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('serviceCRM', '0002_insert_repair'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='insert',
|
||||||
|
name='note',
|
||||||
|
field=models.CharField(blank=True, default=None, max_length=100, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='insert',
|
||||||
|
name='plateno',
|
||||||
|
field=models.CharField(blank=True, default=None, max_length=10, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
serviceCRM/migrations/0004_alter_insert_done.py
Normal file
18
serviceCRM/migrations/0004_alter_insert_done.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0.3 on 2024-03-19 21:00
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('serviceCRM', '0003_insert_note_insert_plateno'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='insert',
|
||||||
|
name='done',
|
||||||
|
field=models.BooleanField(blank=True, default=None, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
serviceCRM/migrations/0005_alter_insert_done.py
Normal file
18
serviceCRM/migrations/0005_alter_insert_done.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0.3 on 2024-03-19 21:00
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('serviceCRM', '0004_alter_insert_done'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='insert',
|
||||||
|
name='done',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -6,8 +6,11 @@ class Insert(models.Model):
|
|||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
phone = models.CharField(max_length=20)
|
phone = models.CharField(max_length=20)
|
||||||
description = models.CharField(max_length=300)
|
description = models.CharField(max_length=300)
|
||||||
|
note= models.CharField(max_length=100, default=None, blank=True, null=True)
|
||||||
date = models.DateField("date submitted")
|
date = models.DateField("date submitted")
|
||||||
done = models.BooleanField()
|
done = models.BooleanField(default=False)
|
||||||
|
repair = models.CharField(default=None, blank=True, null=True,max_length=300)
|
||||||
|
plateno = models.CharField(max_length=10, default=None, blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Ime: " + self.name + " Telefonski broj: " + self.phone + "\nDefekt: " + self.description + "\nDatum: \n"
|
return "Ime: " + self.name + " Telefonski broj: " + self.phone + "\nDefekt: " + self.description + "\nDatum: \n"
|
||||||
|
|||||||
@@ -46,7 +46,12 @@ INSTALLED_APPS = [
|
|||||||
]
|
]
|
||||||
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
|
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
|
||||||
CRISPY_TEMPLATE_PACK = "bootstrap5"
|
CRISPY_TEMPLATE_PACK = "bootstrap5"
|
||||||
|
DJANGO_TABLES2_TABLE_ATTRS = {
|
||||||
|
'class': 'table table-hover',
|
||||||
|
'thead': {
|
||||||
|
'class': 'table-light',
|
||||||
|
},
|
||||||
|
}
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
|||||||
@@ -6,16 +6,19 @@ from .models import Insert
|
|||||||
|
|
||||||
class InsertTable(tables.Table):
|
class InsertTable(tables.Table):
|
||||||
|
|
||||||
actions = TemplateColumn(template_code='<a class="btn btn-secondary" href="{% url \'update\' record.id %}">Edit</a>')
|
actions = TemplateColumn(template_code='<a class="btn btn-secondary" href="{% url \'update\' record.id %}">Edit</a> <a class="btn btn-secondary" href="{% url \'done\' record.id %}">Details</a>')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Insert
|
model = Insert
|
||||||
fields = ("id","name","phone","description","date","done")
|
fields = ("id","name","phone","description","date","done")
|
||||||
|
per_page = 5
|
||||||
|
|
||||||
|
|
||||||
class DoneInsertTable(InsertTable):
|
class DoneInsertTable(InsertTable):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Insert
|
model = Insert
|
||||||
fields = ("id","name","phone","description","date","done")
|
fields = ("id","name","phone","description","date","done")
|
||||||
|
per_page = 5
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|||||||
@@ -19,14 +19,11 @@
|
|||||||
<div class="navbar-header">
|
<div class="navbar-header">
|
||||||
<a class="navbar-brand" href="/">Service CRM</a>
|
<a class="navbar-brand" href="/">Service CRM</a>
|
||||||
</div>
|
</div>
|
||||||
{% comment %} <ul class="nav navbar-nav">
|
|
||||||
<li class="active"><a href="#">Home</a></li>
|
|
||||||
<li><a href="#">Page 1</a></li>
|
|
||||||
<li><a href="#">Page 2</a></li>
|
|
||||||
</ul> {% endcomment %}
|
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li><a href="/insert"><span class="glyphicon glyphicon-user"></span>Insert</a></li>
|
<li><a href="/insert"><span class="glyphicon glyphicon-user"></span>Insert</a></li>
|
||||||
<li><a href="/admin"><span class="glyphicon glyphicon-log-in"></span> Admin</a></li>
|
<li><a href="/admin"><span class="glyphicon glyphicon-log-in"></span> Admin</a></li>
|
||||||
|
<li><a href="/done"><span class="glyphicon glyphicon-log-in"></span> Done</a></li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
35
serviceCRM/tests.py
Normal file
35
serviceCRM/tests.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from django.test import TestCase, RequestFactory
|
||||||
|
from django.urls import reverse
|
||||||
|
from .models import Insert
|
||||||
|
from .views import InsertListView, InsertNew, Update, Nalog, Done
|
||||||
|
|
||||||
|
class InsertListViewTest(TestCase):
|
||||||
|
def test_view_url_exists_at_desired_location(self):
|
||||||
|
response = self.client.get('/list/') # replace with your actual url
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
class InsertNewTest(TestCase):
|
||||||
|
def test_view_url_exists_at_desired_location(self):
|
||||||
|
response = self.client.get('/insert/') # replace with your actual url
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
class UpdateTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.insert = Insert.objects.create(name="Test", phone="1234567890", description="Test description", done=False, repair="Test repair")
|
||||||
|
|
||||||
|
def test_view_url_exists_at_desired_location(self):
|
||||||
|
response = self.client.get(reverse('update', args=(self.insert.id,))) # replace 'update' with your actual url name
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
class NalogTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.insert = Insert.objects.create(name="Test", phone="1234567890", description="Test description", done=False, repair="Test repair")
|
||||||
|
|
||||||
|
def test_view_url_exists_at_desired_location(self):
|
||||||
|
response = self.client.get(reverse('/nalog/', args=(self.insert.id,))) # replace 'nalog' with your actual url name
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
class DoneTest(TestCase):
|
||||||
|
def test_view_url_exists_at_desired_location(self):
|
||||||
|
response = self.client.get('/done/') # replace with your actual url
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
@@ -26,4 +26,5 @@ urlpatterns = [
|
|||||||
path("nalog/<int:id>/", view.Nalog, name="nalog"),
|
path("nalog/<int:id>/", view.Nalog, name="nalog"),
|
||||||
path("delete/<int:id>/", view.Delete.Delete, name="delete"),
|
path("delete/<int:id>/", view.Delete.Delete, name="delete"),
|
||||||
path("done/", view.Done.as_view(), name="done"),
|
path("done/", view.Done.as_view(), name="done"),
|
||||||
|
path("done/<int:id>/", view.Done.done_by_id, name="done")
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -6,19 +6,13 @@ from .forms import InputForm
|
|||||||
from .models import Insert
|
from .models import Insert
|
||||||
from .tables import DoneInsertTable, InsertTable
|
from .tables import DoneInsertTable, InsertTable
|
||||||
from django_tables2 import SingleTableView
|
from django_tables2 import SingleTableView
|
||||||
|
|
||||||
|
|
||||||
class InsertListView(SingleTableView):
|
class InsertListView(SingleTableView):
|
||||||
model = Insert
|
model = Insert
|
||||||
table_class = InsertTable
|
table_class = InsertTable
|
||||||
template_name = 'serviceCRM/list.html'
|
template_name = 'serviceCRM/list.html'
|
||||||
|
|
||||||
# class ReportById(generic.DetailView):
|
|
||||||
# model = Insert
|
|
||||||
# template_name = "serviceCRM/id.html"
|
|
||||||
# def ReportById(request, question_id):
|
|
||||||
# req = get_object_or_404(Insert, id=question_id)
|
|
||||||
# context = {"name": req.name, "phone": req.phone, "desc": req.description, "date": req.date}
|
|
||||||
# return HttpResponse(f"Report ID: {question_id} \nName: {req.name} \nPhone: {req.phone} \nDescription: {req.description} \nDate: {req.date} \nDone: {req.done}")
|
|
||||||
|
|
||||||
class InsertNew(generic.View):
|
class InsertNew(generic.View):
|
||||||
model = Insert
|
model = Insert
|
||||||
template_name = "serviceCRM/form.html"
|
template_name = "serviceCRM/form.html"
|
||||||
@@ -38,14 +32,9 @@ class InsertNew(generic.View):
|
|||||||
class Update(UpdateView):
|
class Update(UpdateView):
|
||||||
model = Insert
|
model = Insert
|
||||||
template_name = "serviceCRM/edit.html"
|
template_name = "serviceCRM/edit.html"
|
||||||
fields = ["name", "phone", "description", "done"]
|
fields = ["name", "phone", "description","note", "done", "repair", "plateno"]
|
||||||
success_url = '/'
|
success_url = '/'
|
||||||
|
|
||||||
def done(request, id):
|
|
||||||
req = get_object_or_404(Insert, id=id)
|
|
||||||
if req.isDone():
|
|
||||||
return HttpResponse("Done")
|
|
||||||
return HttpResponse("Not Done")
|
|
||||||
|
|
||||||
def Nalog(request, id):
|
def Nalog(request, id):
|
||||||
data = Insert.objects.get(id=id)
|
data = Insert.objects.get(id=id)
|
||||||
@@ -53,16 +42,23 @@ def Nalog(request, id):
|
|||||||
context = {"name": data.name, "phone": data.phone, "desc": data.description, "date": data.date}
|
context = {"name": data.name, "phone": data.phone, "desc": data.description, "date": data.date}
|
||||||
return render(request, template, context)
|
return render(request, template, context)
|
||||||
|
|
||||||
class Delete():
|
|
||||||
model = Insert
|
|
||||||
def Delete(request, id):
|
|
||||||
req = get_object_or_404(Insert, id=id)
|
|
||||||
req.delete()
|
|
||||||
return HttpResponseRedirect("/")
|
|
||||||
|
|
||||||
class Done(SingleTableView):
|
class Done(SingleTableView):
|
||||||
model = Insert
|
model = Insert
|
||||||
table_data = Insert.objects.filter(done=True)
|
table_data = Insert.objects.filter(done=True)
|
||||||
table_class = DoneInsertTable
|
table_class = DoneInsertTable
|
||||||
template_name = 'serviceCRM/done.html'
|
template_name = 'serviceCRM/done.html'
|
||||||
|
|
||||||
|
def done_by_id(request, id):
|
||||||
|
try:
|
||||||
|
req = get_object_or_404(Insert, id=id)
|
||||||
|
except:
|
||||||
|
return HttpResponseRedirect("/done/")
|
||||||
|
context = {"name": req.name, "phone": req.phone, "desc": req.description, "date": req.date}
|
||||||
|
return HttpResponse(f"Report ID: {id} \nName: {req.name} \nPhone: {req.phone} \nDescription: {req.description} \n Note:{req.note} \nDate: {req.date} \nDone: {req.done} \nRepair: {req.repair} \n Plateno: {req.plateno} \n")
|
||||||
|
|
||||||
|
class Delete():
|
||||||
|
model = Insert
|
||||||
|
def Delete(request, id):
|
||||||
|
req = get_object_or_404(Insert, id=id)
|
||||||
|
req.delete()
|
||||||
|
return HttpResponseRedirect("/")
|
||||||
Reference in New Issue
Block a user