fichier - formualaire offre, minimum 1 dept pour une offre, ameliorations date expiration

This commit is contained in:
Arthur ZHU 2022-04-12 19:44:09 +02:00
parent 77eefbe483
commit 37832c5bb1
3 changed files with 48 additions and 11 deletions

View File

@ -82,13 +82,6 @@ class EntrepriseCreationForm(FlaskForm):
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
def validate(self):
validate = True
if not FlaskForm.validate(self):
validate = False
return validate
def validate_siret(self, siret):
if EntreprisePreferences.get_check_siret():
siret_data = siret.data.replace(" ", "")
@ -151,7 +144,14 @@ class OffreCreationForm(FlaskForm):
duree = _build_string_field("Durée (*)")
depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
expiration_date = DateField("Date expiration", validators=[Optional()])
correspondant = SelectField("Correspondant à contacté (*)", validators=[Optional()])
correspondant = SelectField("Correspondant à contacté", validators=[Optional()])
fichier = FileField(
"Fichier (*)",
validators=[
Optional(),
FileAllowed(["pdf", "docx"], "Fichier .pdf ou .docx uniquement"),
],
)
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
def __init__(self, *args, **kwargs):
@ -168,6 +168,17 @@ class OffreCreationForm(FlaskForm):
(dept.id, dept.acronym) for dept in Departement.query.all()
]
def validate(self):
validate = True
if not FlaskForm.validate(self):
validate = False
if len(self.depts.data) < 1:
self.depts.errors.append("Choisir au moins un département")
validate = False
return validate
class OffreModificationForm(FlaskForm):
hidden_entreprise_id = HiddenField()
@ -203,6 +214,17 @@ class OffreModificationForm(FlaskForm):
(dept.id, dept.acronym) for dept in Departement.query.all()
]
def validate(self):
validate = True
if not FlaskForm.validate(self):
validate = False
if len(self.depts.data) < 1:
self.depts.errors.append("Choisir au moins un département")
validate = False
return validate
class CorrespondantCreationForm(FlaskForm):
nom = _build_string_field("Nom (*)", render_kw={"class": "form-control"})

View File

@ -18,7 +18,6 @@ from app.entreprises.forms import (
SuppressionConfirmationForm,
OffreCreationForm,
OffreModificationForm,
CorrespondantCreationForm,
CorrespondantModificationForm,
ContactCreationForm,
ContactModificationForm,
@ -509,6 +508,19 @@ def add_offre(id):
dept_id=dept,
)
db.session.add(offre_dept)
if form.fichier.data:
date = f"{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}"
path = os.path.join(
Config.SCODOC_VAR_DIR,
"entreprises",
f"{offre.entreprise_id}",
f"{offre.id}",
f"{date}",
)
os.makedirs(path)
file = form.fichier.data
filename = secure_filename(file.filename)
file.save(os.path.join(path, filename))
log = EntrepriseLog(
authenticated_user=current_user.user_name,
object=entreprise.id,

View File

@ -25,14 +25,17 @@
var closest_form_control = champ_depts.closest(".form-control")
closest_form_control.classList.remove("form-control")
}
if(document.getElementById("expiration_date").value === "")
expiration()
document.getElementById("type_offre").addEventListener("change", expiration);
function expiration() {
var date = new Date()
var expiration = document.getElementById("expiration_date")
var type_offre = document.getElementById("type_offre").value
if (type_offre == "Alternance") {
if (type_offre === "Alternance") {
expiration.value = `${date.getFullYear() + 1}-01-01`
} else {
if(date.getMonth() + 1 < 7)