fix: Show name of reported content
This commit is contained in:
		@@ -680,6 +680,21 @@ class Report(models.Model):
 | 
			
		||||
    def get_moderation_actions(self):
 | 
			
		||||
        return ModerationAction.objects.filter(report=self)
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def reported_content(self):
 | 
			
		||||
        """
 | 
			
		||||
        Dynamically fetch the reported content based on subclass.
 | 
			
		||||
        The alternative would be to use the ContentType framework:
 | 
			
		||||
        https://docs.djangoproject.com/en/5.1/ref/contrib/contenttypes/
 | 
			
		||||
        """
 | 
			
		||||
        print("dodo")
 | 
			
		||||
        if hasattr(self, "reportadoptionnotice"):
 | 
			
		||||
            return self.reportadoptionnotice.adoption_notice
 | 
			
		||||
        elif hasattr(self, "reportcomment"):
 | 
			
		||||
            return self.reportcomment.reported_comment
 | 
			
		||||
        print("dada")
 | 
			
		||||
        return "didi"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ReportAdoptionNotice(Report):
 | 
			
		||||
    adoption_notice = models.ForeignKey("AdoptionNotice", on_delete=models.CASCADE)
 | 
			
		||||
@@ -688,6 +703,9 @@ class ReportAdoptionNotice(Report):
 | 
			
		||||
    def reported_content(self):
 | 
			
		||||
        return self.adoption_notice
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return f"Report der Vermittlung {self.adoption_notice}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ReportComment(Report):
 | 
			
		||||
    reported_comment = models.ForeignKey("Comment", on_delete=models.CASCADE)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,7 @@
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
<div class="report card">
 | 
			
		||||
    <h2>
 | 
			
		||||
        {% blocktranslate %}
 | 
			
		||||
            Meldung von {{ report.reported_content }}
 | 
			
		||||
        {% endblocktranslate %}
 | 
			
		||||
        {% translate 'Meldung von ' %}<i>{{ report.reported_content }}</i>
 | 
			
		||||
    </h2>
 | 
			
		||||
    {% if report.reported_broken_rules %}
 | 
			
		||||
        {% translate "Regeln gegen die Verstoßen wurde" %}
 | 
			
		||||
 
 | 
			
		||||
@@ -429,7 +429,8 @@ def report_detail(request, report_id, form_complete=False):
 | 
			
		||||
    """
 | 
			
		||||
    Detailed view of a report, including moderation actions
 | 
			
		||||
    """
 | 
			
		||||
    report = Report.objects.get(pk=report_id)
 | 
			
		||||
    # Prefetching reduces the number of queries to the database that are needed (see reported_content)
 | 
			
		||||
    report = Report.objects.select_related("reportadoptionnotice", "reportcomment").get(pk=report_id)
 | 
			
		||||
    moderation_actions = ModerationAction.objects.filter(report_id=report_id)
 | 
			
		||||
    is_mod_or_above = user_is_trust_level_or_above(request.user, TrustLevel.MODERATOR)
 | 
			
		||||
 | 
			
		||||
@@ -505,7 +506,7 @@ def my_profile(request):
 | 
			
		||||
 | 
			
		||||
@user_passes_test(user_is_trust_level_or_above)
 | 
			
		||||
def modqueue(request):
 | 
			
		||||
    open_reports = Report.objects.filter(status=Report.WAITING)
 | 
			
		||||
    open_reports = Report.objects.select_related("reportadoptionnotice", "reportcomment").filter(status=Report.WAITING)
 | 
			
		||||
    context = {"reports": open_reports}
 | 
			
		||||
    return render(request, 'fellchensammlung/modqueue.html', context=context)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user