-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from kitab-bazar/feature/import-export-books
Feature/import export books
- Loading branch information
Showing
24 changed files
with
1,259 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
## Run development server: | ||
|
||
```bash | ||
docker-compose up --build | ||
docker compose up --build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import csv | ||
from sys import stdout | ||
from argparse import FileType | ||
from django.conf import settings | ||
from django.core.management import BaseCommand | ||
from django.contrib.postgres.aggregates import StringAgg | ||
from django.db import models | ||
|
||
from apps.book.models import Book | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Export client translation data to csv' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('output_file', nargs='?', type=FileType('w'), default=stdout) | ||
|
||
def handle(self, *_, **options): | ||
output_file = options['output_file'] | ||
|
||
# TODO: Sync this with export | ||
headers = [ | ||
'title_en', | ||
'title_ne', | ||
'edition', | ||
'grade', | ||
'author_name_en', | ||
'author_name_ne', | ||
'price', | ||
'description_en', | ||
'description_ne', | ||
'categories_en', | ||
'categories_ne', | ||
'isbn', | ||
'number_of_pages', | ||
'language', | ||
'publisher_en', | ||
'publisher_ne', | ||
'image', | ||
'published_date', | ||
# 'illustrator_name_en', | ||
# 'illustrator_name_ne', | ||
# 'editor_en', | ||
# 'editor_ne', | ||
] | ||
|
||
# Collect all data to csv | ||
writer = csv.DictWriter(output_file, fieldnames=headers) | ||
writer.writeheader() | ||
for row in Book.objects.annotate( | ||
author_name_en=StringAgg('authors__name_en', ',', distinct=True), | ||
author_name_ne=StringAgg('authors__name_ne', ',', distinct=True), | ||
categories_en=StringAgg('categories__name_en', ',', distinct=True), | ||
categories_ne=StringAgg('categories__name_ne', ',', distinct=True), | ||
publisher_en=models.F('publisher__name_en'), | ||
publisher_ne=models.F('publisher__name_ne'), | ||
).values(*headers).distinct(): | ||
row['image'] = f"https://{settings.DJANGO_API_HOST}{settings.STATIC_URL}{row['image']}" | ||
writer.writerow(row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.16 on 2023-12-03 15:05 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('book', '0006_auto_20230119_1225'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='book', | ||
name='language', | ||
field=models.CharField(choices=[('english', 'English'), ('nepali', 'Nepali'), ('Maithali', 'Maithali'), ('Tharu', 'Tharu'), ('bilingual', 'Bilingual')], max_length=40, verbose_name='Language'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 3.2.16 on 2023-12-03 15:05 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('order', '0010_auto_20230119_1225'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='orderwindow', | ||
name='enable_incentive', | ||
field=models.BooleanField(default=True), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='orderwindow', | ||
name='incentive_max', | ||
field=models.PositiveSmallIntegerField(default=120, help_text='Max incentive count value. eg: 120'), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='orderwindow', | ||
name='incentive_multiplier', | ||
field=models.PositiveSmallIntegerField(default=4, help_text='Generate incentive count by multiplying with. eg: 4'), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='orderwindow', | ||
name='incentive_quantity_threshold', | ||
field=models.PositiveSmallIntegerField(default=10, help_text='Least quantity count required for incentive. eg: 10'), | ||
preserve_default=False, | ||
), | ||
migrations.AlterField( | ||
model_name='bookorder', | ||
name='edition', | ||
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Edition'), | ||
), | ||
migrations.AlterField( | ||
model_name='bookorder', | ||
name='language', | ||
field=models.CharField(blank=True, choices=[('english', 'English'), ('nepali', 'Nepali'), ('Maithali', 'Maithali'), ('Tharu', 'Tharu'), ('bilingual', 'Bilingual')], max_length=40, null=True, verbose_name='Language'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.