mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-24 10:34:03 +03:00
0ebbfbff45
This commit introduces several improvements to the template tags and filters used in Django Rest Framework (DRF). The enhancements focus on code readability, maintainability, efficiency, and security. Key changes include: ### Enhancements: 1. **Regex Precompilation:** - Moved regular expression compilation outside of functions to avoid recompilation and improve performance. 2. **Simplified Add Class Function:** - Refactored the `add_class` function for better readability and efficiency, ensuring that CSS classes are added accurately and safely. 3. **Modularized and Documented Code:** - Broke down larger functions and added detailed comments and docstrings to explain the purpose and functionality of each tag and filter, improving code maintainability. 4. **Security Enhancements:** - Ensured proper escaping of HTML and judicious use of `mark_safe` to prevent XSS attacks, particularly in functions dealing with user-generated content. 5. **Optimized Markdown Rendering:** - Added conditional checks for the availability of the `apply_markdown` function and provided safe fallbacks, enhancing the robustness of markdown rendering. 6. **Improved Handling of Dynamic URLs and Headers:** - Enhanced the logic for handling dynamic URLs and long headers, ensuring that URLs are quoted correctly and headers are broken safely to maintain readability. ### Detailed Changes: - Precompiled regex patterns for class handling and URL validation. - Simplified the `add_class` logic by reducing regex operations and ensuring accurate class insertion. - Added docstrings and inline comments for better code understanding. - Enhanced security by using `escape` and `mark_safe` appropriately. - Improved the handling of markdown text rendering by checking for `apply_markdown` and using `mark_safe`. - Refined the handling of pagination HTML and form rendering for better user experience. - Optimized functions to ensure better performance and adherence to Django best practices. These changes aim to enhance the overall functionality, readability, and security of the template tags and filters, contributing to a more robust and maintainable codebase for Django Rest Framework. |
||
---|---|---|
.. | ||
authtoken | ||
locale | ||
management | ||
schemas | ||
static/rest_framework | ||
templates/rest_framework | ||
templatetags | ||
utils | ||
__init__.py | ||
apps.py | ||
authentication.py | ||
checks.py | ||
compat.py | ||
decorators.py | ||
documentation.py | ||
exceptions.py | ||
fields.py | ||
filters.py | ||
generics.py | ||
metadata.py | ||
mixins.py | ||
negotiation.py | ||
pagination.py | ||
parsers.py | ||
permissions.py | ||
relations.py | ||
renderers.py | ||
request.py | ||
response.py | ||
reverse.py | ||
routers.py | ||
serializers.py | ||
settings.py | ||
status.py | ||
test.py | ||
throttling.py | ||
urlpatterns.py | ||
urls.py | ||
validators.py | ||
versioning.py | ||
views.py | ||
viewsets.py |