Skip to content

Commit

Permalink
Add command to send validated tenders
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Dec 1, 2023
1 parent 1324a83 commit 6be2f87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lemarche/tenders/management/commands/send_validated_tenders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.core.management.base import BaseCommand

from lemarche.tenders.models import Tender
from lemarche.www.tenders.tasks import send_validated_tender


class Command(BaseCommand):
"""
Command to send validated tenders
Usage: python manage.py send_validated_tenders
"""

def handle(self, *args, **options):
validated_tenders_to_send = Tender.objects.validated_but_not_sent()
if validated_tenders_to_send.count():
self.stdout.write(f"Found {validated_tenders_to_send.count()} validated tender(s) to send")
for tender in validated_tenders_to_send:
send_validated_tender(tender)
3 changes: 3 additions & 0 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def by_user(self, user):
def validated(self):
return self.filter(validated_at__isnull=False)

def validated_but_not_sent(self):
return self.filter(validated_at__isnull=False).filter(sent_at__isnull=True)

def sent(self):
return self.filter(sent_at__isnull=False)

Expand Down

0 comments on commit 6be2f87

Please sign in to comment.