Uraden veliki servis

This commit is contained in:
ferdzo
2024-03-19 20:44:23 +01:00
parent ad43613629
commit 571e57a301
15 changed files with 287 additions and 60 deletions

19
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Django",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver"
],
"django": true,
"autoStartBrowser": false
}
]
}

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"cmake.configureOnOpen": false
}

View File

@@ -1,6 +1,73 @@
<index>
<body>
</body>
</index>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Servicing Ticket</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
}
.header img {
max-width: 150px;
}
.ticket {
border: 2px solid #000;
padding: 20px;
margin-bottom: 20px;
}
.ticket-info {
margin-bottom: 20px;
}
.ticket-info label {
font-weight: bold;
}
.ticket-description {
border-top: 2px solid #000;
padding-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<img src="fer-logo.png" style="max-width:65%" alt="Company Logo">
</div>
<div class="ticket">
<div class="ticket-info">
<label>Име и презиме:</label> {{ ticket.name }}
</div>
<div class="ticket-info">
<label>Телефонски број:</label> {{ticket.phone}}
</div>
<div class="ticket-info">
<label>Датум:</label> {{ticket.date}}
</div>
<div class="ticket-description">
<label><b>Опис на дефект:</b></label>{% if ticket.description %} {{ ticket.description }} {% else %} Нема опис {% endif %}
</div>
</div>
<div style="height:150px;"></div>
<div class="ticket">
<div class="ticket-info">
<label>Име и презиме:</label> {{ ticket.name }}
</div>
<div class="ticket-info">
<label>Телефонски број:</label> {{ ticket.phone }}
</div>
<div class="ticket-info">
<label>Датум:</label> {{ ticket.date }}
</div>
<div class="ticket-description">
<label><b>Опис на дефект:</b></label>{% if ticket.description %} {{ ticket.description }} {% else %} Нема опис {% endif %}
</div>
</div>
</div>
</body>
</html>

14
serviceCRM/filter.py Normal file
View File

@@ -0,0 +1,14 @@
from .models import Insert
import django_filters as filters
from django_filters import FilterSet
class DoneTable(FilterSet):
class Meta:
model = Insert
fields = ["done"]
def filter_done(self, queryset, name, value):
if value:
return queryset.filter(done=True)
else:
return queryset.filter(done=False)

View File

@@ -20,7 +20,15 @@ class InputForm(forms.ModelForm):
field_order = ["name", "phone", "date", "description", "done"]
# name = forms.CharField(label="Name", max_length=30)
# phone = forms.CharField(label="Phone", max_length=30)
# date = forms.DateField()
# description = forms.CharField(label="Write description of the problem...", max_length=300)
# class EditForm(forms.ModelForm):
# class Meta:
# model = Insert
# fields = {"name", "phone", "description", "done"}
# labels = {'name': "Name", 'phone': "Phone", 'description': "Description", 'done': "Done"}
# widgets = {
# 'name': forms.TextInput(attrs={'class': 'form-control'}),
# 'phone': forms.TextInput(attrs={'class': 'form-control'}),
# 'description': forms.Textarea(attrs={'class': 'form-control'})
# }
# field_order = ["name", "phone", "description", "done"]

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -1,13 +1,22 @@
import django_tables2 as tables
from django_tables2 import TemplateColumn
from django_filters import FilterSet
from django.db.models.query import QuerySet # Add missing import
from .models import Insert
from django_tables2.utils import A
class InsertTable(tables.Table):
actions = TemplateColumn(template_code='<a class="btn btn-secondary" href="{% url \'update\' record.id %}">Edit</a>')
class Meta:
model = Insert
template_name = "list.html"
sequence = ("name", "phone", "description","date","done" )
delete = tables.LinkColumn('main:delete_item', args=[A('pk')], attrs={
'a': {'class': 'btn'}
})
fields = ("id","name","phone","description","date","done")
class DoneInsertTable(InsertTable):
class Meta:
model = Insert
fields = ("id","name","phone","description","date","done")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print(self.data)

View File

@@ -3,6 +3,6 @@
{% load render_table from django_tables2 %}
{% render_table table %}
{% render_table object_list %}
{% endblock%}

View File

@@ -0,0 +1,6 @@
{% extends 'base.html' %}
{% load render_table from django_tables2 %}
{% block content %}
{% render_table table %}
{%endblock%}

View File

@@ -1 +1,13 @@
<a class="btn btn-info btn-sm" href="{% url 'edit' record.id %}">Edit</a>
{% extends 'base.html' %}
{% block title %}Edit{% endblock %}
{% block content %}
{% csrf_token %}
<form method="post">
<div class="form-group">
{% csrf_token %}
{{form.as_p}}
<input type="submit" class="btn btn-success" value="Update">
<input type="submit" class="btn btn-danger" value="Delete" formaction="{% url 'delete' id=object.id %}">
</div>
</form>
{% endblock%}

View File

@@ -1,8 +1,5 @@
{% extends 'base.html' %}
{% load render_table from django_tables2 %}
{% block content %}
{% load render_table from django_tables2 %}
{% render_table table %}
{% endblock%}

View File

@@ -0,0 +1,83 @@
{% block content %}
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Servicing Ticket</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
}
.header img {
max-width: 150px;
}
.ticket {
border: 2px solid #000;
padding: 20px;
margin-bottom: 20px;
}
.ticket-info {
margin-bottom: 20px;
}
.ticket-info label {
font-weight: bold;
}
.ticket-description {
border-top: 2px solid #000;
padding-top: 10px;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100%;
max-height: 100%;
margin-bottom: 5 0px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<img src="{% static 'fer-logo.png' %}" class="center" alt="Company Logo">
</div>
<div class="ticket">
<div class="ticket-info">
<label>Име и презиме:</label> {{ name }}
</div>
<div class="ticket-info">
<label>Телефонски број:</label> {{phone}}
</div>
<div class="ticket-info">
<label>Датум:</label> {{date}}
</div>
<div class="ticket-description">
<label><b>Опис на дефект:</b></label> {{ desc }}
</div>
</div>
<div style="height:150px;"></div>
<div class="ticket">
<div class="ticket-info">
<label>Име и презиме:</label> {{ name }}
</div>
<div class="ticket-info">
<label>Телефонски број:</label> {{ phone }}
</div>
<div class="ticket-info">
<label>Датум:</label> {{ date }}
</div>
<div class="ticket-description">
<label><b>Опис на дефект:</b></label> {{ desc }}
</div>
</div>
</div>
</body>
</html>
{% endblock %}

View File

@@ -19,8 +19,11 @@ from django.urls import path
import serviceCRM.views as view
urlpatterns = [
path("", view.TableView.as_view(), name="index"),
path("", view.InsertListView.as_view(), name="index"),
path('admin/', admin.site.urls),
path("<int:question_id>/", view.ReportById.ReportById, name="detail"),
path("insert/", view.InsertNew.insert, name="insert"),
path("done/<int:id>/", view.done, name="done"),]
path("edit/<int:pk>/", view.Update.as_view(), name="update"),
path("nalog/<int:id>/", view.Nalog, name="nalog"),
path("delete/<int:id>/", view.Delete.Delete, name="delete"),
path("done/", view.Done.as_view(), name="done"),
]

