Add auto-approval for moderator submissions and update submission handling
@@ -206,7 +206,7 @@ class ManufacturerDetailView(SlugRedirectMixin, EditSubmissionMixin, PhotoSubmis
|
||||
|
||||
|
||||
def _handle_submission(
|
||||
request: Any, form: Any, model: ModelType, success_url: str
|
||||
request: Any, form: Any, model: ModelType, success_url: str = ""
|
||||
) -> HttpResponseRedirect:
|
||||
"""Helper method to handle form submissions"""
|
||||
cleaned_data = form.cleaned_data.copy()
|
||||
@@ -214,6 +214,7 @@ def _handle_submission(
|
||||
user=request.user,
|
||||
content_type=ContentType.objects.get_for_model(model),
|
||||
submission_type="CREATE",
|
||||
status="NEW",
|
||||
changes=cleaned_data,
|
||||
reason=request.POST.get("reason", ""),
|
||||
source=request.POST.get("source", ""),
|
||||
@@ -229,6 +230,12 @@ def _handle_submission(
|
||||
submission.status = "APPROVED"
|
||||
submission.handled_by = request.user
|
||||
submission.save()
|
||||
|
||||
# Generate success URL if not provided
|
||||
if not success_url:
|
||||
success_url = reverse(
|
||||
f"companies:{model.__name__.lower()}_detail", kwargs={"slug": obj.slug}
|
||||
)
|
||||
messages.success(request, f'Successfully created {getattr(obj, "name", "")}')
|
||||
return HttpResponseRedirect(success_url)
|
||||
|
||||
@@ -244,10 +251,7 @@ class CompanyCreateView(LoginRequiredMixin, CreateView):
|
||||
object: Optional[Company]
|
||||
|
||||
def form_valid(self, form: CompanyForm) -> HttpResponseRedirect:
|
||||
success_url = reverse(
|
||||
"companies:company_detail", kwargs={"slug": form.instance.slug}
|
||||
)
|
||||
return _handle_submission(self.request, form, self.model, success_url)
|
||||
return _handle_submission(self.request, form, self.model, "")
|
||||
|
||||
def get_success_url(self) -> str:
|
||||
if self.object is None:
|
||||
@@ -262,10 +266,7 @@ class ManufacturerCreateView(LoginRequiredMixin, CreateView):
|
||||
object: Optional[Manufacturer]
|
||||
|
||||
def form_valid(self, form: ManufacturerForm) -> HttpResponseRedirect:
|
||||
success_url = reverse(
|
||||
"companies:manufacturer_detail", kwargs={"slug": form.instance.slug}
|
||||
)
|
||||
return _handle_submission(self.request, form, self.model, success_url)
|
||||
return _handle_submission(self.request, form, self.model, "")
|
||||
|
||||
def get_success_url(self) -> str:
|
||||
if self.object is None:
|
||||
|
||||
BIN
media/submissions/photos/test_0KnoSgG.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_3LucxDK.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_4TRPE6Y.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_5KD0KRW.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_66qSjsN.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_67QBAK0.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_DrkLE8K.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_IsnDmeY.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_LPkIUyk.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_Oha7RwK.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_RpGxPCG.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_S2JX5Nx.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_TLfYnGO.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_U37Ca0y.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_UBDlVqD.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_aOIN0P5.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_dUweQ8o.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_ez4Nn2l.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_gsmEklC.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_ilc2eam.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_m5s47vB.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_mklzbsE.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_oijLFZj.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_ubzj2io.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_wHX7LMT.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_x2OOj5F.gif
Normal file
|
After Width: | Height: | Size: 35 B |
BIN
media/submissions/photos/test_zxg9z0k.gif
Normal file
|
After Width: | Height: | Size: 35 B |
@@ -278,6 +278,16 @@ class PhotoSubmission(models.Model):
|
||||
self.notes = notes
|
||||
self.save()
|
||||
|
||||
def auto_approve(self) -> None:
|
||||
"""Auto-approve submissions from moderators"""
|
||||
# Get user role safely
|
||||
user_role = getattr(self.user, "role", None)
|
||||
|
||||
# If user is moderator or above, auto-approve
|
||||
if user_role in ["MODERATOR", "ADMIN", "SUPERUSER"]:
|
||||
self.approve(self.user)
|
||||
|
||||
|
||||
def escalate(self, moderator: UserType, notes: str = "") -> None:
|
||||
"""Escalate the photo submission to admin"""
|
||||
self.status = "ESCALATED"
|
||||
|
||||
@@ -24,6 +24,7 @@ django-webpack-loader==3.1.1
|
||||
python-dotenv==1.0.1
|
||||
Pillow==11.1.0 # For image handling
|
||||
django-cleanup==9.0.0 # Automatically delete files
|
||||
piexif==1.1.3 # For image EXIF metadata handling
|
||||
django-filter==24.3
|
||||
django-htmx==1.21.0
|
||||
whitenoise==6.8.2 # Static file serving
|
||||
|
||||