Skip to content
/ django Public

Fixed #13376: Added restrictions to messages to control when they are hidden.#18286

Draft
nanorepublica wants to merge 3 commits intodjango:mainfrom
nanorepublica:ticket_13376
Draft

Fixed #13376: Added restrictions to messages to control when they are hidden.#18286
nanorepublica wants to merge 3 commits intodjango:mainfrom
nanorepublica:ticket_13376

Conversation

@nanorepublica
Copy link
Contributor

@nanorepublica nanorepublica commented Jun 19, 2024

Trac ticket number

ticket-13376

Branch description

This PR adds the ability to control when a message is hidden from view.

Currently there is restrictions for the number of times a message is iterated over and for an expiry time.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@nanorepublica nanorepublica changed the title Initial application of last patch from #13376 and made tests pass Refs #13376 Allow messages to have restrictions to control when they are hidden Jun 19, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

@nanorepublica
Copy link
Contributor Author

This is my initial application of the last patch attached to the Trac ticket.

There is more to do to apply the full patch, which I will be adding soon

@nanorepublica nanorepublica changed the title Refs #13376 Allow messages to have restrictions to control when they are hidden Fixed #13376: Added restrictions to messages to control when they are hidden Jul 2, 2024
@nanorepublica nanorepublica changed the title Fixed #13376: Added restrictions to messages to control when they are hidden Fixed #13376: Added restrictions to messages to control when they are hidden. Jul 2, 2024
Copy link
Contributor

@matthiask matthiask left a comment

Choose a reason for hiding this comment

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

Interesting, thanks. I want to pay attention to this because of https://pypi.org/project/django_user_messages/

return (
self.level == other.level
and self.message == other.message
and self.restrictions == other.restrictions
Copy link
Contributor

Choose a reason for hiding this comment

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

If restrictions were made hashable self.restrictions could be a set(), which would mean that this comparison isn't depending upon the ordering of restrictions in the messages themselves.

def create_message(self, *vars):
"""creates message on the basis of encoded data"""
args = vars[:-1]
restrictions = vars[-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate keyword-only arguments...! Makes sense, but it's not nice to look at.

@nanorepublica
Copy link
Contributor Author

@matthiask Thanks for the notes. This PR is a simple application of the patch that was originally on the ticket with most conflicts resolved.

I am pausing on this PR until I get this smaller PR merged with does less in terms of code changes but allows third-party packages like yours to extend the messages framework in a more useful way which would include the restrictions mentioned here. Once that PR is merged I will reconsider this PR in the context of the ticket.

Copy link
Contributor

@anorthall anorthall left a comment

Choose a reason for hiding this comment

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

Just some small comments!

Edit: looked at the wrong PR 🫣

created = time_provider.time()
self.expires = created + int(seconds)

def set_expirity_time(self, expiration_time):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def set_expirity_time(self, expiration_time):
def set_expiry_time(self, expiration_time):


def set_expirity_time(self, expiration_time):
"""
Sets expilcity expiration time
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Sets expilcity expiration time
Set expiration time to the given absolute value

Comment on lines +71 to +73
def from_json_param(cls, expirity_time):
ret = TimeRestriction(0)
ret.set_expirity_time(expirity_time)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def from_json_param(cls, expirity_time):
ret = TimeRestriction(0)
ret.set_expirity_time(expirity_time)
def from_json_param(cls, expiry_time):
ret = TimeRestriction(0)
ret.set_expiry_time(expiry_time)


def __init__(self, amount):
assert int(amount) >= 0
Restriction.__init__(self, "amount")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use a call to super() instead of calling Restriction explicitly?

self.level = int(level)
self.message = message
self.extra_tags = extra_tags
self.restrictions = restrictions or list([res.AmountRestriction(1)])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the list() call necessary?

"""

def __init__(self, level, message, extra_tags=None):
def __init__(self, level, message, extra_tags=None, restrictions=[]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to keep away from putting a mutable list as a default, and use None, in case it opens up to mutation bugs later?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants