@ -1,14 +1,14 @@
from django import forms
from django . contrib . auth . forms import UserCreationForm
from django . utils import timezone
from crispy_forms . helper import FormHelper
from crispy_forms . layout import Submit , Layout
from django import forms
from django . contrib . auth . forms import UserCreationForm
from django . urls import reverse
from django . utils import timezone
from . models import User , Reference , QSO , ShadowCall , EntryCategory , Contest
from . validators import CallUsernameValidator , CallLogValidator
class CustomUserCreationForm ( UserCreationForm ) :
class Meta :
model = User
@ -17,11 +17,15 @@ class CustomUserCreationForm(UserCreationForm):
username = forms . CharField ( max_length = 50 , validators = [ CallUsernameValidator ( ) ] )
email = forms . EmailField ( required = True )
class UpdateRefForm ( forms . Form ) :
existingRef = forms . ModelChoiceField ( label = " Existing Exchange " , queryset = Reference . objects . all ( ) , help_text = " If exchange already exists, select it here. " , required = False )
newRefName = forms . CharField ( max_length = 50 , label = " New Exchange " , help_text = " Enter name of new exchange, if we should create a new " , required = False )
existingRef = forms . ModelChoiceField ( label = " Existing Exchange " , queryset = Reference . objects . all ( ) ,
help_text = " If exchange already exists, select it here. " , required = False )
newRefName = forms . CharField ( max_length = 50 , label = " New Exchange " ,
help_text = " Enter name of new exchange, if we should create a new " , required = False )
location = forms . CharField ( max_length = 128 , label = ' Exact Location ' , help_text = " E.g. MAR bei den Fahrstuehlen, TEL 15. OG " , required = False )
location = forms . CharField ( max_length = 128 , label = ' Exact Location ' ,
help_text = " E.g. MAR bei den Fahrstuehlen, TEL 15. OG " , required = False )
opName = forms . CharField ( max_length = 128 , label = ' Operators ' , help_text = " Name of operator(s) " , required = False )
regTime = forms . DateTimeField ( label = " Registration time " , help_text = " Time of Registration " )
@ -49,8 +53,10 @@ class UpdateRefForm(forms.Form):
if not existingRef and not newRefName :
raise forms . ValidationError ( " Select either an existing exchange or create a new one! " )
class UpdateCategoryForm ( forms . Form ) :
entry = forms . ModelChoiceField ( label = " Entry category " , queryset = EntryCategory . objects . all ( ) )
def __init__ ( self , * args , * * kwargs ) :
super ( UpdateCategoryForm , self ) . __init__ ( * args , * * kwargs )
@ -68,10 +74,11 @@ class UpdateCategoryForm(forms.Form):
if contest . deadline < timezone . now ( ) :
raise forms . ValidationError ( " The deadline for setting your contest category has passed " )
class QSOForm ( forms . ModelForm ) :
class Meta :
model = QSO
# fields = ["ownNo", "band", "call", "reportTX", "reportRX", "refStr", "otherNo", "remarks"]
# fields = ["ownNo", "band", "call", "reportTX", "reportRX", "refStr", "otherNo", "remarks"]
fields = [ " ownNo " , " band " , " call " , " reportTX " , " reportRX " , " refStr " , " remarks " ]
def __init__ ( self , user , * args , * * kwargs ) :
@ -80,17 +87,16 @@ class QSOForm(forms.ModelForm):
self . helper = FormHelper ( )
self . helper . form_id = " qso-log-form "
# self.helper.form_class = "form-inline "
# self.helper.form_class = "form-horizontal"
# self.helper.form_style = 'inline'
# self.helper.field_template = "bootstrap3/layout/inline_field.html"
# self.helper.form_class = "form-inline "
# self.helper.form_class = "form-horizontal"
# self.helper.form_style = 'inline'
# self.helper.field_template = "bootstrap3/layout/inline_field.html"
self . helper . action = reverse ( " contest:log " )
self . helper . add_input ( Submit ( ' submit ' , ' Log ' ) )
# self.helper.layout = Layout(
# self.helper.layout = Layout(
# #*(QSOForm.Meta.fields + [ButtonHolder(Submit('submit', 'Submit', css_class='button white'))]))
# *(QSOForm.Meta.fields + [FormActions(Submit('submit', 'Log!'))]))
def clean_call ( self ) :
data = self . cleaned_data [ " call " ] . upper ( ) . strip ( )
@ -141,12 +147,14 @@ class QSOForm(forms.ModelForm):
if band . contest . deadline < timezone . now ( ) :
raise forms . ValidationError ( " The deadline for logging and editing QSOs has passed " )
class QSOFormWithTime ( QSOForm ) :
class Meta :
model = QSO
# fields = ["time", "ownNo", "band", "call", "reportTX", "reportRX", "otherNo", "refStr", "remarks"]
# fields = ["time", "ownNo", "band", "call", "reportTX", "reportRX", "otherNo", "refStr", "remarks"]
fields = [ " time " , " ownNo " , " band " , " call " , " reportTX " , " reportRX " , " refStr " , " remarks " ]
class ShadowCallAddForm ( forms . ModelForm ) :
class Meta :