Skip to content

Commit

Permalink
Added default translation update on project update
Browse files Browse the repository at this point in the history
  • Loading branch information
PukieDiederik committed Dec 27, 2023
1 parent bcb61fa commit 1df3dd9
Showing 1 changed file with 39 additions and 27 deletions.
66 changes: 39 additions & 27 deletions backend/portfolio42_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@
import logging


# Translations

class TranslationLanguage(models.Model):
# Validator: `default` or full capitals, 2 sets of letters seperated by a `-` e.g EN-US or EN-AUS
name_short = models.CharField(unique=True, max_length=8, validators=[RegexValidator("([A-Z]+-[A-Z]+)|(default)")])
name_full = models.CharField(unique=True, max_length=64) # For example: English (United States)

def __str__(self):
return f"(Translation Language: {self.name_short})"

class ProjectTranslation(models.Model):
id_project = models.ForeignKey('Project', on_delete=models.CASCADE)
id_language = models.ForeignKey('TranslationLanguage', on_delete=models.CASCADE)

# The description of the project
description = models.TextField(max_length=2000)
# Description for the bonus part of the project
description_bonus = models.TextField(max_length=2000)

# If the bonus description appends (true) or replaces (false)
bonus_append = models.BooleanField(default=True)

updated_at = models.DateTimeField(auto_created=True, auto_now=True)

def __str__(self):
return f"(Project Translation: {self.id_project.name}:{self.id_language.name_short})"

# Intra models

class IntraBaseModel(models.Model):
intra_id = models.IntegerField(unique=True, db_index=True)
updated_at = models.DateTimeField(auto_created=True, auto_now=True)
Expand Down Expand Up @@ -114,6 +143,16 @@ def update(project):
p.solo = False # todo: REMOVE THIS
p.save()

# Update default translation
# Would love to remove the fetching of the default translation every time a project updates but do not see how
def_translation, _ = TranslationLanguage.objects.get_or_create(name_short='default')
p_trans, _ = ProjectTranslation.objects.get_or_create(id_language=def_translation, id_project=p)
try:
p_trans.description = project['description']
except:
p_trans.description = project['slug']
p_trans.save()

log_update(p, created)

return p
Expand Down Expand Up @@ -282,30 +321,3 @@ def update(cursusUser, cuSkill):

return cus


# Translations

class TranslationLanguage(models.Model):
# Validator: `default` or full capitals, 2 sets of letters seperated by a `-` e.g EN-US or EN-AUS
name_short = models.CharField(unique=True, max_length=8, validators=[RegexValidator("([A-Z]+-[A-Z]+)|(default)")])
name_full = models.CharField(unique=True, max_length=64) # For example: English (United States)

def __str__(self):
return f"(Translation Language: {self.name_short})"

class ProjectTranslation(models.Model):
id_project = models.ForeignKey('Project', on_delete=models.CASCADE)
id_language = models.ForeignKey('TranslationLanguage', on_delete=models.CASCADE)

# The description of the project
description = models.TextField(max_length=2000)
# Description for the bonus part of the project
description_bonus = models.TextField(max_length=2000)

# If the bonus description appends (true) or replaces (false)
bonus_append = models.BooleanField(default=True)

updated_at = models.DateTimeField(auto_created=True, auto_now=True)

def __str__(self):
return f"(Project Translation: {self.id_project.name}:{self.id_language.name_short})"

0 comments on commit 1df3dd9

Please sign in to comment.