Skip to content

Commit

Permalink
Merge b070949 into 1e14eff
Browse files Browse the repository at this point in the history
  • Loading branch information
Radi85 committed May 22, 2020
2 parents 1e14eff + b070949 commit 313b83f
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 52 deletions.
71 changes: 48 additions & 23 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
:target: https://django-comment-dab.readthedocs.io/?badge=latest
:alt: Documentation Status

.. image:: https://img.shields.io/github/license/radi85/Comment
:alt: GitHub

===================
django-comments-dab
===================
Expand Down Expand Up @@ -52,12 +55,14 @@ It allows you to integrate commenting functionality with any model you have e.g.

2. Reply to an existing comment.

3. Edit a comment you posted.
3. Edit a comment.

4. Delete a comment.

4. Delete a comment you posted.
5. React to a comment. Available reactions are LIKE and DISLIKE # open PR if you would like to have more reactions


- All actions are done by ajax calls - JQuery 3.2.1
- All actions are done by AJAX calls - JQuery 3.2.1

- Bootstrap 4.1.1 is used in comment templates for responsive design.

Expand All @@ -70,7 +75,7 @@ Requirements:
-------------

1. **django>=2.1**
2. **djangorestframework** # only for API Framework
2. **djangorestframework** # only for the API Framework
3. **Bootstrap 4.1.1**
4. **jQuery 3.2.1**

Expand Down Expand Up @@ -166,10 +171,10 @@ E.g. ``Post`` model, as shown below:
Step 2 - Adding template tags:
------------------------------

``render_comments`` *tag uses 2 positional and 2 optional args*:
``render_comments`` *tag uses 2 required and 2 optional args*:

1. Instance of the targeted model. (**positional**)
2. Request object. (**positional**)
1. Instance of the targeted model. (**Required**)
2. Request object. (**Required**)
3. oauth. (optional - Default is false)
4. comments_per_page (number of Comments Per Page - Default is 10)

Expand Down Expand Up @@ -295,7 +300,9 @@ There are 5 methods available to perform the following actions:

4. Delete a comment you posted. (Authenticated)

5. Retrieve the list of comments and associated replies to a given content type and object ID.
5. React to a comment. (Authenticated)

6. Retrieve the list of comments and associated replies to a given content type and object ID.

These actions are explained below.

Expand All @@ -319,10 +326,12 @@ for the Post model add comments field as shown below:
class Meta:
model = Post
fields = ('id',
...
...
'comments')
fields = (
'id',
...
...
'comments'
)
def get_comments(self, obj):
comments_qs = Comment.objects.filter_parents_by_object(obj)
Expand All @@ -346,7 +355,7 @@ declare the ``COMMENT_PROFILE_API_FIELDS`` tuple inside your ``settings.py``:
Comment API actions:
--------------------

**1- Retrieve the list of comments and associated replies to a given content type and object ID:**
**1- Retrieve the list of comments and associated replies to a given content type and object ID:**

This action can be performed by providing the url with data queries related to the content type.

Expand All @@ -364,24 +373,26 @@ Comment API actions:

::

$ curl 'http://localhost:8000/api/comments/?type=TYPE&id=ID'
$ curl -H "Content-Type: application/json" 'http://localhost:8000/api/comments/?type=MODEL_NAME&id=ID'


**2- Post a comment or reply to an existing comment:**
**2- Create a comment or reply to an existing comment:**

Authorization must be provided as a TOKEN or USERNAME:PASSWORD.

- ``type``: is the model name of the content type that have comments associated with it.
- ``id``: is the id of an object of that model
- ``parent_id``: is 0 or **NOT PROVIDED** for parent comments and for reply comments must be the id of parent comment


Example: posting a parent comment

::

$ curl -X POST -u USERNAME:PASSWORD -d "content=CONTENT" "http://localhost:8000/api/comments/create/?type=MODEL&id=ID&parent_id=0"
$ curl -X POST -u USERNAME:PASSWORD -d "content=CONTENT" -H "Content-Type: application/json" "http://localhost:8000/api/comments/create/?type=MODEL_NAME&id=ID&parent_id=0"


