Skip to content
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 seed script for TextItem #560

Merged
merged 5 commits into from
Sep 21, 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: 2 additions & 0 deletions backend/root/management/commands/seed_scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
billig,
menu,
documents,
textitems,
example,
samf3,
recruitment,
Expand All @@ -32,6 +33,7 @@
('menu', menu.seed),
('documents', documents.seed),
('information_page', information_pages.seed),
('textitems', textitems.seed),
('blogposts', blogposts.seed),
('organization', oganizations.seed),
('recruitment', recruitment.seed),
Expand Down
44 changes: 44 additions & 0 deletions backend/root/management/commands/seed_scripts/textitems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from samfundet.models.general import TextItem


def seed():
text_items = [
{
'key': 'welcome_message',
'text_nb': 'Velkommen til Studentersamfundet i Trondhjem!',
'text_en': 'Welcome to the Student Society in Trondheim!',
},
{
'key': 'upcoming_events',
'text_nb': 'Sjekk ut våre kommende arrangementer og konsertene vi har planlagt!',
'text_en': 'Check out our upcoming events and concerts we have planned!',
},
{
'key': 'join_us',
'text_nb': 'Bli medlem av Studentersamfundet og nyt godt av medlemsfordelene!',
'text_en': 'Join the Student Society and enjoy the benefits of membership!',
},
{
'key': 'volunteer',
'text_nb': 'Vil du bli frivillig? Bli med i vårt fantastiske team og bidra til studentkulturen i Trondheim!',
'text_en': 'Want to volunteer? Join our amazing team and contribute to the student culture in Trondheim!',
},
{
'key': 'about_us',
'text_nb': 'Studentersamfundet i Trondhjem er et kulturelt senter for studenter og en viktig del av studentlivet i Trondheim.',
'text_en': 'The Student Society in Trondheim is a cultural center for students and an essential part of student life in Trondheim.',
},
{
'key': 'contact_us',
'text_nb': 'Har du spørsmål eller ønsker å komme i kontakt med oss? Ikke nøl med å ta kontakt!',
'text_en': 'Do you have any questions or want to get in touch with us? Don"t hesitate to contact us!',
},
]

TextItem.objects.all().delete()
yield 0, 'Deleted old textitems'

for i, item in enumerate(text_items):
text_item, created = TextItem.objects.get_or_create(key=item['key'], text_nb=item['text_nb'], text_en=item['text_en'])
if created:
yield (100 * (i + 1) // len(text_items), f'Created {len(TextItem.objects.all())} textitems')
Loading