Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix/has photo #600

Merged
merged 4 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/utils/cert_acess.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_certificate_data(ind, user_id):
"herd": herd,
"fullname": fullname,
"issue_date": date,
"photos": False,
"photos": "Ja" if ind["has_photo"] else "Nej",
}
ind["notes"] = ".\r\n ".join(
[
Expand Down
32 changes: 31 additions & 1 deletion app/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
from playhouse.migrate import PostgresqlMigrator, SqliteMigrator, migrate

CURRENT_SCHEMA_VERSION = 9
CURRENT_SCHEMA_VERSION = 10
DB_PROXY = Proxy()
DATABASE = None
DATABASE_MIGRATOR = None
Expand Down Expand Up @@ -566,6 +566,7 @@ class Individual(BaseModel):
belly_color = TextField(null=True)
hair_notes = TextField(null=True)
is_active = BooleanField(null=True, default=True)
has_photo = BooleanField(null=True, default=False)
butchered = BooleanField(null=True, default=False)
castration_date = DateField(null=True, default=None)

Expand Down Expand Up @@ -1595,6 +1596,35 @@ def migrate_8_to_9():
).execute()


def migrate_9_to_10():
"""
Migrate between schema version 9 and 10.
"""
with DATABASE.atomic():
if "individual" not in DATABASE.get_tables():
# Can't run migration
SchemaHistory.insert( # pylint: disable=E1120
version=10,
comment="not yet bootstrapped, skipping",
applied=datetime.now(),
).execute()
return

cols = [x.name for x in DATABASE.get_columns("individual")]

if "has_photo" not in cols:
migrate(
DATABASE_MIGRATOR.add_column(
"individual",
"has_photo",
BooleanField(null=True, default=False),
)
)
SchemaHistory.insert( # pylint: disable=E1120
version=10, comment="Add has_photo to individual", applied=datetime.now()
).execute()


def check_migrations():
"""
Check if the database needs any migrations run and run those if that's the case.
Expand Down
1 change: 1 addition & 0 deletions frontend/src/data_context_global.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface Individual extends LimitedIndividual {
herd_active: boolean;
is_active: boolean;
is_registered: boolean;
has_photo: boolean;
alive: boolean;
belly_color: string | null;
eye_color: string | null;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/individual_certificate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export function IndividualCertificate({
name: individual?.name,
litter_size: individual?.litter_size,
litter_size6w: individual?.litter_size6w,
has_photo: individual?.has_photo,
notes: individual?.notes,
sex: individual?.sex,
genebank: individual?.genebank,
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/individual_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function IndividualForm({
intygError,
herdOptions,
}: {
genebank: Genebank;
genebank?: Genebank;
individual: Individual;
onUpdateIndividual: any;
formAction: FormAction;
Expand Down Expand Up @@ -105,10 +105,9 @@ export function IndividualForm({
];

const photoOptions = [
{ value: "no", label: "Nej" },
{ value: "yes", label: "Ja" },
]; //should be boolean but doesn't work together with the OptionType
// also decide how this should be stored in the backend
{ value: false, label: "Nej" },
{ value: true, label: "Ja" },
];

return (
<>
Expand Down Expand Up @@ -493,6 +492,11 @@ export function IndividualForm({
options={photoOptions ?? []}
className="controlWidth"
getOptionLabel={(option: OptionType) => option.label}
value={
photoOptions.find(
(option) => option.value == individual.has_photo
) ?? photoOptions[0] //"nej as defult pos 0 "
}
renderInput={(params) => (
<TextField
{...params}
Expand All @@ -502,6 +506,9 @@ export function IndividualForm({
margin="normal"
/>
)}
onChange={(event: any, newValue: OptionType | null) => {
onUpdateIndividual("has_photo", newValue?.value ?? "");
}}
/>
</div>
<div className="flexRow">
Expand Down