**3- Update a comment:**
**3- Update a comment:**

Authorization must be provided as a TOKEN or USERNAME:PASSWORD.

Expand All @@ -390,21 +401,35 @@ Comment API actions:

::

$ curl -X PUT -u USERNAME:PASSWORD -d "content=CONTENT" "http://localhost:8000/api/comments/ID/
$ curl -X PUT -u USERNAME:PASSWORD -d "content=CONTENT" -H "Content-Type: application/json" "http://localhost:8000/api/comments/ID/



**4- Delete a comment:**
**4- Delete a comment:**

Authorization must be provided as a TOKEN or USERNAME:PASSWORD.

This action requires the ``comment.id`` that you want to delete:

::

$ curl -X DELETE -u USERNAME:PASSWORD "http://localhost:8000/api/comments/ID/
$ curl -X DELETE -u USERNAME:PASSWORD -H "Content-Type: application/json" "http://localhost:8000/api/comments/ID/


**5- React to a comment:**

``POST`` is the allowed method to perform a reaction on a comment.

Authorization must be provided as a TOKEN or USERNAME:PASSWORD.

This action requires the ``comment.id``. and,
``reaction_type``: one of ``like`` or ``dislike``

::

$ curl -X POST -u USERNAME:PASSWORD -H "Content-Type: application/json" "http://localhost:8000/api/comments/ID/react/REACTION_TYPE/


PS: As in the UI, clicking the **liked** button will remove the reaction => unlike the comment. This behaviour is performed when repeating the same post request.


.. _`Style Customization`:
Expand Down Expand Up @@ -473,6 +498,6 @@ Login with:
.. image:: /docs/_static/img/img_1.png


.. image:: /docs/_static/img/img_2.png

The icons are picked from `Feather`_. Many thanks for the good work.

.. _`Feather`: https://feathericons.com
Binary file modified docs/_static/img/img_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/_static/img/img_2.png
Binary file not shown.
6 changes: 6 additions & 0 deletions docs/source/Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

1.5.0
-----

- Add reactions - (LIKE and DISLIKE)
- Restrict the requests to AJAX calls only

1.4.0
-----

Expand Down
55 changes: 39 additions & 16 deletions docs/source/Web API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ There are 5 methods available to perform the following actions:

4. Delete a comment you posted. (Authenticated)

5. Retrieve the list of comments and associated replies to a given content type and object ID.
5. React to a comment. (Authenticated)

6. Retrieve the list of comments and associated replies to a given content type and object ID.

These actions are explained below.

Expand All @@ -39,10 +41,12 @@ for the Post model add comments field as shown below:
class Meta:
model = Post
fields = ('id',
...
...
'comments')
fields = (
'id',
...
...
'comments'
)
def get_comments(self, obj):
comments_qs = Comment.objects.filter_parents_by_object(obj)
Expand All @@ -66,7 +70,7 @@ declare the ``COMMENT_PROFILE_API_FIELDS`` tuple inside your ``settings.py``:
Comment API actions:
--------------------

**1- Retrieve the list of comments and associated replies to a given content type and object ID:**
**1- Retrieve the list of comments and associated replies to a given content type and object ID:**

This action can be performed by providing the url with data queries related to the content type.

Expand All @@ -84,24 +88,26 @@ Comment API actions:

::

$ curl 'http://localhost:8000/api/comments/?type=TYPE&id=ID'
$ curl -H "Content-Type: application/json" 'http://localhost:8000/api/comments/?type=MODEL_NAME&id=ID'


**2- Post a comment or reply to an existing comment:**
**2- Create a comment or reply to an existing comment:**

Authorization must be provided as a TOKEN or USERNAME:PASSWORD.

- ``parent_id``: is 0 or **NOT PROVIDED** for parent comments and for reply comments must be the id of the parent comment.
- ``type``: is the model name of the content type that have comments associated with it.
- ``id``: is the id of an object of that model
- ``parent_id``: is 0 or **NOT PROVIDED** for parent comments and for reply comments must be the id of parent comment


Example: posting a parent comment:
Example: posting a parent comment

::

