Skip to content

Commit

Permalink
feat(Besoins): Nouveau champ M2M 'admins' pour aider le suivi (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Mar 6, 2024
1 parent 6f014b3 commit e042239
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from lemarche.tenders.forms import TenderAdminForm
from lemarche.tenders.models import PartnerShareTender, Tender, TenderQuestion, TenderSiae, TenderStepsData
from lemarche.users import constants as user_constants
from lemarche.users.models import User
from lemarche.utils.admin.admin_site import admin_site
from lemarche.utils.fields import ChoiceArrayField, pretty_print_readonly_jsonfield
from lemarche.www.tenders.tasks import restart_send_tender_task
Expand Down Expand Up @@ -190,7 +191,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
ordering = ["-created_at"]

form = TenderForm
autocomplete_fields = ["sectors", "location", "perimeters", "author"]
autocomplete_fields = ["sectors", "location", "perimeters", "author", "admins"]
readonly_fields = [field for field in Tender.READONLY_FIELDS] + [
# slug
# status
Expand Down Expand Up @@ -359,6 +360,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
)
},
),
("Suivi", {"fields": ("admins",)}),
(
"Stats",
{
Expand Down Expand Up @@ -414,6 +416,11 @@ def get_readonly_fields(self, request, obj=None):
readonly_fields.append("slug")
return readonly_fields

def formfield_for_manytomany(self, db_field, request, **kwargs):
if db_field.name == "admins":
kwargs["queryset"] = User.objects.filter(kind=User.KIND_ADMIN)
return super().formfield_for_manytomany(db_field, request, **kwargs)

def save_model(self, request, obj: Tender, form, change):
"""
Set Tender author on create
Expand Down
6 changes: 6 additions & 0 deletions lemarche/tenders/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def siaes(self, create, extracted, **kwargs):
# Add the iterable of groups using bulk addition
self.siaes.add(*extracted)

@factory.post_generation
def admins(self, create, extracted, **kwargs):
if extracted:
# Add the iterable of groups using bulk addition
self.admins.add(*extracted)


class TenderQuestionFactory(DjangoModelFactory):
class Meta:
Expand Down
25 changes: 25 additions & 0 deletions lemarche/tenders/migrations/0078_tender_admins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.9 on 2024-03-04 13:32

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("tenders", "0077_alter_tender_siae_kind"),
]

operations = [
migrations.AddField(
model_name="tender",
name="admins",
field=models.ManyToManyField(
blank=True,
help_text="Champ renseigné par un ADMIN",
related_name="tenders_admins",
to=settings.AUTH_USER_MODEL,
verbose_name="Admin(s) du besoin",
),
),
]
8 changes: 8 additions & 0 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,14 @@ class Tender(models.Model):
siae_list_last_seen_date = models.DateTimeField(
"Date de dernière visite de l'auteur sur la page 'structures intéressées'", blank=True, null=True
)

admins = models.ManyToManyField(
"users.User",
verbose_name="Admin(s) du besoin",
help_text=ADMIN_FIELD_HELP_TEXT,
related_name="tenders_admins",
blank=True,
)
logs = models.JSONField(verbose_name="Logs historiques", editable=False, default=list)
source = models.CharField(
verbose_name="Source",
Expand Down

0 comments on commit e042239

Please sign in to comment.