Skip to content

Commit

Permalink
feat: implicitly include static files in the template
Browse files Browse the repository at this point in the history
include_static templatetag is now deprecated.
  • Loading branch information
rmustafa-cocus authored and Radi85 committed Sep 26, 2020
1 parent 4b75fb4 commit d96fa5a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ Usage
1. Basics usage:
----------------

``include_static`` this tag will include CSS and javascript files,

``include_bootstrap`` tag is for bootstrap-4.1.1, if it’s already used in the project, get rid of this tag.

In the template (e.g. post_detail.) add the following template tags where ``obj`` is the instance of post model.
Expand All @@ -222,6 +220,7 @@ In the template (e.g. post_detail.) add the following template tags where ``obj`
{% load comment_tags %} {# Loading the template tag #}
{% render_comments obj request %} {# Render all the comments belong to the passed object "obj" #}
{% include_bootstrap %} {# Include bootstrap 4.1.1 - remove this line if BS is already used in your project #}
2. Advanced usage:
Expand Down
2 changes: 2 additions & 0 deletions comment/templates/comment/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% include 'comment/static.html' %}
{% include 'comment/comments/base.html' %}
10 changes: 4 additions & 6 deletions comment/templatetags/comment_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def render_comments(obj, request, oauth=False):
return context


register.inclusion_tag('comment/comments/base.html')(render_comments)
register.inclusion_tag('comment/base.html')(render_comments)


def render_content(comment, number):
Expand Down Expand Up @@ -111,12 +111,10 @@ def can_delete_comment(comment, user):
register.inclusion_tag('comment/comments/content.html')(render_content)


@register.simple_tag(name='include_static')
def include_static():
""" include static files """
return None


register.inclusion_tag('comment/static.html')(include_static)
""" This function shall be deprecated """
return ''


def include_bootstrap():
Expand Down
2 changes: 1 addition & 1 deletion comment/tests/test_template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_render_comments(self):
self.assertTrue(data['comments'].has_previous())

def test_static_functions(self):
self.assertIsNone(include_static())
self.assertEqual(include_static(), '')
self.assertIsNone(include_bootstrap())

def test_render_field(self):
Expand Down
4 changes: 1 addition & 3 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Usage
1. Basics usage:
----------------

``include_static`` this tag will include CSS and javascript files,

``include_bootstrap`` tag is for bootstrap-4.1.1, if it’s already used in the project, get rid of this tag.

In the template (e.g. post_detail.) add the following template tags where ``obj`` is the instance of post model.
Expand All @@ -14,6 +12,7 @@ In the template (e.g. post_detail.) add the following template tags where ``obj`
{% load comment_tags %} {# Loading the template tag #}
{% render_comments obj request %} {# Render all the comments belong to the passed object "obj" #}
{% include_bootstrap %} {# Include bootstrap 4.1.1 - remove this line if BS is already used in your project #}
2. Advanced usage:
Expand All @@ -32,7 +31,6 @@ To change the default number, set ``COMMENT_PER_PAGE=number``.
{% render_comments obj request %} {# Include comments belonging to a certain object #}
{% include_bootstrap %} {# Include bootstrap 4.1.1 - remove this line if BS 4.1.1 is already used in your project #}
{% include_static %} {# Include comment CSS and JS files #}
Expand Down

1 comment on commit d96fa5a

@abhiabhi94
Copy link
Collaborator

@abhiabhi94 abhiabhi94 commented on d96fa5a Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Radi85, now that we have made this change, which is a major one and isn't backward compatible. I think, the next version that we shall release should now directly be 3.0.0.

Edit: i see that the tag has not yet been deprecated. maybe we can issue a warning to the console when this function is called.

Please sign in to comment.