2022-05-07 14:51:26 -07:00
|
|
|
from django.conf import settings
|
2022-05-07 13:24:43 -07:00
|
|
|
from django.forms import ModelForm
|
2022-06-14 14:56:50 -07:00
|
|
|
from board.models import Post, Report
|
2022-05-07 14:51:26 -07:00
|
|
|
from hcaptcha.fields import hCaptchaField
|
2022-05-07 13:24:43 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PostForm(ModelForm):
|
|
|
|
|
"""
|
|
|
|
|
A form used for new threads for posts.
|
|
|
|
|
|
|
|
|
|
This requires the board and the IP address to be specified.
|
|
|
|
|
"""
|
|
|
|
|
|
2022-05-07 14:51:26 -07:00
|
|
|
hcaptcha = hCaptchaField() if settings.USE_HCAPTCHA else None
|
|
|
|
|
|
2022-05-07 13:24:43 -07:00
|
|
|
class Meta:
|
|
|
|
|
model = Post
|
|
|
|
|
fields = ["subject", "name", "text", "image"]
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, board, ip, **kwargs):
|
|
|
|
|
super(PostForm, self).__init__(*args, **kwargs)
|
|
|
|
|
self.instance.board = board
|
|
|
|
|
self.instance.ip = ip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReplyForm(PostForm):
|
|
|
|
|
"""
|
|
|
|
|
A form used for replies to posts.
|
|
|
|
|
|
|
|
|
|
This requires the OP post, the reply post, the board, and the IP address be
|
|
|
|
|
specified.
|
|
|
|
|
"""
|
|
|
|
|
|
2022-05-07 14:51:26 -07:00
|
|
|
hcaptcha = hCaptchaField() if settings.USE_HCAPTCHA else None
|
|
|
|
|
|
2022-05-07 13:24:43 -07:00
|
|
|
class Meta:
|
|
|
|
|
model = Post
|
2022-05-07 13:51:03 -07:00
|
|
|
fields = ["name", "text", "bump", "image"]
|
2022-05-07 13:24:43 -07:00
|
|
|
|
|
|
|
|
def __init__(self, *args, op, reply, **kwargs):
|
|
|
|
|
super(ReplyForm, self).__init__(*args, **kwargs)
|
|
|
|
|
self.instance.op = op
|
|
|
|
|
self.instance.reply = reply
|
2022-06-14 14:56:50 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReportForm(ModelForm):
|
|
|
|
|
"""
|
|
|
|
|
A form used to create reports on posts.
|
|
|
|
|
|
|
|
|
|
This requires the board and the IP address to be specified.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
model = Report
|
|
|
|
|
fields = ["reason"]
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, op, board, ip, **kwargs):
|
|
|
|
|
super(ReportForm, self).__init__(*args, **kwargs)
|
|
|
|
|
self.instance.ip = ip
|
|
|
|
|
self.instance.post = op
|