-
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.
[DOC] Add models, templatetags and serializers doc
- Loading branch information
Showing
9 changed files
with
259 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,10 +1,14 @@ | ||
.. _intro_django-app: | ||
.. _intro_firm-info: | ||
|
||
================== | ||
Django application | ||
Django firm info | ||
================== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
models.rst | ||
|
||
serializers.rst | ||
|
||
templatetags.rst |
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,9 @@ | ||
.. _intro_firm-info_models: | ||
|
||
====== | ||
Models | ||
====== | ||
|
||
.. automodule:: firm_info.models | ||
:members: FirmContact, Link, SocialSharing, Tracking, AppsBanner, | ||
:exclude-members: DoesNotExist, MultipleObjectsReturned |
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,9 @@ | ||
.. _intro_firm-info_serializers: | ||
|
||
=========== | ||
Serializers | ||
=========== | ||
|
||
.. automodule:: firm_info.serializers | ||
:members: SerializeFirmError, _format_address, serialize_firm_info, serialize_firm_social, serialize_firm_description, serialize_firm_social_sharing, serialize_firm_apps_banner | ||
:exclude-members: DoesNotExist, MultipleObjectsReturned |
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,9 @@ | ||
.. _intro_firm-info_templatetags: | ||
|
||
============ | ||
Templatetags | ||
============ | ||
|
||
.. automodule:: firm_info.templatetags.firm_info | ||
:members: firm_contact, firm_social_links, firm_description, firm_logos, firm_social_shares, firm_tag_analytic, app_banner | ||
:exclude-members: DoesNotExist, MultipleObjectsReturned |
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ User’s Guide | |
:maxdepth: 2 | ||
|
||
install.rst | ||
django_app/index.rst | ||
firm_info/index.rst | ||
|
||
|
||
Developer’s Guide | ||
|
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,12 +1,23 @@ | ||
class SerializeFirmError(Exception): | ||
""" | ||
Custom exception to handle errors during Firm informations serialization. | ||
""" | ||
|
||
pass | ||
|
||
|
||
def _format_address(firm_info: dict) -> str: | ||
""" | ||
Formats the address using the firm information. | ||
Args: | ||
firm_info (dict): The firm information with the following keys: | ||
- "address": The address of the firm. | ||
- "postal_code": The postal code of the firm. | ||
- "city": The city of the firm. | ||
- "country": The country of the firm. | ||
Returns: | ||
str: The formatted address string in the format | ||
`"{address}, {postal_code} {city} {country}"`. | ||
""" | ||
return "{}, {} {} {}".format( | ||
firm_info.get("address"), | ||
firm_info.get("postal_code"), | ||
|
@@ -17,31 +28,26 @@ def _format_address(firm_info: dict) -> str: | |
|
||
def serialize_firm_info(queryset): | ||
""" | ||
Serialize FirmContact unique instance. | ||
Serializes the firm information from a queryset. | ||
Args: | ||
`FirmContact` Queryset | ||
Raises: | ||
SerializeFirmError | ||
queryset: The queryset containing the firm information. | ||
Returns: | ||
(dict): email phone and address of firm as serialized data | ||
Sample: | ||
``` | ||
{ | ||
"email": "[email protected]", | ||
"phone": "003369856321", | ||
"full_address": "1 avenue Charles de Gaulle, 99999 Paris France", | ||
"address": "1 avenue Charles de Gaulle", | ||
"postal_code": "99999", | ||
"city": "Paris", | ||
"country": "France", | ||
} | ||
``` | ||
dict: the serialized firm information with the following keys: | ||
- "email": The email address of the firm. | ||
- "phone": The phone number of the firm. | ||
- "full_address": The formatted full address of the firm. | ||
- "address": The address of the firm. | ||
- "postal_code": The postal code of the firm. | ||
- "city": The city of the firm. | ||
- "country": The country of the firm. | ||
Raises: | ||
SerializeFirmError: Raised when an error occurs during serialization. | ||
""" | ||
|
||
try: | ||
firm_info = queryset.values( | ||
"phone_number", "email", "address", "postal_code", "city", "country" | ||
|
@@ -61,25 +67,19 @@ def serialize_firm_info(queryset): | |
|
||
def serialize_firm_social(queryset): | ||
""" | ||
Serialize Firm social networks urls. | ||
Serializes the firm social media information from a queryset. | ||
Args: | ||
`Link` Queryset | ||
Raises: | ||
SerializeFirmError | ||
queryset: The queryset containing the firm social media information. | ||
Returns: | ||
(dict): social network name as dict key, url as dict value. | ||
dict: The serialized firm social media information with the social media names | ||
as keys and their corresponding URLs as values. | ||
Sample: | ||
```python | ||
{ | ||
"facebook": "www.site.com", | ||
"instagram": "www.site2.com" | ||
} | ||
``` | ||
Raises: | ||
SerializeFirmError: Raised when an error occurs during serialization. | ||
""" | ||
|
||
try: | ||
firm_socials = list( | ||
queryset.values( | ||
|
@@ -97,25 +97,19 @@ def serialize_firm_social(queryset): | |
|
||
def serialize_firm_description(queryset): | ||
""" | ||
Serialize FirmContact unique instance. | ||
Serializes the firm description from a queryset. | ||
Args: | ||
`FirmContact` Queryset | ||
Raises: | ||
SerializeFirmError | ||
queryset: The queryset containing the firm description. | ||
Returns: | ||
(dict): baseline and short_description of firm as serialized data | ||
dict: The serialized firm description with the following keys: | ||
Sample: | ||
``` | ||
{ | ||
"baseline": "Non eram nescius, Brute, cum, quae summis ingeniis", | ||
"short_description": "Quamquam, si plane sic verterem Platonem" | ||
} | ||
``` | ||
- "baseline": The baseline of the firm. | ||
- "short_description": The short description of the firm. | ||
Raises: | ||
SerializeFirmError: Raised when an error occurs during serialization. | ||
""" | ||
try: | ||
firm_info = queryset.values("baseline", "short_description").first() | ||
|
@@ -129,25 +123,20 @@ def serialize_firm_description(queryset): | |
|
||
def serialize_firm_social_sharing(obj): | ||
""" | ||
Serialize Firm social networks sharing urls. | ||
Serialize Firm social networks sharing URLs. | ||
Args: | ||
`SocialSharing` Queryset | ||
Raises: | ||
SerializeFirmError | ||
obj (QuerySet): The `SocialSharing` queryset. | ||
Returns: | ||
(dict): og_image, og_description and og_twitter_site as serialized data | ||
Sample: | ||
```python | ||
{ | ||
"og_image": SmartMediaField(), | ||
"og_description": TextField(), | ||
"og_twitter_site": CharField(), | ||
} | ||
``` | ||
dict: The serialized data with the following keys: | ||
- og_image (SmartMediaField): The OG image for social media sharing. | ||
- og_description (TextField): The OG description for social media sharing. | ||
- og_twitter_site (CharField): The OG Twitter site for social media sharing. | ||
Raises: | ||
SerializeFirmError: Raised when an error occurs during serialization. | ||
""" | ||
|
||
try: | ||
|
@@ -162,6 +151,23 @@ def serialize_firm_social_sharing(obj): | |
|
||
|
||
def serialize_firm_apps_banner(obj): | ||
""" | ||
Serializes an instance of the AppsBanner model into a dictionary. | ||
Args: | ||
obj: The AppsBanner object to be serialized. | ||
Returns: | ||
dict: The serialized data with the following keys: | ||
- "title": The title of the `AppsBanner`. | ||
- "description": The description of the AppsBanner. | ||
- "image": The image associated with the AppsBanner. | ||
Raises: | ||
SerializeFirmError: Raised when an error occurs during serialization. | ||
""" | ||
|
||
try: | ||
return { | ||
"title": obj.title, | ||
|
Oops, something went wrong.