# Path: django_sonic_screwdriver/apps/admin_comments/forms.py
# class CommentInlineForm(forms.ModelForm):
#     def __init__(self, *args, **kwargs):
#         super(CommentInlineForm, self).__init__(*args, **kwargs)
#         instance = getattr(self, "instance", None)
# 
#         self.fields["comment"].widget.attrs["rows"] = 3
# 
#         if instance and instance.pk:
#             line_height = len(instance.comment.split("\n"))
#             self.fields["comment"].widget.attrs["rows"] = line_height
#             self.fields["comment"].widget.attrs["readonly"] = True
#             self.fields["comment"].widget.attrs["border"] = 0
# 
#     class Meta:
#         model = Comment
#         exclude = []
# 
#     class Media:
#         css = {"all": ("css/admin_comments.css",)}
# 
# class CommentInlineFormset(BaseGenericInlineFormSet):
#     def save_new(self, form, commit=True):
#         setattr(form.instance, "user", self.current_user)
#         return super(CommentInlineFormset, self).save_new(form, commit=True)
# 
# Path: django_sonic_screwdriver/apps/admin_comments/models.py
# class Comment(BaseModel):
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         on_delete=models.CASCADE,
#         verbose_name=_("User"),
#         blank=False,
#         null=True,
#         help_text=_("The user is the creator of the comment."),
#     )
# 
#     comment = models.TextField(
#         verbose_name=_("Comment"),
#         blank=False,
#         null=True,
#         help_text=_("The comment itself."),
#     )
# 
#     object_id = models.CharField(
#         max_length=36,
#         verbose_name=_("Object ID"),
#         blank=True,
#         null=True,
#         help_text=_("ID of the related object."),
#     )
# 
#     content_object = GenericForeignKey(
#         ct_field="content_type", fk_field="object_id", for_concrete_model=True
#     )
# 
#     content_type = models.ForeignKey(
#         ContentType,
#         on_delete=models.CASCADE,
#         verbose_name=_("Content type"),
#         blank=False,
#         null=True,
#         help_text=_("Related content type."),
#     )
# 
#     class Meta:
#         verbose_name = _("Comment")
#         verbose_name_plural = _("Comments")
# 
#     def __str__(self):
#         return f"{self.content_type} - {self.object_id}"


from django.contrib.contenttypes.admin import GenericTabularInline
from .forms import CommentInlineForm, CommentInlineFormset
from .models import Comment



class CommentInline(GenericTabularInline):
    model = Comment

    readonly_fields = ["user", "created_at"]

    def __init__(self, *args, **kwargs):
        self.form = CommentInlineForm

# Path: django_sonic_screwdriver/apps/admin_comments/forms.py
# class CommentInlineForm(forms.ModelForm):
#     def __init__(self, *args, **kwargs):
#         super(CommentInlineForm, self).__init__(*args, **kwargs)
#         instance = getattr(self, "instance", None)
# 
#         self.fields["comment"].widget.attrs["rows"] = 3
# 
#         if instance and instance.pk:
#             line_height = len(instance.comment.split("\n"))
#             self.fields["comment"].widget.attrs["rows"] = line_height
#             self.fields["comment"].widget.attrs["readonly"] = True
#             self.fields["comment"].widget.attrs["border"] = 0
# 
#     class Meta:
#         model = Comment
#         exclude = []
# 
#     class Media:
#         css = {"all": ("css/admin_comments.css",)}
# 
# class CommentInlineFormset(BaseGenericInlineFormSet):
#     def save_new(self, form, commit=True):
#         setattr(form.instance, "user", self.current_user)
#         return super(CommentInlineFormset, self).save_new(form, commit=True)
# 
# Path: django_sonic_screwdriver/apps/admin_comments/models.py
# class Comment(BaseModel):
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         on_delete=models.CASCADE,
#         verbose_name=_("User"),
#         blank=False,
#         null=True,
#         help_text=_("The user is the creator of the comment."),
#     )
# 
#     comment = models.TextField(
#         verbose_name=_("Comment"),
#         blank=False,
#         null=True,
#         help_text=_("The comment itself."),
#     )
# 
#     object_id = models.CharField(
#         max_length=36,
#         verbose_name=_("Object ID"),
#         blank=True,
#         null=True,
#         help_text=_("ID of the related object."),
#     )
# 
#     content_object = GenericForeignKey(
#         ct_field="content_type", fk_field="object_id", for_concrete_model=True
#     )
# 
#     content_type = models.ForeignKey(
#         ContentType,
#         on_delete=models.CASCADE,
#         verbose_name=_("Content type"),
#         blank=False,
#         null=True,
#         help_text=_("Related content type."),
#     )
# 
#     class Meta:
#         verbose_name = _("Comment")
#         verbose_name_plural = _("Comments")
# 
#     def __str__(self):
#         return f"{self.content_type} - {self.object_id}"


# Path: django_sonic_screwdriver/apps/admin_comments/admin.py
from django.contrib.contenttypes.admin import GenericTabularInline
from .forms import CommentInlineForm, CommentInlineFormset
from .models import Comment




class CommentInline(GenericTabularInline):
    model = Comment

    readonly_fields = ["user", "created_at"]

    def __init__(self, *args, **kwargs):
        self.form = CommentInlineForm

        self.formset = CommentInlineFormset