Skip to content

Commit

Permalink
clean up card model, don't show backs when theyd on't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaanahmed committed Sep 12, 2023
1 parent 879f1b0 commit b907f4c
Show file tree
Hide file tree
Showing 10 changed files with 2,366 additions and 5,576 deletions.
60 changes: 32 additions & 28 deletions backend/app/management/commands/import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,18 @@ def populate_playing_cards(self):
card_data = deck_data_frame.to_dict(orient="records")

# create and save the deck
deck_instance = Deck(name=deck_name,
period=period,
start_date=card_data[0]["Start Date"],
end_date=card_data[0]["End Date"],
maker=card_data[0]["Maker"],
title=card_data[0]["Title"],
town=card_data[0]["Town"])
deck = Deck(name=deck_name,
period=period,
start_date=card_data[0]["Start Date"],
end_date=card_data[0]["End Date"],
maker=card_data[0]["Maker"],
title=card_data[0]["Title"],
town=card_data[0]["Town"])

deck_instance.save()
self.stdout.write(f'Created deck {deck_name} (id {deck_instance.id}...')
deck.save()
self.stdout.write(f'Created deck {deck_name} (id {deck.id}...')

for entry in card_data:
if entry["Recto or Verso"] == 'V':
continue

rank = entry['Card']
suit = entry["Suit"]

Expand All @@ -60,25 +57,32 @@ def populate_playing_cards(self):
suit = ""

# create and save each card
recto_img=f'{period}/{deck_name}/{rank}{suit}.1.jpeg'
verso_img=f'{period}/{deck_name}/{rank}{suit}.2.jpeg'
recto_img = f'{period}/{deck_name}/{rank}{suit}.1.jpeg'

sort_order = ABBREVIATIONS_TO_CARD_SORT[suit]*4 + ABBREVIATIONS_TO_CARD_SORT[rank]

card = Card(
deck=deck_instance,
db_id=entry["DB ID"],
rank=rank,
suit=suit,
type=entry["Type"],
back_notes=entry["Back notes?"],
url=entry["BnF URL"],
recto_img=recto_img,
verso_img=verso_img,
sort_order=sort_order
)
card.save()
# TODO(ra): Add a verbose flag (maybe? probably don't need it...)
if entry["Recto or Verso"] == 'R':
card = Card(
deck=deck,
rank=rank,
suit=suit,
back_notes=entry["Back notes?"],
url=entry["BnF URL"],
recto_img=recto_img,
sort_order=sort_order
)
card.save()

elif entry["Recto or Verso"] == 'V':
card = Card.objects.get(
deck=deck,
rank=rank,
suit=suit
)
card.verso_img = f'{period}/{deck_name}/{rank}{suit}.2.jpeg'
card.save()


# self.stdout.write('Created card {} with id of {}'.format(card.db_id, card.id))
# self.stdout.write('-------')

Expand Down
14 changes: 9 additions & 5 deletions backend/app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.1.3 on 2023-06-07 22:23
# Generated by Django 4.1.3 on 2023-09-12 19:32

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -32,30 +32,34 @@ class Migration(migrations.Migration):
('lang', models.CharField(max_length=2)),
('number', models.IntegerField()),
('orientation', models.BooleanField(blank=True, null=True)),
('card', models.CharField(max_length=1)),
('rank', models.CharField(max_length=1)),
('title', models.CharField(blank=True, max_length=30)),
('subtitle', models.CharField(blank=True, max_length=30)),
('pair', models.CharField(blank=True, max_length=20)),
('etteilla', models.CharField(blank=True, max_length=25)),
('quad', models.CharField(blank=True, max_length=20)),
('triple', models.CharField(blank=True, max_length=20)),
('double', models.CharField(blank=True, max_length=20)),
('image', models.FilePathField(null=True, path='assets/img/divination/')),
('image', models.FilePathField(null=True, path='C:\\dev\\dhmit\\french-playing-cards\\assets\\img\\cartomancy')),
],
),
migrations.CreateModel(
name='Card',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('db_id', models.CharField(max_length=30, null=True)),
('rank', models.CharField(max_length=1, null=True)),
('suit', models.CharField(max_length=1, null=True)),
('type', models.CharField(max_length=30, null=True)),
('back_notes', models.CharField(max_length=30, null=True)),
('url', models.URLField(null=True)),
('recto_img', models.FilePathField()),
('verso_img', models.FilePathField()),
('verso_img', models.FilePathField(null=True)),
('sort_order', models.IntegerField()),
('deck', models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='app.deck')),
],
options={
'ordering': ['sort_order'],
'unique_together': {('deck', 'rank', 'suit')},
},
),
]
23 changes: 0 additions & 23 deletions backend/app/migrations/0002_alter_card_options_card_sort_order.py

This file was deleted.

This file was deleted.

6 changes: 2 additions & 4 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ class Card(models.Model):
"""
The Card model
"""
# auto id generated
deck = models.ForeignKey('Deck', null=True, on_delete=models.DO_NOTHING)
db_id = models.CharField(max_length=30, null=True)
rank = models.CharField(max_length=1, null=True)
suit = models.CharField(max_length=1, null=True)
type = models.CharField(max_length=30, null=True)
back_notes = models.CharField(max_length=30, null=True)
url = models.URLField(max_length=200, null=True)
recto_img = models.FilePathField()
verso_img = models.FilePathField()
verso_img = models.FilePathField(null=True)

# So that we don't have to do any sorting in Python, we define a sort order
# for cards within a deck as follows:
Expand All @@ -51,6 +48,7 @@ def __str__(self):

class Meta:
ordering = ['sort_order']
unique_together = ['deck', 'rank', 'suit']


class Deck(models.Model):
Expand Down
Loading

0 comments on commit b907f4c

Please sign in to comment.