-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add promo video to form #1292
base: master
Are you sure you want to change the base?
Add promo video to form #1292
Changes from all commits
d250287
b252203
2d7445a
5f25e7f
a0cb330
2108f83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.2 on 2024-09-10 19:39 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('samfundet', '0007_recruitmentgangstat'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='recruitment', | ||
name='promo_media', | ||
field=models.CharField(default=None, help_text='Youtube video id', max_length=11, null=True), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
import re | ||
import itertools | ||
from typing import TYPE_CHECKING | ||
from collections import defaultdict | ||
|
@@ -719,11 +720,20 @@ class Meta: | |
|
||
class RecruitmentSerializer(CustomBaseSerializer): | ||
separate_positions = RecruitmentSeparatePositionSerializer(many=True, read_only=True) | ||
promo_media = serializers.CharField(max_length=100) | ||
|
||
class Meta: | ||
model = Recruitment | ||
fields = '__all__' | ||
|
||
def validate_promo_media(self, value: str | None) -> str | None: | ||
if (value is None): | ||
return None | ||
match = re.search(r'(youtu.*be.*)\/(watch\?v=|embed\/|v|shorts|)(.*?((?=[&#?])|$))', value) | ||
if (match): | ||
return match.group(3) | ||
raise ValidationError("Invalid youtube url") | ||
|
||
Comment on lines
+729
to
+736
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hvor brukes denne? Bør nok være i recruitment og ikke serializer. Validate blir brukt i andre steder i recruitment model objektet, kan sette dette opp der There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kan i samme sleng påkreve kun siste biten av url, og så manuellt legge den til når den vises There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Den kjøres av seg selv, django magic ellerno There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
class RecruitmentForRecruiterSerializer(CustomBaseSerializer): | ||
seperate_positions = RecruitmentSeparatePositionSerializer(many=True, read_only=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'; | |
import { useNavigate, useParams, useRouteLoaderData } from 'react-router-dom'; | ||
import { toast } from 'react-toastify'; | ||
import { DropDownOption } from '~/Components/Dropdown/Dropdown'; | ||
import { SamfForm } from '~/Forms/SamfForm'; | ||
import { SamfError, SamfForm } from '~/Forms/SamfForm'; | ||
import { SamfFormField } from '~/Forms/SamfFormField'; | ||
import { getOrganizations, postRecruitment, putRecruitment } from '~/api'; | ||
import { OrganizationDto, RecruitmentDto } from '~/dto'; | ||
|
@@ -24,8 +24,18 @@ type FormType = { | |
reprioritization_deadline_for_applicant: string; | ||
reprioritization_deadline_for_groups: string; | ||
organization: number; | ||
promo_media: string; | ||
}; | ||
|
||
function youtubeLinkValidator(state: FormType): SamfError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anbefaler å holde komponentfilen ren. Kan flyttes til ./utils.ts |
||
const link = state.promo_media; | ||
const regex = /(youtu.*be.*)\/(watch\?v=|embed\/|v|shorts|)(.*?((?=[&#?])|$))/; | ||
if (link && !link.match(regex)) { | ||
return 'Not valid youtbue link'; | ||
} | ||
return true; | ||
} | ||
|
||
export function RecruitmentFormAdminPage() { | ||
const { t } = useTranslation(); | ||
const navigate = useNavigate(); | ||
|
@@ -190,6 +200,14 @@ export function RecruitmentFormAdminPage() { | |
required={true} | ||
/> | ||
</div> | ||
<div className={styles.row}> | ||
<SamfFormField | ||
field="promo_media" | ||
type="text" | ||
label={t(KEY.promo_media)} | ||
validator={youtubeLinkValidator} | ||
/> | ||
</div> | ||
</SamfForm> | ||
</div> | ||
</AdminPageLayout> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,6 +293,7 @@ export const KEY = { | |
recrutment_default_application_letter: 'recrutment_default_application_letter', | ||
reprioritization_deadline_for_groups: 'reprioritization_deadline_for_groups', | ||
max_applications: 'max_applications', | ||
promo_media: 'promo_video', | ||
Comment on lines
295
to
+296
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. feil navngivning, se toppen av filen |
||
recruitment_norwegian_applicants_only: 'recruitment_norwegian_applicants_only', | ||
reprioritization_deadline_for_applicant: 'reprioritization_deadline_for_applicant', | ||
recruitment_show_unprocessed_applicants: 'recruitment_show_unprocessed_applicants', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,6 +279,7 @@ export const nb: Record<KeyValues, string> = { | |
[KEY.recrutment_default_application_letter]: 'Standard søknadstekst', | ||
[KEY.reprioritization_deadline_for_groups]: 'Flaggefrist', | ||
[KEY.max_applications]: 'Maks søknader per bruker', | ||
[KEY.promo_media]: 'Promo video', | ||
[KEY.recruitment_norwegian_applicants_only]: 'Kun norsktalende søkere', | ||
[KEY.reprioritization_deadline_for_applicant]: 'Omprioriteringsfrist', | ||
[KEY.recruitment_show_unprocessed_applicants]: 'Vis ubehandlede søkere', | ||
|
@@ -692,6 +693,7 @@ export const en: Record<KeyValues, string> = { | |
[KEY.recrutment_default_application_letter]: 'Default application letter', | ||
[KEY.reprioritization_deadline_for_groups]: 'Group reprioritization deadline', | ||
[KEY.max_applications]: 'Max applications per user', | ||
[KEY.promo_media]: "Promo Video", | ||
Comment on lines
695
to
+696
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. liten V? |
||
[KEY.reprioritization_deadline_for_applicant]: 'Reprioritization deadline', | ||
[KEY.recruitment_show_unprocessed_applicants]: 'Show unprocessed applicants', | ||
[KEY.recruitment_show_all_applicants]: 'Show all applicants', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tror ikke dette er nødvendig, ettersom det er allerede gjort gjennom at det er et innkludert felt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det var nødvendig for å tillate input lenger enn 11 characters i api-interface