$ curl -X POST -u USERNAME:PASSWORD -d "content=CONTENT" "http://localhost:8000/api/comments/create/?type=MODEL&id=ID&parent_id=0"
$ curl -X POST -u USERNAME:PASSWORD -d "content=CONTENT" -H "Content-Type: application/json" "http://localhost:8000/api/comments/create/?type=MODEL_NAME&id=ID&parent_id=0"


**3- Update a comment:**
**3- Update a comment:**

Authorization must be provided as a TOKEN or USERNAME:PASSWORD.

Expand All @@ -110,17 +116,34 @@ Comment API actions:

::

$ curl -X PUT -u USERNAME:PASSWORD -d "content=CONTENT" "http://localhost:8000/api/comments/ID/

$ curl -X PUT -u USERNAME:PASSWORD -d "content=CONTENT" -H "Content-Type: application/json" "http://localhost:8000/api/comments/ID/


**4- Delete a comment:**
**4- Delete a comment:**

Authorization must be provided as a TOKEN or USERNAME:PASSWORD.

This action requires the ``comment.id`` that you want to delete:

::

$ curl -X DELETE -u USERNAME:PASSWORD "http://localhost:8000/api/comments/ID/
$ curl -X DELETE -u USERNAME:PASSWORD -H "Content-Type: application/json" "http://localhost:8000/api/comments/ID/


**5- React to a comment:**

``POST`` is the allowed method to perform a reaction on a comment.

Authorization must be provided as a TOKEN or USERNAME:PASSWORD.

This action requires the ``comment.id``. and,
``reaction_type``: one of ``like`` or ``dislike``

::

$ curl -X POST -u USERNAME:PASSWORD -H "Content-Type: application/json" "http://localhost:8000/api/comments/ID/react/REACTION_TYPE/


PS: As in the UI, clicking the **liked** button will remove the reaction => unlike the comment. This behaviour is performed when repeating the same post request.
.

6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
# -- Project information -----------------------------------------------------

project = 'django-comments-dab'
copyright = '2018, Radico'
copyright = '2018, Radico'
author = 'Radico'

# The short X.Y version
version = '1.4.0'
version = '1.5.0'
# The full version, including alpha/beta/rc tags
release = '1.4.0'
release = '1.5.0'


# -- General configuration ---------------------------------------------------
Expand Down
5 changes: 0 additions & 5 deletions docs/source/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ Login with:
password: ``django-comments``

.. image:: ../_static/img/img_1.png


.. image:: ../_static/img/img_2.png


11 changes: 7 additions & 4 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ django-comments-dab
.. image:: https://img.shields.io/pypi/djversions/django-comments-dab.svg
:target: https://pypi.python.org/pypi/django-comments-dab/

.. image:: https://img.shields.io/github/license/radi85/Comment
:alt: GitHub

Introduction
============


**dab stands for Django-Ajax-Bootstrap**

``django-comments-dab`` is a commenting application for Django-powered
Expand All @@ -38,11 +39,13 @@ It allows you to integrate commenting functionality with any model you have e.g.

2. Reply to an existing comment.

3. Edit a comment you posted.
3. Edit a comment.

4. Delete a comment.

4. Delete a comment you posted.
5. React to a comment. Available reactions are LIKE and DISLIKE # open PR if you would like to have more reactions


- All actions are done by ajax calls - JQuery 3.2.1
- All actions are done by AJAX calls - JQuery 3.2.1

- Bootstrap 4.1.1 is used in comment templates for responsive design.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='django-comments-dab',
version='1.4.0',
version='1.5.0',
packages=find_packages(exclude=['docs', 'test*']),
include_package_data=True,
author=u'Radico',
Expand Down
Binary file modified test/db.sqlite3
Binary file not shown.
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ deps =
django22: django>=2.2,<2.3
django30: django>=3.0,<3.1
djangomaster: https://github.com/django/django/archive/master.tar.gz

usedevelop = True
ignore_outcome =
djangomaster: True

commands =
flake8 comment/
python manage.py migrate
coverage run manage.py test
coverage report

setenv =
PYTHONDONTWRITEBYTECODE=1

0 comments on commit 313b83f

Please sign in to comment.