-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reactions #10
Add reactions #10
Conversation
Make comment models a python package - make other necessary changes to imports everywhere - move code for manager to manager module Add reaction models - add some general property functions to be useful in future Reorder some import to conform to PEP8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey,
Many thanks for you efforts.
I would separate show reacted user
feature in a different issue so for now just ignore it.
Please consider PEP 8 compatibility and ignore typing for now.
- likes and dislikes are now part of a column. - add functions to update reactions and their count. Make changes to the ReactionInstance model - reaction choices now uses IntegerChoices which is similar to IntEnum Add the reaction model and reaction instance model to the admin Change import of comment model - it is directly imported from the model package rather than going inside the comments module.
- all comment models are now imported in the __init__ file
Changes made to Reaction model - Reaction choices are now made from IntEnum, since models.TextChoices is only supported in Django 3.0 - related_name for foreign keys made plural - move logic for set_reaction to ReactionInstance model Changes to ReactionInstance - add function to override save function. - add a function to be executed on pre-delete signal. - set_reaction method is now a classmethod. - clean up set_reaction and refactor it. Changes to Comment model - add property for showing like and dislike count. Add urlpattern for accepting requests for reaction. Changes to views - views is now a package, move earlier code to comments module inside it - add module for reactions Changes to templates - show like and dislike count alongside the comment content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey,
Thanks a lot. A lot of work has been done.
I would like to use icons instead, thumbs up and down, if your question is realted to the font, feel free to use any light weight version.
As suggested, please move reply
, like
and dislike
to the second row.
Unfortunately I have no more time but I would like to get back to review the models again, nice work!
Btw, the work you have already done, could be splitted to more features :D |
Add svg icons for like and dislike - fill them if the logged in user has liked or disliked a comment - add templatetags that make this feature possible Add post save signal to Comment model - Reaction instance is created when a new comment is created. Changes in ReactionInstance model - change related name for user attribute -> 'reactions' seems more natural.
Well done so far. I like how it looks like. |
Other changes to comply with flake8
- Reaction icon's color and count are updated. Changes in reaction views - View all returns latest reaction count for the updated reaction -> Updates reaction count as per the last HTTP request Changes to comment content template - Remove block for like and dislike icon colors -> the color values are used in javascript too. Obtaining them to javascript from the template would require a hack. Can be done in the future. - Make or remove element properties as per changes in the javascript.
- cite was probably mistakenly used here.
Hey, currently the reaction thing works well for authenticated users. For unauthenticated users, I was thinking of following this workflow
|
Changes in view handling reaction - bad react requests are handled now
- they were anyway used outside the class Add tests for unauthenticated users for the has_reacted template tag - mock an unauthenticated user for the template -> complete coverage for template tags.
To avoid this complex, please use a simple if statement inside the template: {% if user.is_authenticated %}
a_tag
{% else %}
div_tag
{% endif %}
I believe django will authenticate the user when using |
How will this help in handling the event when triggered through javascript?
I was concerned about redirecting the user to the like link for the comment. How do we do that? |
Javascript fucntion is triggered here: $(document).on("click", ".js-comment-reaction", commentReact); Add this class to html tag only if the user is authenticated: <small class="{% if user.is_authenticated %}js-comment-like {% endif %} {% block like_link_cls %} btn btn-link" {% endblock like_link_cls %} href="{% url 'comment:react' comment_id=obj.id reaction='like' %}">{% trans "Like" %}</small>
I am not sure what |
Sorry, I didn't mention this explicitly, but I was talking about unauthenticated users. If they click on the like icon, we would want to redirect them to like URL after they are authenticated. For normal auth, we can put the link something like this Also, how should we handle the response in this case(after performing the action on the redirected link)? Currently, I am returning JSON response which might not be an ideal scenario. |
We also need to add exception handling to the comment views. |
- move reactions part to a separate template - add translation capabilities to this template. Create new templates for reactions templates - handles url for unauthenticated users. - like and dislike icon moved to a separate template. Remove Reaction manager - it wasn't used anywhere in the application. Change request method for reaction - GET allows redirect for unauthenticated users - make the corresponding change to the javascript function Changes in tests - add tests in models for post delete signal. - refactor code for view tests. - remove unnecessary part.
- it was mistakenly copied from the like icon Add an empty line at the end of the file
I have fixed it in the latest commit. It was caused when I was refactoring the templates. I had accidently forgot to change the icon class and filter to the dislike icon file after copying things from the like icon file. |
One feature has a lot of sub-features or substantial subtilities that are required for its implementation. I don't think you can put the whole thing in a single commit. Anyways it is your call. I believe Github gives the owners/maintainers option to squash the commits while merging. |
Don't worry about it then, I will take care of it. |
Maybe we can put the file in .gitignore to stop it from being tracked, to stop it from causing issues with version control. |
After rendreing the page. |
I actually keep this db for the demo project so who would like to use app, can directly find an example with less efforts. |
Are you sure? This means the template filter is not working correctly then. Just to make sure, have you pulled in the latest commits? |
I forgot to mention the icons were picked from https://feathericons.com. Please don't forget to give them credit in the documentation. |
Thanks for mentioning. Just small thing regarding the icons, could you please make them with the count text a little bit small? |
Height and width of size 20 for icons look fine to me. Just try and tell me if it looks good to you before I push in the change. |
- remove the filter used for chaining. - change tests accordingly Like and Dislike icon are now filled using a class - make appropriate changes to the javascript file - add classes to the css file - this change was made because style property was sometimes not overiding the fill property of svg element Fixes like and dislike icons filling now hopefully.
- make corresponding changes in the url and tests.
The test is failing due to passing the reply comment object to the context data as context['comment'] = PARENT_COMMENT
context['reply'] = CHILD_COMMENT As I see this is a bad design and I am going to refactor the code. |
Add type checking for reaction type in model - add clean function in views also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got 405 (Method Not Allowed) error when try to react to a comment.
Yes, I too get this error now. I had not checked the response by testing it from a browser after the database issue. Since the tests were passing, I assumed it should pass. I will fix this soon and commit. |
- change made after refactoring view to a class based one.
Merged in #16 |
Add reactions to comments.
Tasks:
post_save
signal that creates a Reaction instance when a comment is created.The reaction process currently looks something like this:
Fixes #8, maybe we can move adding flag to a separate issue.