setup update 3
This commit is contained in:
+27
-41
@@ -1,58 +1,44 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, IntegerField, SelectField, TextAreaField, SubmitField
|
||||
from wtforms.validators import DataRequired, NumberRange, Length, Optional
|
||||
from wtforms import StringField, IntegerField, TextAreaField, BooleanField, SubmitField, SelectField
|
||||
from wtforms.validators import DataRequired, Length, NumberRange, Optional
|
||||
|
||||
class ClassroomForm(FlaskForm):
|
||||
code = StringField('Classroom Code', validators=[
|
||||
DataRequired(),
|
||||
Length(min=2, max=20, message='Code must be between 2 and 20 characters')
|
||||
])
|
||||
name = StringField('Classroom Name', validators=[
|
||||
DataRequired(),
|
||||
Length(max=100)
|
||||
])
|
||||
# campus_id = SelectField('Campus', coerce=int, validators=[DataRequired()])
|
||||
building = StringField('Building', validators=[
|
||||
DataRequired(),
|
||||
Length(max=50)
|
||||
Length(min=2, max=100)
|
||||
])
|
||||
room_number = StringField('Room Number', validators=[
|
||||
DataRequired(),
|
||||
Length(min=1, max=50)
|
||||
])
|
||||
floor = IntegerField('Floor', validators=[
|
||||
DataRequired(),
|
||||
NumberRange(min=1, max=10)
|
||||
NumberRange(min=1, max=50)
|
||||
])
|
||||
capacity = IntegerField('Capacity', validators=[
|
||||
DataRequired(),
|
||||
NumberRange(min=1, max=200)
|
||||
NumberRange(min=1, max=500)
|
||||
])
|
||||
description = TextAreaField('Description', validators=[Optional(), Length(max=500)])
|
||||
campus_location = SelectField('Campus Location',
|
||||
choices=[
|
||||
('Main Campus', 'Main Campus'),
|
||||
('North Campus', 'North Campus'),
|
||||
('Science & Technology Campus', 'Science & Technology Campus'),
|
||||
('Downtown Campus', 'Downtown Campus')
|
||||
],
|
||||
validators=[DataRequired()])
|
||||
description = TextAreaField('Description', validators=[
|
||||
Optional(),
|
||||
Length(max=500)
|
||||
])
|
||||
is_active = BooleanField('Active', default=True)
|
||||
submit = SubmitField('Save Classroom')
|
||||
|
||||
class ClassroomResourceForm(FlaskForm):
|
||||
resource_type = SelectField('Resource Type',
|
||||
choices=[
|
||||
('PROJECTOR', 'Projector'),
|
||||
('WHITEBOARD', 'Whiteboard'),
|
||||
('SMART_BOARD', 'Smart Board'),
|
||||
('SCREEN', 'Screen'),
|
||||
('AUDIO_SYSTEM', 'Audio System'),
|
||||
('COMPUTERS', 'Computers'),
|
||||
('LAB_EQUIPMENT', 'Lab Equipment'),
|
||||
('AIR_CONDITIONING', 'Air Conditioning'),
|
||||
('HEATING', 'Heating')
|
||||
],
|
||||
validators=[DataRequired()])
|
||||
resource_type = SelectField('Resource Type', choices=[
|
||||
('PROJECTOR', 'Projector'),
|
||||
('WHITEBOARD', 'Whiteboard'),
|
||||
('COMPUTER', 'Computer'),
|
||||
('SOUND_SYSTEM', 'Sound System'),
|
||||
('MICROPHONE', 'Microphone'),
|
||||
('AIR_CONDITIONER', 'Air Conditioner'),
|
||||
('OTHER', 'Other')
|
||||
], validators=[DataRequired()])
|
||||
brand = StringField('Brand', validators=[Optional(), Length(max=100)])
|
||||
model = StringField('Model', validators=[Optional(), Length(max=100)])
|
||||
specifications = TextAreaField('Specifications', validators=[Optional(), Length(max=1000)])
|
||||
quantity = IntegerField('Quantity', validators=[
|
||||
DataRequired(),
|
||||
NumberRange(min=1, max=50)
|
||||
], default=1)
|
||||
submit = SubmitField('Add Resource')
|
||||
specifications = TextAreaField('Specifications', validators=[Optional()])
|
||||
functional = BooleanField('Functional', default=True)
|
||||
submit = SubmitField('Save Resource')
|
||||
@@ -1,19 +1,40 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SelectField, IntegerField, TextAreaField, SubmitField, DateTimeLocalField
|
||||
from wtforms.validators import DataRequired, NumberRange, Length, Optional
|
||||
from wtforms import SelectField, StringField, TextAreaField, IntegerField, SubmitField, DateTimeLocalField
|
||||
from wtforms.validators import DataRequired, Length, NumberRange, Optional, ValidationError
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
class ReservationForm(FlaskForm):
|
||||
classroom_id = SelectField('Classroom', coerce=int, validators=[DataRequired()])
|
||||
commission_id = SelectField('Commission', coerce=int, validators=[DataRequired()])
|
||||
commission_id = SelectField('Commission/Subject', coerce=int, validators=[DataRequired()])
|
||||
start_time = DateTimeLocalField('Start Time', format='%Y-%m-%dT%H:%M', validators=[DataRequired()])
|
||||
end_time = DateTimeLocalField('End Time', format='%Y-%m-%dT%H:%M', validators=[DataRequired()])
|
||||
purpose = StringField('Purpose', validators=[
|
||||
DataRequired(),
|
||||
Length(max=500, message='Purpose must be less than 500 characters')
|
||||
Length(min=3, max=500)
|
||||
])
|
||||
expected_attendees = IntegerField('Expected Attendees', validators=[
|
||||
DataRequired(),
|
||||
NumberRange(min=1, max=200, message='Number of attendees must be between 1 and 200')
|
||||
NumberRange(min=1, max=500)
|
||||
])
|
||||
notes = TextAreaField('Notes', validators=[Optional(), Length(max=1000)])
|
||||
submit = SubmitField('Save Reservation')
|
||||
notes = TextAreaField('Notes', validators=[
|
||||
Optional(),
|
||||
Length(max=1000)
|
||||
])
|
||||
submit = SubmitField('Make Reservation')
|
||||
|
||||
def validate_end_time(self, field):
|
||||
if field.data <= self.start_time.data:
|
||||
raise ValidationError('End time must be after start time.')
|
||||
|
||||
# Check if duration is reasonable (max 8 hours)
|
||||
if field.data > self.start_time.data + timedelta(hours=8):
|
||||
raise ValidationError('Reservation cannot exceed 8 hours.')
|
||||
|
||||
def validate_start_time(self, field):
|
||||
# Don't allow reservations in the past
|
||||
if field.data < datetime.now():
|
||||
raise ValidationError('Start time cannot be in the past.')
|
||||
|
||||
# Don't allow reservations too far in the future (max 3 months)
|
||||
if field.data > datetime.now() + timedelta(days=90):
|
||||
raise ValidationError('Reservations cannot be made more than 3 months in advance.')
|
||||
Reference in New Issue
Block a user