-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: supprimer les traces d'envoi d'emails de plus de 90 jours #902
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b0e691
setup logger for management commands
vincentporte f1f725d
add mixin to override auto_now_add property on models in factories
vincentporte d39aa48
get better EmailSentTrack factory
vincentporte 2a0a13d
add delete_old_records method on EmailSentTrack
vincentporte 7c33e90
setup weekly command to delete old records
vincentporte 84f5990
enhance admin, let user filter on status_code
vincentporte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
lacommunaute/notification/management/commands/delete_old_email_sent_tracks.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from logging import getLogger | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from lacommunaute.notification.models import EmailSentTrack | ||
|
||
|
||
logger = getLogger("commands") | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Supprimer les anciens enregistrements EmailSentTrack" | ||
|
||
def handle(self, *args, **options): | ||
nb_deleted = EmailSentTrack.objects.delete_old_records() | ||
logger.info("%s enregistrements EmailSentTrack supprimés", nb_deleted) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
lacommunaute/notification/tests/tests_management_commands.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from dateutil.relativedelta import relativedelta | ||
from django.core.management import call_command | ||
from django.utils import timezone | ||
|
||
from lacommunaute.notification.factories import EmailSentTrackFactory | ||
from lacommunaute.notification.models import EmailSentTrack | ||
|
||
|
||
def test_delete_old_email_sent_tracks(db): | ||
EmailSentTrackFactory(created=timezone.now() - relativedelta(days=90)) | ||
call_command("delete_old_email_sent_tracks") | ||
assert EmailSentTrack.objects.count() == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AutoNowAddOverrideMixin: | ||
"""This mixin allows you to override fields with `auto_now=True`""" | ||
|
||
@classmethod | ||
def _create(cls, model_class, *args, **kwargs): | ||
auto_now_add_desactivated = [] | ||
for field in model_class._meta.get_fields(): | ||
if getattr(field, "auto_now_add", False) and kwargs.get(field.name): | ||
field.auto_now_add = False | ||
auto_now_add_desactivated.append(field) | ||
try: | ||
return super()._create(model_class, *args, **kwargs) | ||
finally: | ||
for field in auto_now_add_desactivated: | ||
field.auto_now_add = True |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
mais du coup le champ n'est pas renseigné, le but c'est forcer à le renseigner à l'appel de la factory ?
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.
ajout de
dans
EmailSentTrackFactory
.Merci @tonial