Skip to content
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

Increase tn_priority max value to 9999999999 #166

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

simensol
Copy link
Contributor

@simensol simensol commented Sep 20, 2024

Describe your changes
I want to use the current timestamp (epoch) to sort the tree nodes by creation date, e.g., 1726814949. Although priority_max = 9999999999 in __get_node_order_str:

def __get_node_order_str(self):
priority_max = 9999999999
priority_len = len(str(priority_max))
priority_val = priority_max - min(self.tn_priority, priority_max)
priority_key = str(priority_val).zfill(priority_len)
alphabetical_val = slugify(str(self))
alphabetical_key = alphabetical_val.ljust(priority_len, "z")
alphabetical_key = alphabetical_key[0:priority_len]

the maximum value of the tn_priority field is set to MaxValueValidator(9999):

tn_priority = models.PositiveIntegerField(
default=0,
validators=[MinValueValidator(0), MaxValueValidator(9999)],
verbose_name=_("Priority"),
)

My current workaround is to overwrite the tn_priority field in my own model:

class MyModel(TreeNodeModel):
    ...
    tn_priority = models.PositiveIntegerField(
        default=0,
        validators=[MinValueValidator(0), MaxValueValidator(9999999999)],
        verbose_name=_("Priority"),
    )

This pull request increases the maximum value for tn_priority to 9999999999, enabling the use of timestamps for sorting and aligning it with the priority_max value in __get_node_order_str.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

@fabiocaccamo
Copy link
Owner

@simensol thank you for this useful PR!

@fabiocaccamo fabiocaccamo merged commit d42d166 into fabiocaccamo:main Sep 20, 2024
51 checks passed
@fabiocaccamo fabiocaccamo added the enhancement New feature or request label Sep 20, 2024
@fabiocaccamo fabiocaccamo self-assigned this Sep 20, 2024
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.96%. Comparing base (5663c5b) to head (95a841d).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #166   +/-   ##
=======================================
  Coverage   90.96%   90.96%           
=======================================
  Files          11       11           
  Lines         697      697           
=======================================
  Hits          634      634           
  Misses         63       63           
Flag Coverage Δ
unittests 90.96% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fabiocaccamo
Copy link
Owner

@simensol thank you for this PR, you can upgrade to 0.22.1 version!

@simensol
Copy link
Contributor Author

Thanks @fabiocaccamo, and I appreciate the fast response! The PR was merged before I even managed to apply the workaround to my own repository. Looking forward to using the new version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants