-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
help category detail page and management command
- Loading branch information
Showing
8 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.utils.text import slugify | ||
from faker import Faker | ||
import random | ||
|
||
from ...models import Article, Category | ||
|
||
fake = Faker() | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Populate the database with sample data for Help Articles model" | ||
|
||
def handle(self, *args, **kwargs): | ||
categories = Category.objects.all() | ||
for _ in range(50): | ||
title = fake.sentence(nb_words=5) | ||
slug = slugify(title) | ||
content = fake.paragraph(nb_sentences=10) | ||
category = random.choice(categories) | ||
|
||
Article.objects.create( | ||
title=title, | ||
slug=slug, | ||
content=content, | ||
category=category, | ||
) | ||
self.stdout.write(self.style.SUCCESS("Successfully added 50 Help Articles")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 5.0.2 on 2024-03-06 09:53 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("help", "0002_article_category"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="article", | ||
name="category", | ||
field=models.ForeignKey( | ||
help_text="Category linked to this Help Article.", | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="articles", | ||
to="help.category", | ||
verbose_name="category", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,53 @@ | ||
from django.test import TestCase | ||
# from django.test import TestCase | ||
# from django.urls import reverse | ||
# from django.utils.text import slugify | ||
|
||
# Create your tests here. | ||
# from .models import Category | ||
# from apps.help.management.commands.populate_categories import Command as PopulateCategoriesCommand | ||
|
||
|
||
# class CategoryModelTests(TestCase): | ||
|
||
# def setUp(self): | ||
# self.category_data = { | ||
# "name": "Test Category", | ||
# "slug": "test-category", | ||
# "description": "This is a test category.", | ||
# "icon": "test-icon", | ||
# } | ||
|
||
# def test_category_creation(self): | ||
# category = Category.objects.create(**self.category_data) | ||
# self.assertEqual(category.name, "Test Category") | ||
# self.assertEqual(category.slug, "test-category") | ||
# self.assertEqual(category.description, "This is a test category.") | ||
# self.assertEqual(category.icon, "test-icon") | ||
|
||
# def test_get_absolute_url(self): | ||
# category = Category.objects.create(**self.category_data) | ||
# url = reverse("help:category", kwargs={"slug": category.slug}) | ||
# self.assertEqual(category.get_absolute_url(), url) | ||
|
||
# def test_get_article_count(self): | ||
# category = Category.objects.create(**self.category_data) | ||
# # Assuming you have an 'Article' model, you need to import it | ||
# from apps.help.models import Article | ||
|
||
# Article.objects.create(category=category, title="Test Article", content="Article content") | ||
# self.assertEqual(category.get_article_count(), 1) | ||
|
||
|
||
# class PopulateCategoriesCommandTests(TestCase): | ||
|
||
# def test_populate_categories_command(self): | ||
# command = PopulateCategoriesCommand() | ||
# command.handle() | ||
|
||
# # Check if the categories have been created | ||
# self.assertEqual(Category.objects.count(), 6) | ||
|
||
# # Check if the icon field is chosen from the provided list | ||
# icons = [category.icon for category in Category.objects.all()] | ||
# self.assertIn(icons[0], ["user", "cog", "file", "question", "lock", "chart-bar"]) | ||
|
||
# # Add more assertions as needed based on your specific requirements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<a href="{# article.get_absolute_url #}" class="text-decoration-none"><i | ||
class="fa-solid fa-file-lines me-2"></i>{{ article.title }}</a> | ||
<a href="{# article.get_absolute_url #}" | ||
class="link-offset-2 link-offset-3-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover"><i | ||
class="fa-solid fa-file-lines me-2"></i>{{ article.title }}</a> |