Skip to content

Commit

Permalink
add report system feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kkkkkkkkatya committed May 21, 2024
1 parent f4eddf0 commit f098c8c
Show file tree
Hide file tree
Showing 37 changed files with 521 additions and 14 deletions.
Binary file modified OnlineBookClub/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified OnlineBookClub/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added books/__pycache__/tests.cpython-311.pyc
Binary file not shown.
Binary file modified db.sqlite3
Binary file not shown.
Binary file added group/__pycache__/tests.cpython-311.pyc
Binary file not shown.
Binary file modified main/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file modified main/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified main/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified main/__pycache__/views.cpython-311.pyc
Binary file not shown.
33 changes: 33 additions & 0 deletions main/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.forms import ModelForm
from .models import *
from datetime import date
from django.forms import ModelForm, TextInput, Textarea, Select


class CreateFeedback(ModelForm):
class Meta:
model = Feedback
fields = ["feedback"]
widgets = {
'feedback': TextInput(attrs={
'placeholder': "add your comment",
'class': "form-control"
}),
}


class CreateReport(ModelForm):
class Meta:
model = Report
topics_choices = Topic.objects.order_by('-id')
fields = ["report", "topic"]
widgets = {
'report': TextInput(attrs={
'placeholder': "add your comment",
'class': "form-control"
}),
'topic': Select(choices=topics_choices, attrs={
'placeholder': "horror",
'class': "form-control"
}),
}
26 changes: 26 additions & 0 deletions main/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.0.2 on 2024-05-15 09:33

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Feedback',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('feedback', models.TextField(max_length=1000)),
('date_created', models.DateTimeField(auto_now_add=True, null=True)),
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
33 changes: 33 additions & 0 deletions main/migrations/0002_topic_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 5.0.2 on 2024-05-19 19:16

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('main', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Topic',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Report',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('report', models.TextField(max_length=1000)),
('date_created', models.DateTimeField(auto_now_add=True, null=True)),
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('topic', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.topic')),
],
),
]
Binary file not shown.
Binary file not shown.
29 changes: 29 additions & 0 deletions main/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
from django.db import models
from django.contrib.auth.models import User


class Topic(models.Model):
name = models.CharField(max_length=200)

def __str__(self):
return self.name


class Feedback(models.Model):
feedback = models.TextField(max_length=1000, blank=False)
user_id = models.ForeignKey(User, blank=False, on_delete=models.CASCADE)
date_created = models.DateTimeField(auto_now_add=True, null=True)

def __str__(self):
return str(self.feedback)



class Report(models.Model):
report = models.TextField(max_length=1000, blank=False)
user_id = models.ForeignKey(User, blank=False, on_delete=models.CASCADE)
topic = models.ForeignKey(Topic, blank=False, on_delete=models.CASCADE)
date_created = models.DateTimeField(auto_now_add=True, null=True)

def __str__(self):
return str(self.report)

33 changes: 33 additions & 0 deletions main/templates/main/feedback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends 'main/layout.html' %}


{% block content %}
<div class="modal modal-sheet position-static d-block bg-body-secondary p-4 py-md-5" tabindex="-1" role="dialog" id="modalSignin">
<div class="modal-dialog" role="document">
<div class="modal-content rounded-4 shadow">
<div class="modal-header p-5 pb-4 border-bottom-0">
<h1 class="fw-bold mb-0 fs-2">Leave your feedback<3</h1>
<a href="{% url 'main:home' %}" >
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">

</button>
</a>
</div>

<div class="modal-body p-5 pt-0">
<form method="post">
{% csrf_token %}
<div class="form-floating mb-3">
{{ form.feedback }}
<label for="floatingInput">Feedback </label>
</div>

<button class="w-100 mb-2 btn btn-lg rounded-3 btn-dark" formaction="feedback"
type="submit">Send</button>

</form>
</div>
</div>
</div>
</div>
{% endblock %}
17 changes: 8 additions & 9 deletions main/templates/main/home.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<!DOCTYPE html>

{% extends 'main/layout.html' %}


