Application Community¶
The Community application contains the pages of Community.
Templates¶
The stats application contains 4 templates :
publication_detail.html
: community page that displays the detail about a certain publication.publication_edit.html
: comminuty page that allows the manager or the administrator to edit a certain publication.publication_list.html
: main page that lists all the publications.publication_new.html
: page that allows the user to create a new publication.
Key files of the « Community » application¶
admin.py¶
- class apps.community.admin.CommunityCategoryAdmin(model, admin_site)¶
Adding the CommunityCategory table in the Django admin and customizing therendering
- class apps.community.admin.CommunityPublicationAdmin(model, admin_site)¶
Adding the CommunityCategory table in the Django admin and customizing the rendering
model.py¶
- class apps.community.models.CommunityCategory(*args, **kwargs)¶
community category model table
- exception DoesNotExist¶
- exception MultipleObjectsReturned¶
- class apps.community.models.CommunityPublication(id, category, title, description, content, author, date)¶
- exception DoesNotExist¶
- exception MultipleObjectsReturned¶
test.py¶
view.py¶
- apps.community.views.publication_delete(request, id)¶
The function deletes a community publication and redirects to the publication list page with a message.
- Paramètres
request – The request parameter is an object that represents the HTTP request made by the user. It contains information such as the user making the request, the method used (GET, POST, etc.), and any data sent with the request
id – The « id » parameter in the « publication_delete » function is the unique identifier of the publication that needs to be deleted
- Renvoie
a redirect to the “publication_list” view with a message parameter.
- apps.community.views.publication_detail(request, id)¶
The function « publication_detail » retrieves a specific community publication object based on its ID, retrieves the tags associated with the publication, and renders a template with the publication and tags as context variables.
- Paramètres
request – The request object represents the HTTP request made by the user. It contains information such as the user’s browser, IP address, and any data sent with the request
id – The « id » parameter is the unique identifier of the CommunityPublication object that we want to retrieve and display its details
- Renvoie
a rendered HTML template with the publication details and tags.
- apps.community.views.publication_edit(request, id)¶
The function publication_edit is used to edit a community publication and save the changes.
- Paramètres
request – The request object represents the HTTP request made by the user. It contains information such as the user’s browser, IP address, and any data sent with the request
id – The « id » parameter is the unique identifier of the CommunityPublication object that we want to edit. It is used to retrieve the specific object from the database using the get_object_or_404() function
- Renvoie
a rendered HTML template called “publication_edit.html” with the form and instance as context variables.
- apps.community.views.publication_list(request, cat_id=None, tag_id=None, message=None)¶
The publication_list function retrieves a list of publications based on category and/or tag filters, and renders them in a template along with other necessary data.
- Paramètres
request – The request parameter is an object that represents the HTTP request made by the user. It contains information such as the request method (GET, POST, etc.), the user’s session, and any data submitted with the request
cat_id – The cat_id parameter is used to filter the publications by a specific category. If a cat_id is provided, the function will retrieve the publications that belong to that category
tag_id – The tag_id parameter is used to filter the publications based on a specific tag. If a tag_id is provided, the function will retrieve the tag object with that ID and filter the publications to only include those that have that tag
message – The « message » parameter is used to pass a message to the template. It can be used to display any kind of information or notification to the user
- Renvoie
a rendered HTML template with the following context variables:
- apps.community.views.publication_new(request)¶
The function publication_new renders a form to create a new publication, saves the publication if the form is valid, and redirects to the publication list page.
- Paramètres
request – The request parameter is an object that represents the HTTP request made by the user. It contains information about the user, the requested URL, any submitted data, and other metadata related to the request. In this code snippet, the request parameter is used to access the user making the request
- Renvoie
a rendered HTML template called “publication_new.html” along with a form and a list of tags.