Skip to content

Commit

Permalink
Merge branch 'dev' into passez_votre_chemin_refacto_url_en_cours
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink authored Jul 3, 2022
2 parents 3274d04 + 36550f7 commit fe7dcb4
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 90 deletions.
8 changes: 4 additions & 4 deletions fixtures/advanced/aide_tuto_media.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
- factory: zds.utils.tests.factories.HelpWritingFactory
- factory: zds.tutorialv2.tests.factories.HelpWritingFactory
fields:
title: "Rédacteur"
tablelabel: "Besoin d'aide pour la rédaction"
slug: "redacteur"
fixture_image_path: "aide_redacteur.png"

- factory: zds.utils.tests.factories.HelpWritingFactory
- factory: zds.tutorialv2.tests.factories.HelpWritingFactory
fields:
title: "Correcteur"
tablelabel: "Besoin d'aide pour la correction"
slug: "correcteur"
fixture_image_path: "aide_correcteur.png"

- factory: zds.utils.tests.factories.HelpWritingFactory
- factory: zds.tutorialv2.tests.factories.HelpWritingFactory
fields:
title: "Illustrateur"
tablelabel: "Besoin d'aide pour l'illustration"
slug: "illustrateur"
fixture_image_path: "aide_illustrateur.png"

- factory: zds.utils.tests.factories.HelpWritingFactory
- factory: zds.tutorialv2.tests.factories.HelpWritingFactory
fields:
title: "Repreneur"
tablelabel: "Cherche un repreneur"
Expand Down
2 changes: 2 additions & 0 deletions zds/tutorialv2/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ContentContributionRole,
)
from zds.tutorialv2.models.events import Event
from zds.tutorialv2.models.help_requests import HelpWriting


class PublishableContentAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -119,4 +120,5 @@ class ContentReviewTypeAdmin(admin.ModelAdmin):
admin.site.register(ContentRead, ContentReadAdmin)
admin.site.register(PublicationEvent, PublicationEventAdmin)
admin.site.register(ContentContributionRole, ContentReviewTypeAdmin)
admin.site.register(HelpWriting)
admin.site.register(Event)
2 changes: 1 addition & 1 deletion zds/tutorialv2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from zds.utils.forms import CommonLayoutEditor, CommonLayoutVersionEditor
from zds.utils.models import SubCategory, Licence
from zds.tutorialv2.models import TYPE_CHOICES
from zds.utils.models import HelpWriting
from zds.tutorialv2.models.help_requests import HelpWriting
from zds.tutorialv2.models.database import PublishableContent, ContentContributionRole, ContentSuggestion
from django.utils.translation import gettext_lazy as _
from zds.member.models import Profile
Expand Down
37 changes: 37 additions & 0 deletions zds/tutorialv2/migrations/0033_move_helpwriting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.db import migrations, models

import easy_thumbnails.fields

import zds


class Migration(migrations.Migration):

dependencies = [
("tutorialv2", "0032_event"),
("utils", "0025_move_helpwriting"),
]

state_operations = [
migrations.CreateModel(
name="HelpWriting",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("title", models.CharField(max_length=20, verbose_name="Name")),
("slug", models.SlugField(max_length=20)),
("tablelabel", models.CharField(max_length=150, verbose_name="TableLabel")),
("image", easy_thumbnails.fields.ThumbnailerImageField(upload_to=zds.utils.models.image_path_help)),
],
options={
"verbose_name": "Aide à la rédaction",
"verbose_name_plural": "Aides à la rédaction",
},
),
migrations.AlterField(
model_name="publishablecontent",
name="helps",
field=models.ManyToManyField(blank=True, db_index=True, to="tutorialv2.HelpWriting", verbose_name="Aides"),
),
]

operations = [migrations.SeparateDatabaseAndState(state_operations=state_operations)]
2 changes: 1 addition & 1 deletion zds/tutorialv2/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from zds.forum.models import Topic
from zds.tutorialv2.models.database import PublishableContent, PublishedContent, ContentRead
from zds.tutorialv2.utils import mark_read
from zds.utils.models import HelpWriting
from zds.tutorialv2.models.help_requests import HelpWriting


class SingleContentViewMixin:
Expand Down
3 changes: 2 additions & 1 deletion zds/tutorialv2/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
from zds.tutorialv2.models.versioned import NotAPublicVersion
from zds.tutorialv2.utils import get_content_from_json, BadManifestError, get_blob
from zds.utils import get_current_user
from zds.utils.models import SubCategory, Licence, HelpWriting, Comment, Tag
from zds.utils.models import SubCategory, Licence, Comment, Tag
from zds.tutorialv2.models.help_requests import HelpWriting
from zds.utils.templatetags.emarkdown import render_markdown_stats
from zds.utils.uuslug_wrapper import uuslug

Expand Down
32 changes: 32 additions & 0 deletions zds/tutorialv2/models/help_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.db import models
from easy_thumbnails.fields import ThumbnailerImageField