{% block content %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>

{% load static %}
<body>

<div class="centered">
<style>
/* Define a CSS rule to target the image */
Expand Down Expand Up @@ -54,6 +50,9 @@ <h1>Your favorite online book club</h1>
You can engage in lively discussions about literature, join reading groups tailored to your interests,
and even participate in exclusive Q&A sessions with your favorite authors. Online Book Club provides
a dynamic space for literary exploration and community building.</p>
</body>
</html>





{% endblock %}
46 changes: 45 additions & 1 deletion main/templates/main/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3">


<!-- Our project just needs Font Awesome Free's Solid and Brand files -->

Expand All @@ -19,6 +21,11 @@
<link href="{% static 'fontawesomefree/css/solid.css' %}" rel="stylesheet" type="text/css">
<script src="https://kit.fontawesome.com/0c08b70a26.js" crossorigin="anonymous"></script>

<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">


</head>
<body>
<header data-bs-theme="dark">
Expand Down Expand Up @@ -105,7 +112,7 @@
<div class="row mt-5 mb-3"></div>
<main class="container">
{% block content %}{% endblock %}
</main>


{% if messages %}
<ul class="messages">
Expand All @@ -116,5 +123,42 @@
</ul>
{% endif %}

<hr class="featurette-divider mt-4">

<!-- /END THE FEATURETTES -->



<footer class="container mt-4 mb-7 text-center" style="padding-bottom: 100px;">



<div class="row mt-4">
<div class="col-md-3">
<h6>Help Us</h6>
<p> <a href="{% url 'main:feedback' %}" class="text-decoration-none text-dark"> Leave feedback</a> </p>
<p> <a href="{% url 'main:report' %}" class="text-decoration-none text-dark">Report a problem</a> </p>
</div>
<div class="col-md-3">
<h6>Contact</h6>
<p>Email: [email protected]</p>
</div>
<div class="col-md-3">
<h6>Follow Us</h6>
<a href="#" class="me-2"><i class="fab fa-facebook"></i></a>
<a href="#" class="me-2"><i class="fab fa-twitter"></i></a>
<a href="#" class="me-2"><i class="fab fa-instagram"></i></a>
</div>
<div class="col-md-3">
<a href="#" class="btn btn-dark ">Back to top</a>
</div>
</div>
<!-- Кінець додаткового контенту -->

</footer>
</main>
<script src="/docs/5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

</body>
</html>
37 changes: 37 additions & 0 deletions main/templates/main/report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends 'main/layout.html' %}


{% block content %}
<div class="modal modal-sheet position-static d-block bg-body-secondary p-4 py-md-5" tabindex="-1" role="dialog" id="modalSignin">
<div class="modal-dialog" role="document">
<div class="modal-content rounded-4 shadow">
<div class="modal-header p-5 pb-4 border-bottom-0">
<h1 class="fw-bold mb-0 fs-2">Create your report</h1>
<a href="{% url 'main:home' %}" >
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">

</button>
</a>
</div>

<div class="modal-body p-5 pt-0">
<form method="post">
{% csrf_token %}
<div class="form-floating mb-3">
{{ form.topic }}
<label for="floatingInput">About </label>
</div>
<div class="form-floating mb-3">
{{ form.report }}
<label for="floatingInput">Problem </label>
</div>

<button class="w-100 mb-2 btn btn-lg rounded-3 btn-dark" formaction="report"
type="submit">Send</button>

</form>
</div>
</div>
</div>
</div>
{% endblock %}
3 changes: 3 additions & 0 deletions main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

urlpatterns = [
path('', views.index, name='home'),
path('feedback', views.feedback_create, name='feedback'),
path('report', views.report_create, name='report'),

]


Expand Down
61 changes: 59 additions & 2 deletions main/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,66 @@
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, get_object_or_404
from .models import *
from .forms import *
from main.keeper_service import keeper_service
from django.utils import timezone

# Create your views here.

### index site ###
def index(request):
return render(request, 'main/home.html')
form = CreateFeedback()
return render(request, 'main/home.html', {'form':form })


def feedback_create(request):
print("request = ", request.POST)
name = request.user
date_created = timezone.now().date
error = ''
form = CreateFeedback(request.POST)

if request.method == 'POST':
form = CreateFeedback(request.POST)
if form.is_valid():
feedback = form.save(commit=False)
feedback.user_id = name
feedback.save()
return redirect('main:home')
else:
error = 'Помилки при заповненні форми'
context = {
'form': form,
'error': error,
'name': name,
'date_created': date_created
}
return render(request, 'main/feedback.html', context)

def report_create(request):
print("request = ", request.POST)
name = request.user
date_created = timezone.now().date
error = ''
form = CreateReport(request.POST)

if request.method == 'POST':
form = CreateReport(request.POST)
if form.is_valid():
report = form.save(commit=False)
report.user_id = name
report.save()
return redirect('main:home')
else:
error = 'Помилки при заповненні форми'
context = {
'form': form,
'error': error,
'name': name,
'date_created': date_created
}
return render(request, 'main/report.html', context)





Binary file added manager/__pycache__/tests.cpython-311.pyc
Binary file not shown.
Binary file modified manager/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified manager/__pycache__/views.cpython-311.pyc
Binary file not shown.
Loading

0 comments on commit f098c8c

Please sign in to comment.