2020-12-24 15:30:45 -05:00
|
|
|
from datetime import datetime
|
|
|
|
|
2020-12-03 12:31:39 -05:00
|
|
|
from django import forms
|
2024-01-17 21:17:24 -05:00
|
|
|
|
2021-05-20 18:00:12 -04:00
|
|
|
from markdownx.widgets import MarkdownxWidget
|
2020-12-03 12:31:39 -05:00
|
|
|
|
|
|
|
from .models import Event
|
|
|
|
|
2022-01-24 23:37:04 -05:00
|
|
|
|
2020-12-03 12:31:39 -05:00
|
|
|
class EventForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Event
|
2022-01-24 23:37:04 -05:00
|
|
|
fields = ["date", "user", "notes"]
|
2021-05-20 18:00:12 -04:00
|
|
|
widgets = {
|
2022-01-24 23:37:04 -05:00
|
|
|
"notes": MarkdownxWidget(attrs={"rows": 2}),
|
2021-05-20 18:00:12 -04:00
|
|
|
}
|
2020-12-24 15:30:45 -05:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2022-01-24 23:37:04 -05:00
|
|
|
user = kwargs.pop("user")
|
2020-12-24 15:30:45 -05:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-01-24 23:37:04 -05:00
|
|
|
self.fields["date"].initial = datetime.now()
|
|
|
|
self.fields["user"].initial = user
|
2020-12-24 15:31:43 -05:00
|
|
|
if not user.is_staff:
|
2022-01-24 23:37:04 -05:00
|
|
|
print(list(self.fields["user"].choices))
|
|
|
|
self.fields["user"].choices = [(user.id, user)]
|