from zds.utils import old_slugify
from zds.utils.models import image_path_help


class HelpWriting(models.Model):

"""Tutorial Help"""

class Meta:
verbose_name = "Aide à la rédaction"
verbose_name_plural = "Aides à la rédaction"

# A name for this help
title = models.CharField("Name", max_length=20, null=False)
slug = models.SlugField(max_length=20)

# tablelabel: Used for the accessibility "This tutoriel need help for writing"
tablelabel = models.CharField("TableLabel", max_length=150, null=False)

# The image to use to illustrate this role
image = ThumbnailerImageField(upload_to=image_path_help)

def __str__(self):
"""Textual Help Form."""
return self.title

def save(self, *args, **kwargs):
self.slug = old_slugify(self.title)
super().save(*args, **kwargs)
44 changes: 44 additions & 0 deletions zds/tutorialv2/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from datetime import datetime
from os.path import join, basename
from shutil import copyfile

import factory
from django.conf import settings

from zds.forum.tests.factories import PostFactory, TopicFactory
from zds.gallery.tests.factories import GalleryFactory, UserGalleryFactory
from zds.tutorialv2.models.help_requests import HelpWriting
from zds.utils import old_slugify
from zds.utils.tests.factories import LicenceFactory, SubCategoryFactory
from zds.utils.models import Licence
from zds.tutorialv2.models.database import PublishableContent, Validation, ContentReaction
Expand Down Expand Up @@ -255,3 +260,42 @@ class ValidationFactory(factory.django.DjangoModelFactory):

class Meta:
model = Validation


class HelpWritingFactory(factory.django.DjangoModelFactory):
"""
Factory that creates a HelpWriting.
"""

class Meta:
model = HelpWriting

title = factory.Sequence("titre de l'image {}".format)
slug = factory.LazyAttribute(lambda o: f"{old_slugify(o.title)}")
tablelabel = factory.LazyAttribute(lambda n: "Besoin de " + n.title)

@classmethod
def _generate(cls, create, attrs):
# These parameters are only used inside _generate() and won't be saved in the database,
# which is why we use attrs.pop() (they are removed from attrs).
image_path = attrs.pop("image_path", None)
fixture_image_path = attrs.pop("fixture_image_path", None)

help_writing = super()._generate(create, attrs)

if fixture_image_path is not None:
image_path = join(settings.BASE_DIR, "fixtures", fixture_image_path)

if image_path is not None:
copyfile(image_path, settings.MEDIA_ROOT / basename(image_path))
help_writing.image = basename(image_path)
help_writing.save()

return help_writing

@classmethod
def _create(cls, target_class, *args, **kwargs):
kwargs.pop("image_path", None)
kwargs.pop("fixture_image_path", None)

return super()._create(target_class, *args, **kwargs)
6 changes: 4 additions & 2 deletions zds/tutorialv2/tests/tests_views/tests_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
PublishedContentFactory,
tricky_text_content,
BetaContentFactory,
HelpWritingFactory,
)
from zds.tutorialv2.models.database import (
PublishableContent,
Expand All @@ -48,8 +49,9 @@
ZMarkdownEpubPublicator,
)
from zds.tutorialv2.tests import TutorialTestMixin, override_for_contents
from zds.utils.models import HelpWriting, Tag
from zds.utils.tests.factories import HelpWritingFactory, SubCategoryFactory, LicenceFactory
from zds.utils.models import Tag
from zds.tutorialv2.models.help_requests import HelpWriting
from zds.utils.tests.factories import SubCategoryFactory, LicenceFactory
from zds import json_handler


