Les utilitaires (utils/
)¶
Module situé dans zds/utils/
. Il regroupe certaines fonctions et objets utiles à tout les autres modules.
Fichiers documentés :
Modèles (models.py
)¶
-
class
zds.utils.models.
Alert
(*args, **kwargs)¶ Alerts on all kinds of Comments and PublishedContents.
-
get_comment_subclass
()¶ Used to retrieve comment URLs (simple call to get_absolute_url doesn’t work: objects are retrived as Comment and not subclasses) As real Comment implementation (subclasses) can’t be hard-coded due to unresolvable import loops, use InheritanceManager from django-model- utils.
-
-
class
zds.utils.models.
Category
(*args, **kwargs)¶ Common category for several concepts of the application.
-
class
zds.utils.models.
CategorySubCategory
(*args, **kwargs)¶ ManyToMany between Category and SubCategory but save a boolean to know if category is his main category.
-
class
zds.utils.models.
Comment
(*args, **kwargs)¶ Comment in forum, articles, tutorial, chapter, etc.
-
get_dislikers
()¶ Get the list of the users that disliked this Comment
-
get_likers
()¶ Get the list of the users that liked this Comment
-
get_user_vote
(user)¶ Get a user vote (like, dislike or neutral)
-
get_votes
(type=None)¶ Get the non-anonymous votes
-
hide_comment_by_user
(user, text_hidden)¶ Hide a comment and save it
Paramètres: - user – the user that hid the comment
- text_hidden – the hide reason
Retourne:
-
set_user_vote
(user, vote)¶ Set a user vote (like, dislike or neutral)
-
-
class
zds.utils.models.
CommentEdit
(*args, **kwargs)¶ Archive for editing a comment.
-
class
zds.utils.models.
CommentVote
(*args, **kwargs)¶ Set of comment votes.
-
class
zds.utils.models.
Hat
(*args, **kwargs)¶ Hats are labels that users can add to their messages. Each member can be allowed to use several hats. It can be used for exemple to allow members to identify that a moderation message was posted by a staff member.
-
class
zds.utils.models.
HatRequest
(*args, **kwargs)¶ A hat requested by a user.
-
class
zds.utils.models.
HelpWriting
(*args, **kwargs)¶ Tutorial Help
-
class
zds.utils.models.
Licence
(*args, **kwargs)¶ Publication licence.
-
class
zds.utils.models.
SubCategory
(*args, **kwargs)¶ Common subcategory for several concepts of the application.
-
class
zds.utils.models.
Tag
(*args, **kwargs)¶ Set of tags.
-
zds.utils.models.
image_path_category
(instance, filename)¶ Return path to an image.
-
zds.utils.models.
image_path_help
(instance, filename)¶ Return path to an image.
Forums (forums.py
)¶
-
zds.utils.forums.
create_topic
(request, author, forum, title, subtitle, text, tags='', related_publishable_content=None)¶ create topic in forum
-
zds.utils.forums.
get_tag_by_title
(title)¶ Extract tags from title. In a title, tags can be set this way: > [Tag 1][Tag 2] There is the real title Rules to detect tags: - Tags are enclosed in square brackets. This allows multi-word tags instead of hashtags. - Tags can embed square brackets: [Tag] is a valid tag and must be written [[Tag]] in the raw title - All tags must be declared at the beginning of the title. Example: _”Title [tag]”_ will not create a tag. - Tags and title correctness (example: empty tag/title detection) is not checked here :param title: The raw title :return: A tuple: (the tag list, the title without the tags).
Messages privés (mps.py
)¶
-
zds.utils.mps.
send_message_mp
(author, n_topic, text, send_by_mail=True, direct=False, with_hat='')¶ Send a post in an MP. Most of the param are obvious, excepted : * direct : send a mail directly without mp (ex : ban members who wont connect again) * leave : the author leave the conversation (usefull for the bot : it wont read the response a member could send)
-
zds.utils.mps.
send_mp
(author, users, title, subtitle, text, send_by_mail=True, leave=True, direct=False, mark_as_read=False, with_hat='')¶ Send MP at members. Most of the param are obvious, excepted : * direct : send a mail directly without mp (ex : ban members who wont connect again) * leave : the author leave the conversation (usefull for the bot : it wont read the response a member could send)
Les processeurs de contexte (context_processor.py
)¶
La doc de Django explique le principe des context_processors comme suit :
TEMPLATE_CONTEXT_PROCESSORS
contienne le chemin vers le processeur personnalisé.(pour plus de détails, voir la documenation de Django à ce sujet)
-
zds.utils.context_processor.
app_settings
(request)¶ A context processor with all APP settings.
-
zds.utils.context_processor.
get_git_version
()¶ Get the git version of the site.
-
zds.utils.context_processor.
git_version
(request)¶ A context processor to include the git version on all pages.
Utilitaires pour formulaires (forms.py
)¶
-
class
zds.utils.forms.
TagValidator
¶ validate tags
-
validate_length
(tag)¶ Check the length is in correct range. See
Tag.label
max length to have the true upper bound.Paramètres: tag – the tag lavel to validate Retourne: True
if length is valid
-
validate_raw_string
(raw_string)¶ validate a string composed as
tag1,tag2
.Paramètres: raw_string (basestring) – the string to be validate. If None
this is considered as a empty str.Retourne: True
ifraw_string
is fully valid,False
if at least one error appears. Seeself.errors
to get all internationalized error.
-
validate_string_list
(string_list)¶ Same as
validate_raw_string
but with a list of tag labels.Paramètres: string_list – Retourne: True
ifv
is fully valid,False
if at least one error appears. Seeself.errors
to get all internationalized error.
-
validate_utf8mb4
(tag)¶ Checks the tag does not contain utf8mb4 chars.
Paramètres: tag – Retourne: True
if no utf8mb4 string is found
-
Autres (misc.py
)¶
-
zds.utils.misc.
compute_hash
(filenames)¶ returns a md5 hexdigest of group of files to check if they have change
-
zds.utils.misc.
contains_utf8mb4
(s)¶ This string contains at least one character of more than 3 bytes
-
zds.utils.misc.
convert_camel_to_underscore
(camel_case)¶ Converts a name in camel case to underscore.
-
zds.utils.misc.
has_changed
(instance, field, manager='objects')¶ Returns true if a field has changed in a model May be used in a model.save() method.