Skip to content

Commit

Permalink
add inactive projects page accessible by staff
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulkireev committed Jun 12, 2024
1 parent 24ee234 commit 8fdeaab
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
10 changes: 9 additions & 1 deletion projects/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from django.urls import path

from .views import CommentCreateView, ProjectCreateView, ProjectDetailView, ProjectListView, ProjectUpdateView
from .views import (
CommentCreateView,
InactiveProjectListView,
ProjectCreateView,
ProjectDetailView,
ProjectListView,
ProjectUpdateView,
)

urlpatterns = [
path("", ProjectListView.as_view(), name="projects"),
path("inactive", InactiveProjectListView.as_view(), name="inactive-projects"),
path("<slug:slug>", ProjectDetailView.as_view(), name="project"),
path(
"<slug:slug>/update",
Expand Down
13 changes: 11 additions & 2 deletions projects/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.messages.views import SuccessMessageMixin
from django.db.models import Count, Q
from django.urls import reverse, reverse_lazy
from django.views.generic import CreateView, DetailView, UpdateView
from django.views.generic import CreateView, DetailView, ListView, UpdateView
from django_filters.views import FilterView
from django_q.tasks import async_task

Expand Down Expand Up @@ -48,6 +48,15 @@ def get_context_data(self, **kwargs):
return context


class InactiveProjectListView(LoginRequiredMixin, UserPassesTestMixin, ListView):
model = Project
template_name = "projects/all_inactive_projects.html"
queryset = Project.objects.filter(published=True, active=False)

def test_func(self):
return self.request.user.is_staff


class ProjectDetailView(DetailView):
model = Project
template_name = "projects/project_detail.html"
Expand Down
79 changes: 79 additions & 0 deletions templates/projects/all_inactive_projects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{% extends "base.html" %}
{% load static %}
{% load widget_tweaks %}

{% block content %}
<div class="px-6 py-20 bg-white sm:py-24 lg:px-8">
<div class="max-w-2xl mx-auto text-center">
<h1 class="text-4xl font-bold tracking-tight text-gray-900 sm:text-6xl">Inactive Django Projects</h1>
</div>
</div>

<div>
<div class="grid grid-cols-1 gap-6 mb-10 lg:grid-cols-3 md:grid-cols-2">
{% for site in objects %}
<div class="flex flex-col justify-start bg-white border-solid rounded shadow border-1">
<div class="border-b border-gray-300 border-solid rounded-t-lg">
<a href="{% url 'project' site.slug %}">
<img class="object-cover object-left-top w-full h-auto border-0 rounded-t"
src="{% get_media_prefix %}{{ site.homepage_screenshot }}"
alt="{{ site.title }} | Screenshot"/>
</a>
</div>
<div class="flex-auto h-full p-4 border-b border-gray-300 border-solid">
<h2 class="mb-2 text-lg font-semibold text-gray-900">
<a href="{% url 'project' site.slug %}">{{ site.title }}</a>
</h2>
<p class="text-sm leading-normal text-grey-700">
{{ site.short_description }}
</p>
</div>
<div class="flex items-center justify-between px-4 py-2">
<div>
<a class="inline-block p-2 text-xl bg-gray-200 border border-gray-200 rounded-lg hover:bg-gray-300"
href="{{ site.url }}?ref={{ request.get_host }}"
target="_blank">
<i class="las la-link"></i>
</a>
{% if site.github_url %}
<a class="inline-block p-2 text-xl bg-gray-200 border border-gray-200 rounded-lg hover:bg-gray-300"
href="{{ site.github_url }}?ref={{ request.get_host }}"
target="_blank">
<i class="lab la-github"></i>
</a>
{% endif %}
{% if site.twitter_url %}
<a class="inline-block p-2 text-xl bg-gray-200 border border-gray-200 rounded-lg hover:bg-gray-300"
href="{{ site.twitter_url }}?ref={{ request.get_host }}"
target="_blank">
<i class="lab la-twitter"></i>
</a>
{% endif %}
</div>

{% include "components/project-likes.html" with site=site %}

</div>
</div>
{% endfor %}
</div>
</div>
{% endblock content %}
{% block schema %}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "Projects Built with Django",
"description": "Collection of cool projects people built with Django",
"thumbnailUrl": "https://{{ request.get_host }}{% static 'vendors/images/logo.png' %}",
"url": "https://{{ request.get_host }}/",
"author": {
"@type": "Person",
"givenName": "Rasul",
"familyName": "Kireev",
"url": "https://rasulkireev.com/"
}
}
</script>
{% endblock schema %}

0 comments on commit 8fdeaab

Please sign in to comment.