Expand Down
3 changes: 2 additions & 1 deletion zds/tutorialv2/tests/tests_views/tests_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ContainerFactory,
ExtractFactory,
PublishedContentFactory,
HelpWritingFactory,
)
from zds.tutorialv2.models.database import (
PublishableContent,
Expand All @@ -30,7 +31,7 @@
from zds.tutorialv2.publication_utils import publish_content
from zds.tutorialv2.tests import TutorialTestMixin
from zds.utils.models import Alert, Tag, Hat
from zds.utils.tests.factories import CategoryFactory, SubCategoryFactory, LicenceFactory, HelpWritingFactory
from zds.utils.tests.factories import CategoryFactory, SubCategoryFactory, LicenceFactory
from zds.utils.header_notifications import get_header_notifications
from copy import deepcopy
from zds import json_handler
Expand Down
4 changes: 3 additions & 1 deletion zds/tutorialv2/views/authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def form_valid(self, form):
self.object.validation_private_message.add_participant(user)
all_authors_pk.append(user.pk)
if user != self.request.user:
url_index = reverse(self.object.type.lower() + ":find-" + self.object.type.lower(), args=[user.pk])
url_index = reverse(
self.object.type.lower() + ":find-" + self.object.type.lower(), args=[user.username]
)
send_mp(
bot,
[user],
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/views/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from zds.tutorialv2.mixins import SingleContentFormViewMixin

from zds.tutorialv2.models.database import PublishableContent
from zds.utils.models import HelpWriting
from zds.tutorialv2.models.help_requests import HelpWriting
from zds.utils.paginator import ZdSPagingListView


Expand Down
2 changes: 0 additions & 2 deletions zds/utils/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
SubCategory,
CategorySubCategory,
Tag,
HelpWriting,
CommentEdit,
Hat,
HatRequest,
Expand Down Expand Up @@ -60,7 +59,6 @@ class HatRequestAdmin(admin.ModelAdmin):
admin.site.register(Category)
admin.site.register(SubCategory, SubCategoryAdmin)
admin.site.register(CategorySubCategory)
admin.site.register(HelpWriting)
admin.site.register(CommentEdit, CommentEditAdmin)
admin.site.register(Hat, HatAdmin)
admin.site.register(HatRequest, HatRequestAdmin)
3 changes: 2 additions & 1 deletion zds/utils/management/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from django.contrib.auth.models import User, Permission
from zds.member.models import Profile
from zds.forum.models import Forum, Topic, ForumCategory
from zds.utils.models import Tag, Category as TCategory, CategorySubCategory, SubCategory, HelpWriting, Licence
from zds.utils.models import Tag, Category as TCategory, CategorySubCategory, SubCategory, Licence
from zds.tutorialv2.models.help_requests import HelpWriting
from zds.member.tests.factories import ProfileFactory
from zds.tutorialv2.models.database import (
PublishableContent,
Expand Down
14 changes: 14 additions & 0 deletions zds/utils/migrations/0025_move_helpwriting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [("utils", "0024_alter_hatrequest_is_granted")]

database_operations = [migrations.AlterModelTable("HelpWriting", "tutorialv2_helpwriting")]

state_operations = [migrations.DeleteModel("HelpWriting")]

operations = [
migrations.SeparateDatabaseAndState(database_operations=database_operations, state_operations=state_operations)
]
29 changes: 0 additions & 29 deletions zds/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from django.dispatch import receiver
from django.template.loader import render_to_string

from easy_thumbnails.fields import ThumbnailerImageField

from zds.utils import signals
from zds.mp.models import PrivateTopic
from zds.tutorialv2.models import TYPE_CHOICES, TYPE_CHOICES_DICT
Expand Down Expand Up @@ -790,30 +788,3 @@ def has_read_permission(request):

def has_object_read_permission(self, request):
return True


class HelpWriting(models.Model):

"""Tutorial Help"""

class Meta:
verbose_name = "Aide à la rédaction"
verbose_name_plural = "Aides à la rédaction"

# A name for this help
title = models.CharField("Name", max_length=20, null=False)
slug = models.SlugField(max_length=20)

# tablelabel: Used for the accessibility "This tutoriel need help for writing"
tablelabel = models.CharField("TableLabel", max_length=150, null=False)

# The image to use to illustrate this role
image = ThumbnailerImageField(upload_to=image_path_help)

def __str__(self):
"""Textual Help Form."""
return self.title

def save(self, *args, **kwargs):
self.slug = old_slugify(self.title)
super().save(*args, **kwargs)
47 changes: 1 addition & 46 deletions zds/utils/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
from os.path import basename, join
from shutil import copyfile

import factory

from django.conf import settings

from zds.utils.models import HelpWriting, Category, SubCategory, CategorySubCategory, Licence
from zds.utils import old_slugify


class HelpWritingFactory(factory.django.DjangoModelFactory):
"""
Factory that creates a HelpWriting.
"""

class Meta:
model = HelpWriting

title = factory.Sequence("titre de l'image {}".format)
slug = factory.LazyAttribute(lambda o: f"{old_slugify(o.title)}")
tablelabel = factory.LazyAttribute(lambda n: "Besoin de " + n.title)

@classmethod
def _generate(cls, create, attrs):
# These parameters are only used inside _generate() and won't be saved in the database,
# which is why we use attrs.pop() (they are removed from attrs).
image_path = attrs.pop("image_path", None)
fixture_image_path = attrs.pop("fixture_image_path", None)

help_writing = super()._generate(create, attrs)

if fixture_image_path is not None:
image_path = join(settings.BASE_DIR, "fixtures", fixture_image_path)

if image_path is not None:
copyfile(image_path, settings.MEDIA_ROOT / basename(image_path))
help_writing.image = basename(image_path)
help_writing.save()

return help_writing

@classmethod
def _create(cls, target_class, *args, **kwargs):
kwargs.pop("image_path", None)
kwargs.pop("fixture_image_path", None)

return super()._create(target_class, *args, **kwargs)
from zds.utils.models import Category, SubCategory, CategorySubCategory, Licence


class CategoryFactory(factory.django.DjangoModelFactory):
Expand Down

0 comments on commit fe7dcb4

Please sign in to comment.