Skip to content

Conversation

@Radi85
Copy link
Owner

@Radi85 Radi85 commented Jun 24, 2020

  • The comment admin and moderator can now toggle between the flag states of a flagged comment.
  • Add function to check and update the flag state after each migrate
    command.
  • Extend the API to cover all GUI actions

- The comment admin and moderator can now toggle between the flag states of a flagged comment.
- Add function to check and update the flag state after each migrate
command.
- Extend the API to cover all GUI actions
@Radi85 Radi85 merged commit 71562d0 into staging Jun 24, 2020

return super().get_queryset().select_related('flag').annotate(
flags=models.F('flag__count')).filter(flags__lte=allowed_flags)
return super().get_queryset().exclude(flag__state__exact=2)
Copy link
Collaborator

@abhiabhi94 abhiabhi94 Jun 24, 2020

Choose a reason for hiding this comment

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

Instead of using raw numbers maybe we may use Enum choices or the class variable here.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes I will look at this in future code refactoring, I tried to get Flag.Flagged but got a circular import.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that is the reason I had used the statues in managers.

Comment on lines +23 to +26
(UNFLAGGED, 'Unflagged'),
(FLAGGED, 'Flagged'),
(REJECTED, 'Flag rejected by the moderator'),
(RESOLVED, 'Comment modified by the author'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Earlier gettext_lazy was used with the raw message for the state. It would help users from non-english language to easily port this in their language.

from django.utils.translation import gettext_lazy as _

STATE_CHOICES = [
        (UNFLAGGED, _('Unflagged')),
        (FLAGGED, _('Flagged')),
        (REJECTED, _('Flag rejected by the moderator')),
        (RESOLVED, _('Comment modified by the author')),
]

Copy link
Owner Author

Choose a reason for hiding this comment

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

You are right. I will open an issue for translating to cover everything.

Comment on lines 59 to +63
if hasattr(self, 'flag'):
self.flag.refresh_from_db()
allowed_flags = getattr(settings, 'COMMENT_FLAGS_ALLOWED', 0)
if allowed_flags:
return self.flag.count > allowed_flags
if not self.flag.is_flag_enabled:
return False
return self.flag.state != self.flag.UNFLAGGED
return False
Copy link
Collaborator

@abhiabhi94 abhiabhi94 Jun 24, 2020

Choose a reason for hiding this comment

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

This can be changed to:

if self.flag.is_flag_enabled:
    return self.flag.state != self.flag.UNFLAGGED
return False

Copy link
Owner Author

Choose a reason for hiding this comment

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

Your suggestion is not valid here because the developer may disable flagging and is_flagged will still be true and the comments will appear as flagged even if the feature is disabled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure I understand your argument since I've not seen all the changes in depth. What I suggested was a simple refactoring of your code, which does the exact same thing as your code or does it?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Simply: self.flag.state != self.flag.UNFLAGGED can be False or True, even if the flagging system is disabled.
I want is_flagged to be always false when the flagging system is disabled.

Copy link
Collaborator

@abhiabhi94 abhiabhi94 Jun 24, 2020

Choose a reason for hiding this comment

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

Okay, now I understand. I had mistakenly added the hasattr check in my comment. I have edited it now. Everything else is fine.

@abhiabhi94
Copy link
Collaborator

Also, I had used 1 one single setting variable for allowing flags and their count. I think you have moved them to separate variables.

We can ask the developer to set the value as 0 or False(whatever you feel like) to check if flags are allowed. This will help in moving the changes to one variable.

@Radi85
Copy link
Owner Author

Radi85 commented Jun 24, 2020

Also, I had used 1 one single setting variable for allowing flags and their count. I think you have moved them to separate variables.

We can ask the developer to set the value as 0 or False(whatever you feel like) to check if flags are allowed. This will help in moving the changes to one variable.

The new variable is for new purpose.
So we have one for allowed flag counts and if it's 0 then the flagging system will be disabled
the second one is to keep the flagged comment visible to all users. We previously hided the flagged comments

@Radi85 Radi85 deleted the update-flag-states branch June 24, 2020 15:40
@abhiabhi94
Copy link
Collaborator

abhiabhi94 commented Jun 24, 2020

So we have one for allowed flag counts and if it's 0 then the flagging system will be disabled
the second one is to keep the flagged comment visible to all users. We previously hided the flagged comments

Okay. Suppose if I set allowed flag count to 10, I obviously want the comment below this number to be hidden. Do I miss something here?

One use case that I can think of is notifying the moderators after this count for a review (before which the comments should/shouldn't be visible). I don't think we have implemented this till now.

@Radi85
Copy link
Owner Author

Radi85 commented Jun 24, 2020

Okay. Suppose if I set allowed flag count to 10, I obviously want the comment below this number to be hidden. Do I miss something here?

The comment that has flags count above this number will be hidden and here comes the new variable, maybe the developer doesn't want that comment to be hidden then he can simply set COMMENT_SHOW_FLAGGED=True
I believe everything will be clear when you make a quick tour around the code. The docs

One use case that I can think of is notifying the moderators after this count for a review (before which the comments should/shouldn't be visible). I don't think we have implemented this till now.

We haven't.

@abhiabhi94
Copy link
Collaborator

Okay, One of them is used to enable the flagging system.

Also, In my opinion, the migration of comments should ideally be handled via a command to manage.py. I was feeling too lazy while adding this feature. I will work on this sometime in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants