-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5999020
commit aa06701
Showing
41 changed files
with
799 additions
and
229 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
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,38 @@ | ||
from django.contrib import admin | ||
|
||
from lacommunaute.documentation.models import Category, Document, DocumentRating | ||
from lacommunaute.forum.models import Forum | ||
|
||
|
||
class DocumentInlines(admin.TabularInline): | ||
model = Document | ||
extra = 0 | ||
fields = ("name", "short_description") | ||
readonly_fields = ("name", "short_description") | ||
|
||
def has_delete_permission(self, request, obj=None): | ||
return False | ||
|
||
def has_add_permission(self, request, obj=None): | ||
return False | ||
|
||
@admin.register(Category) | ||
class CategoryAdmin(admin.ModelAdmin): | ||
list_display = ("name",) | ||
search_fields = ("name",) | ||
fields = ("name", "short_description", "description", "image") | ||
inlines = [DocumentInlines] | ||
|
||
@admin.register(Document) | ||
class DocumentAdmin(admin.ModelAdmin): | ||
list_display = ("name","category") | ||
list_filter = ("category",) | ||
search_fields = ("name",) | ||
fields = ("name", "short_description", "description", "image") | ||
|
||
@admin.register(DocumentRating) | ||
class DocumentRatingAdmin(admin.ModelAdmin): | ||
list_display = ("document", "rating", "created_at") | ||
list_filter = ("document",) | ||
list_display_links = ("rating",) | ||
raw_id_fields = ("document", "user") |
81 changes: 81 additions & 0 deletions
81
lacommunaute/documentation/management/commands/rearrange_documentation.py
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,81 @@ | ||
|
||
|
||
from django.contrib.contenttypes.models import ContentType | ||
from taggit.models import TaggedItem | ||
|
||
from lacommunaute.documentation.models import Category, Document, DocumentRating | ||
from lacommunaute.forum.models import Forum, ForumRating | ||
from lacommunaute.forum_conversation.models import Topic | ||
from lacommunaute.forum_upvote.models import UpVote | ||
from lacommunaute.stats.models import DocumentStat, ForumStat | ||
|
||
|
||
def create_categories_from_catforums(): | ||
transpo_dict = {} | ||
for forum in Forum.objects.filter(type=1, level=0): | ||
category = Category.objects.create( | ||
name=forum.name, | ||
short_description=forum.short_description, | ||
description=forum.description, | ||
image=forum.image, | ||
) | ||
print(f"{category} created") | ||
transpo_dict[forum] = category | ||
return transpo_dict | ||
|
||
|
||
def create_document_from_forums(category_transpo_dict): | ||
forum_content_type = ContentType.objects.get_for_model(Forum) | ||
document_content_type = ContentType.objects.get_for_model(Document) | ||
transpo_dict = {} | ||
for forum in Forum.objects.filter(parent__type=1): | ||
document = Document.objects.create( | ||
name=forum.name, | ||
short_description=forum.short_description, | ||
description=forum.description, | ||
image=forum.image, | ||
category = category_transpo_dict[forum.parent], | ||
partner = forum.partner, | ||
certified = forum.certified, | ||
) | ||
UpVote.objects.filter(content_type=forum_content_type, object_id=forum.id).update(content_type=document_content_type, object_id=document.id) | ||
TaggedItem.objects.filter(content_type=forum_content_type, object_id=forum.id).update(content_type=document_content_type, object_id=document.id) | ||
transpo_dict[forum] = document | ||
print('Documents created') | ||
return transpo_dict | ||
|
||
def migrate_ratings(document_transpo_dict): | ||
document_ratings = [DocumentRating(document=document_transpo_dict[rating.forum], session_id=rating.session_id, rating=rating.rating, user=rating.user, created_at=rating.created, updated_at=rating.updated) for rating in ForumRating.objects.all()] | ||
DocumentRating.objects.bulk_create(document_ratings) | ||
ForumRating.objects.all().delete() | ||
print(f"{len(document_ratings)} ratings migrated") | ||
|
||
def link_topics(document_transpo_dict): | ||
main_forum = Forum.objects.get_main_forum() | ||
for forum, document in document_transpo_dict.items(): | ||
topics = Topic.objects.filter(forum=forum) | ||
topics.update(document=document, forum=main_forum) | ||
for topic in topics: | ||
topic.save() | ||
forum.save() | ||
print('Topics linked to documents') | ||
|
||
def convert_stats(document_transpo_dict): | ||
document_stats = [DocumentStat(document=document_transpo_dict[stat.forum], date=stat.date, period=stat.period, visits=stat.visits, entry_visits=stat.entry_visits, time_spent=stat.time_spent) for stat in ForumStat.objects.all()] | ||
|
||
def add_redirections(): | ||
# for categories | ||
# for documents | ||
pass | ||
|
||
def del_forums(): | ||
#categories | ||
#documents | ||
pass | ||
|
||
|
||
# main | ||
category_transpo_dict = create_categories_from_catforums() | ||
document_transpo_dict = create_document_from_forums(category_transpo_dict) | ||
migrate_ratings(document_transpo_dict) | ||
link_topics(document_transpo_dict) |
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,81 @@ | ||
# Generated by Django 5.0.9 on 2024-09-11 13:48 | ||
|
||
import django.db.models.deletion | ||
import lacommunaute.utils.validators | ||
import machina.models.fields | ||
import storages.backends.s3 | ||
import taggit.managers | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("documentation", "0002_alter_category_options"), | ||
("partner", "0002_alter_partner_options"), | ||
("taggit", "0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Document", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("name", models.CharField(max_length=100, verbose_name="Name")), | ||
("slug", models.SlugField(max_length=255, unique=True, verbose_name="Slug")), | ||
( | ||
"description", | ||
machina.models.fields.MarkupTextField( | ||
blank=True, no_rendered_field=True, null=True, verbose_name="Description" | ||
), | ||
), | ||
( | ||
"short_description", | ||
models.CharField(blank=True, max_length=400, null=True, verbose_name="Description courte (SEO)"), | ||
), | ||
( | ||
"image", | ||
models.ImageField( | ||
storage=storages.backends.s3.S3Storage(bucket_name="private-bucket", file_overwrite=False), | ||
upload_to="", | ||
validators=[lacommunaute.utils.validators.validate_image_size], | ||
), | ||
), | ||
( | ||
"certified", | ||
models.BooleanField(default=False, verbose_name="Certifié par la communauté de l'inclusion"), | ||
), | ||
("_description_rendered", models.TextField(blank=True, editable=False, null=True)), | ||
( | ||
"category", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="documents", | ||
to="documentation.category", | ||
), | ||
), | ||
( | ||
"partner", | ||
models.ForeignKey( | ||
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="partner.partner" | ||
), | ||
), | ||
( | ||
"tags", | ||
taggit.managers.TaggableManager( | ||
help_text="A comma-separated list of tags.", | ||
through="taggit.TaggedItem", | ||
to="taggit.Tag", | ||
verbose_name="Tags", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Document", | ||
"verbose_name_plural": "Documents", | ||
"ordering": ["-created_at"], | ||
}, | ||
), | ||
] |
41 changes: 41 additions & 0 deletions
41
lacommunaute/documentation/migrations/0004_documentrating.py
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,41 @@ | ||
# Generated by Django 5.0.9 on 2024-09-12 14:14 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("documentation", "0003_document"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="DocumentRating", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("session_id", models.CharField(max_length=40)), | ||
("rating", models.PositiveSmallIntegerField()), | ||
( | ||
"document", | ||
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="documentation.document"), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Notation d'un document", | ||
"verbose_name_plural": "Notations des documents", | ||
"ordering": ("-created_at",), | ||
}, | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
lacommunaute/documentation/migrations/0005_alter_documentrating_created_at_and_more.py
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,23 @@ | ||
# Generated by Django 5.0.9 on 2024-09-12 14:20 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("documentation", "0004_documentrating"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="documentrating", | ||
name="created_at", | ||
field=models.DateTimeField(blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="documentrating", | ||
name="updated_at", | ||
field=models.DateTimeField(blank=True, null=True), | ||
), | ||
] |
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,13 @@ | ||
from django.urls import path | ||
|
||
from lacommunaute.documentation.views import CategoryDetailView, CategoryListView, DocumentDetailView | ||
|
||
|
||
app_name = "documentation" | ||
|
||
|
||
urlpatterns = [ | ||
path("", CategoryListView.as_view(), name="category_list"), | ||
path("<str:slug>-<int:pk>/", CategoryDetailView.as_view(), name="category_detail"), | ||
path("<str:category_slug>-<int:category_pk>/<str:slug>-<int:pk>/", DocumentDetailView.as_view(), name="document_detail"), | ||
] |
Oops, something went wrong.