feat: change entire downloads
This commit is contained in:
+2
-1
@@ -23,7 +23,8 @@ class FAQEntryAdmin(admin.ModelAdmin):
|
||||
search_fields = ("question", "answer")
|
||||
list_editable = ("order", "is_active")
|
||||
fieldsets = (
|
||||
(None, {"fields": ("question", "answer")}),
|
||||
(None, {"fields": ("question",)}),
|
||||
("Answer", {"fields": ("answer_format", "answer")}),
|
||||
("Settings", {"fields": ("order", "is_active")}),
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0.2 on 2026-05-14 05:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pages', '0002_contactsubmission'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='faqentry',
|
||||
name='answer_format',
|
||||
field=models.CharField(choices=[('plain', 'Plain Text'), ('markdown', 'Markdown'), ('html', 'HTML')], default='plain', max_length=20),
|
||||
),
|
||||
]
|
||||
@@ -1,5 +1,7 @@
|
||||
from django.db import models
|
||||
|
||||
from apps.core.utils import CONTENT_FORMAT_CHOICES, FORMAT_PLAIN, render_content
|
||||
|
||||
|
||||
class ContactSubmission(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
@@ -21,6 +23,9 @@ class ContactSubmission(models.Model):
|
||||
class FAQEntry(models.Model):
|
||||
question = models.CharField(max_length=500)
|
||||
answer = models.TextField()
|
||||
answer_format = models.CharField(
|
||||
max_length=20, choices=CONTENT_FORMAT_CHOICES, default=FORMAT_PLAIN
|
||||
)
|
||||
order = models.PositiveIntegerField(default=0)
|
||||
is_active = models.BooleanField(default=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
@@ -34,6 +39,10 @@ class FAQEntry(models.Model):
|
||||
def __str__(self):
|
||||
return self.question
|
||||
|
||||
@property
|
||||
def rendered_answer(self):
|
||||
return render_content(self.answer, self.answer_format)
|
||||
|
||||
|
||||
class DownloadItem(models.Model):
|
||||
PLATFORM_WINDOWS = "windows"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from apps.pages.models import DownloadItem, FAQEntry
|
||||
from apps.pages.models import FAQEntry
|
||||
|
||||
|
||||
class HomeViewTest(TestCase):
|
||||
@@ -24,42 +24,6 @@ class AboutViewTest(TestCase):
|
||||
self.assertTemplateUsed(response, "pages/about.html")
|
||||
|
||||
|
||||
class DownloadsViewTest(TestCase):
|
||||
def setUp(self):
|
||||
DownloadItem.objects.create(
|
||||
name="Radiuma Desktop",
|
||||
platform="windows",
|
||||
version="1.0",
|
||||
download_url="https://example.com/windows",
|
||||
is_active=True,
|
||||
)
|
||||
DownloadItem.objects.create(
|
||||
name="Radiuma Desktop",
|
||||
platform="macos",
|
||||
version="Coming Soon",
|
||||
download_url="#",
|
||||
is_active=False,
|
||||
)
|
||||
|
||||
def test_downloads_returns_200(self):
|
||||
response = self.client.get(reverse("pages:downloads"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_downloads_uses_correct_template(self):
|
||||
response = self.client.get(reverse("pages:downloads"))
|
||||
self.assertTemplateUsed(response, "pages/downloads.html")
|
||||
|
||||
def test_downloads_context_has_platform_keys(self):
|
||||
response = self.client.get(reverse("pages:downloads"))
|
||||
self.assertIn("windows_items", response.context)
|
||||
self.assertIn("macos_items", response.context)
|
||||
self.assertIn("linux_items", response.context)
|
||||
|
||||
def test_windows_item_in_context(self):
|
||||
response = self.client.get(reverse("pages:downloads"))
|
||||
self.assertEqual(response.context["windows_items"].count(), 1)
|
||||
|
||||
|
||||
class FAQViewTest(TestCase):
|
||||
def setUp(self):
|
||||
FAQEntry.objects.create(
|
||||
@@ -107,8 +71,12 @@ class NavigationContextTest(TestCase):
|
||||
reverse("pages:about"),
|
||||
reverse("pages:faq"),
|
||||
reverse("pages:contact"),
|
||||
reverse("pages:downloads"),
|
||||
reverse("products:overview"),
|
||||
]
|
||||
for url in urls:
|
||||
response = self.client.get(url)
|
||||
self.assertIn("nav_main_products", response.context, f"Missing nav_main_products at {url}")
|
||||
self.assertIn(
|
||||
"nav_main_products",
|
||||
response.context,
|
||||
f"Missing nav_main_products at {url}",
|
||||
)
|
||||
|
||||
@@ -7,7 +7,6 @@ app_name = "pages"
|
||||
urlpatterns = [
|
||||
path("", views.HomeView.as_view(), name="home"),
|
||||
path("about/", views.AboutView.as_view(), name="about"),
|
||||
path("downloads/", views.DownloadsView.as_view(), name="downloads"),
|
||||
path("faq/", views.FAQView.as_view(), name="faq"),
|
||||
path("contact/", views.ContactView.as_view(), name="contact"),
|
||||
]
|
||||
|
||||
+1
-19
@@ -6,7 +6,7 @@ from django.views import View
|
||||
from django.views.generic import ListView, TemplateView
|
||||
|
||||
from .forms import ContactForm
|
||||
from .models import ContactSubmission, DownloadItem, FAQEntry
|
||||
from .models import ContactSubmission, FAQEntry
|
||||
|
||||
|
||||
class HomeView(TemplateView):
|
||||
@@ -17,24 +17,6 @@ class AboutView(TemplateView):
|
||||
template_name = "pages/about.html"
|
||||
|
||||
|
||||
class DownloadsView(ListView):
|
||||
template_name = "pages/downloads.html"
|
||||
context_object_name = "download_items"
|
||||
|
||||
def get_queryset(self):
|
||||
return DownloadItem.objects.filter(is_active=True).order_by("order", "platform")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
all_items = DownloadItem.objects.order_by("order", "platform")
|
||||
context["windows_items"] = all_items.filter(
|
||||
platform=DownloadItem.PLATFORM_WINDOWS
|
||||
)
|
||||
context["macos_items"] = all_items.filter(platform=DownloadItem.PLATFORM_MACOS)
|
||||
context["linux_items"] = all_items.filter(platform=DownloadItem.PLATFORM_LINUX)
|
||||
return context
|
||||
|
||||
|
||||
class FAQView(ListView):
|
||||
model = FAQEntry
|
||||
template_name = "pages/faq.html"
|
||||
|
||||
Reference in New Issue
Block a user