View File

@@ -1,36 +1,23 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.views import generic
from django.views.generic import UpdateView
from .forms import InputForm
from .tables import InsertTable
from .models import Insert
from .tables import DoneInsertTable, InsertTable
from django_tables2 import SingleTableView
# from django.template import loader
def index(request):
if request.user.is_authenticated:
return HttpResponse("You are logged in")
proba = Insert.objects.order_by("date")
return HttpResponse(proba)
else:
return HttpResponse("You are not logged in")
# def detail(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(render(request,"serviceCRM/id.html", context))
#
class ReportById(generic.DetailView):
class InsertListView(SingleTableView):
model = Insert
template_name = "serviceCRM/id.html"
table_class = InsertTable
template_name = 'serviceCRM/list.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 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):
model = Insert
@@ -40,23 +27,42 @@ class InsertNew(generic.View):
if request.method == 'POST':
form = InputForm(request.POST)
if form.is_valid():
form.save()
ticket=form.save()
print("Raboti")
return HttpResponseRedirect("/admin/")
return HttpResponseRedirect(f"/nalog/{ticket.id}/")
else:
form = InputForm()
return render(request, InsertNew.template_name, {'form': form})
class TableView(SingleTableView):
table_class = Insert
queryset = Insert.objects.all()
template_name = "serviceCRM/list.html"
class Update(UpdateView):
model = Insert
template_name = "serviceCRM/edit.html"
fields = ["name", "phone", "description", "done"]
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):
data = Insert.objects.get(id=id)
template = "serviceCRM/nalog.html"
context = {"name": data.name, "phone": data.phone, "desc": data.description, "date": data.date}
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):
model = Insert
table_data = Insert.objects.filter(done=True)
table_class = DoneInsertTable
template_name = 'serviceCRM/done.html'