Commit 34366f6a authored by Volkov Gherman's avatar Volkov Gherman

Заввершил проект курсовой работы News

parent fad0df08
.idea
venv
*.sqlite3
__pycache__
**.pyc
Проект с кодовым названием NEWS, нужно склонировать, установить зависимости из файла requirements.txt, загрузить фикстуры Проект с кодовым названием NEWS, нужно склонировать, установить зависимости из файла requirements.txt, загрузить фикстуры.
\ No newline at end of file
Админ - log - admin
pass - admin12345
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<form action="{% url 'accounts:password_change_done' request.user.pk %}" method="post"> <form action="{% url 'accounts:password_change_done' request.user.pk %}" method="post">
{% csrf_token %} {% csrf_token %}
{{ form|crispy }} {{ form|crispy }}
<button class="btn btn-outline-dark log_btn" type="submit">Login</button> <button class="btn btn-outline-dark log_btn" type="submit">Change</button>
</form> </form>
</div> </div>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.contrib.auth.views import LoginView, LogoutView, PasswordChangeView from django.contrib.auth.views import LoginView, LogoutView, PasswordChangeView
from django.urls import path from django.urls import path, reverse_lazy
from accounts.views import RegisterView from accounts.views import RegisterView
...@@ -9,5 +9,5 @@ urlpatterns = [ ...@@ -9,5 +9,5 @@ urlpatterns = [
path("account/login/", LoginView.as_view(), name="login"), path("account/login/", LoginView.as_view(), name="login"),
path("account/logout/", LogoutView.as_view(), name="logout"), path("account/logout/", LogoutView.as_view(), name="logout"),
path("account/registration/", RegisterView.as_view(), name="register"), path("account/registration/", RegisterView.as_view(), name="register"),
path("account/<int:pk>/change_password", PasswordChangeView.as_view(), name="password_change_done"), path("account/<int:pk>/change_password", PasswordChangeView.as_view(success_url=reverse_lazy('accounts:password_change_done')), name="password_change_done"),
] ]
No preview for this file type
body { body {
margin: 0; margin: 0;
}
footer {
position: absolute;
bottom: 0;
right: 0;
left: 0;
} }
/*BASE*/ /*BASE*/
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
{% csrf_token %} {% csrf_token %}
<button class="btn text-dark btn-link" title="Logout"><i class="bi bi-door-closed icon"></i></button> <button class="btn text-dark btn-link" title="Logout"><i class="bi bi-door-closed icon"></i></button>
</form> </form>
{% if requert.user.is_superuser %} {% if request.user.is_superuser %}
<a style="margin-right: 10px;" href="{% url "webapp:post_create" %}" class="text-dark" title="Add post"><i class="bi bi-file-plus icon"></i></a> <a style="margin-right: 10px;" href="{% url "webapp:post_create" %}" class="text-dark" title="Add post"><i class="bi bi-file-plus icon"></i></a>
{% endif %} {% endif %}
<a style="margin-right: 10px;" href="{% url "accounts:password_change_done" request.user.pk %}" class="text-dark" title="Change password"><i class="bi bi-pencil icon"></i></a> <a style="margin-right: 10px;" href="{% url "accounts:password_change_done" request.user.pk %}" class="text-dark" title="Change password"><i class="bi bi-pencil icon"></i></a>
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<p class="card-text post_d_text">{{ post.text }}</p> <p class="card-text post_d_text">{{ post.text }}</p>
<hr> <hr>
<p class="card-text"><i>{{ post.create }}</i></p> <p class="card-text"><i>{{ post.create }}</i></p>
{% if request.user.is_superuser %}
<p> Active?: {{ post.is_active }}</p>
{% endif %}
<a href="{% url 'webapp:post_detail' post.pk %}" class="btn btn-outline-dark">In detail..</a> <a href="{% url 'webapp:post_detail' post.pk %}" class="btn btn-outline-dark">In detail..</a>
</div> </div>
</div> </div>
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<p class="card-text post_d_text">{{ post.text }}</p> <p class="card-text post_d_text">{{ post.text }}</p>
<hr> <hr>
<p class="card-text"><i>{{ post.create }}</i></p> <p class="card-text"><i>{{ post.create }}</i></p>
{% if request.user.is_superuser %}
<p> Active?: {{ post.is_active }}</p>
{% endif %}
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
<div class="post_d_buttons"> <div class="post_d_buttons">
<a href="{% url 'webapp:post_update' post.pk %}" class="btn btn-outline-dark">Update</a> <a href="{% url 'webapp:post_update' post.pk %}" class="btn btn-outline-dark">Update</a>
...@@ -32,8 +35,8 @@ ...@@ -32,8 +35,8 @@
<div class="toast comment_container" role="alert" aria-live="assertive" aria-atomic="true"> <div class="toast comment_container" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header com_header"> <div class="toast-header com_header">
{# <img src="..." class="rounded mr-2" alt="...">#}
{% if request.user.is_superuser %} {% if request.user.is_superuser or comment.author == request.user %}
{% include 'comment/comment_delete.html' %} {% include 'comment/comment_delete.html' %}
{% endif %} {% endif %}
<strong class="mr-auto">{{ comment.author }}</strong> <strong class="mr-auto">{{ comment.author }}</strong>
......
...@@ -17,8 +17,10 @@ class PostListView(ListView): ...@@ -17,8 +17,10 @@ class PostListView(ListView):
paginate_by = 10 paginate_by = 10
def get_queryset(self): def get_queryset(self):
if self.request.user.is_superuser:
queryset = super().get_queryset().filter(is_active=True) queryset = super().get_queryset().filter(is_active=True)
return queryset return queryset
return super().get_queryset()
class PostDetailView(DetailView): class PostDetailView(DetailView):
...@@ -93,7 +95,8 @@ class CommentDeleteView(PermissionRequiredMixin, DeleteView): ...@@ -93,7 +95,8 @@ class CommentDeleteView(PermissionRequiredMixin, DeleteView):
permission_required = 'webapp.delete_comment' permission_required = 'webapp.delete_comment'
def has_permission(self): def has_permission(self):
return super().has_permission() or self.object == self.request.user self.object = self.get_object()
return super().has_permission() or self.object.author == self.request.user
def get_success_url(self): def get_success_url(self):
return reverse('webapp:post_detail', kwargs={"pk": self.object.post.pk}) return reverse('webapp:post_detail', kwargs={"pk": self.object.post.pk})
...@@ -117,7 +120,7 @@ class SearchView(ListView): ...@@ -117,7 +120,7 @@ class SearchView(ListView):
return context return context
def get_queryset(self): def get_queryset(self):
query_set = super().get_queryset() query_set = super().get_queryset().filter(is_active=True)
if self.search_value: if self.search_value:
query = Q(title__icontains=self.search_value) | Q(text__icontains=self.search_value) query = Q(title__icontains=self.search_value) | Q(text__icontains=self.search_value)
query_set = query_set.filter(query) query_set = query_set.filter(query)
......
Markdown is supported
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