pbaranay / django-magic-cards Goto Github PK
View Code? Open in Web Editor NEWA pluggable Django app for the Oracle text of all Magic: the Gathering cards
License: MIT License
A pluggable Django app for the Oracle text of all Magic: the Gathering cards
License: MIT License
The mtgjson "extras" includes information about foreign language printings.
Please allow accessing foreign language printing information, like card name and multiverse IDs. I believe this would be a OneToMany from Printing to ForeignPrinting with the fields language
, name
, multiverse_id
and the property image_url
.
Under Python 2, admin/magic_cards/printing/
cannot be loaded due to bad Unicode data on a handful of cards. Explore using python_2_unicode_compatible
to fix.
There is a v4 of mtgjson https://mtgjson.com/v4/
It is apparently feature-incompatible with the current downloadable json files.
Can this module be updated to use the new API?
It takes about 5 minutes to import all the cards. I should investigate how this can be improved, e.g. by using bulk_create
.
Split cards appear in your data source separately - i.e., there is an object with name="Cut"
, and one with name="Ribbons"
. There's no way to relate them together that I can see. How would you suggest handling card names like "Cut // Ribbons"? (IIRC, Judge Center displayed both halves side by side?)
The models appear in the django admin, but there is no way to search for a specific card in the admin by name (or type/artist/set/whatever). The appropriate fields should be searchable.
Per models.py
, I don't see anywhere that a Planeswalker card's starting loyalty is saved.
Similarly, color indicators are probably missing. Anything else you can think of?
As mentioned by @dcollinsn in #19.
Typing ./manage.py import_magic_cards
should present more output to the user. Some ideas:
https://docs.djangoproject.com/en/1.11/ref/models/fields/#arguments
on_delete
will become a required argument in Django 2.0. In older versions it defaults toCASCADE
.
A typeline
@property
on class Card
which correctly orders supertypes, types, and subtypes, inserting a dash between types and subtypes if there are subtypes, would be useful, and I think it would be appropriate for this package.
@property
def typeline(self):
typeline = ''
if self.supertypes.exists():
typeline += ' '.join(self.supertypes.values_list('name', flat=True))
typeline += ' '
typeline += ' '.join(self.types.values_list('name', flat=True))
if self.subtypes.exists():
typeline += ' โ ' + ' '.join(self.subtypes.values_list('name', flat=True))
return typeline
No idea if there's a correct sorting for any of the types of types, but if there is, it should probably be added to the class Meta
in models.py
?
http://mtgjson.com/sets.html lists the last update time of each set code. Feature request: Write a management command that will only download the files that haven't changed (and exit without doing anything if all files are up to date). This would require storing the "last-updated" date in the Set
model.
Readme.rst reads:
Add Django Magic Cards' tables to your the database:
./manage.py magic_cards
It should read
./manage.py migrate magic_cards
class Card(NameMixin, models.Model):
name = models.CharField(max_length=127, unique=True)
However, R&D gave us "Our Market Research Shows That Players Like Really Long Card Names So We Made this Card to Have the Absolute Longest Card Name Ever Elemental", which has 141 characters.
Traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/async/models.py", line 223, in execute
return atomic(execute)()
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 185, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/async/models.py", line 217, in execute
result = function(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 130, in call_command
return command.execute(*args, **defaults)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/magic_cards/management/commands/import_magic_cards.py", line 27, in handle
import_cards(set_codes or Everything)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 185, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/magic_cards/utils/initial_import.py", line 117, in import_cards
parse_data(sets_data, set_codes)
File "/usr/local/lib/python2.7/dist-packages/magic_cards/utils/initial_import.py", line 82, in parse_data
'toughness': toughness,
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 475, in get_or_create
return self._create_object_from_params(lookup, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 505, in _create_object_from_params
obj = self.create(**params)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 399, in create
obj.save(force_insert=True, using=self.db)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 796, in save
force_update=force_update, update_fields=update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 824, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 908, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 947, in _do_insert
using=using, raw=raw)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1045, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 1054, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 110, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
DataError: (1406, "Data too long for column 'name' at row 1")
Currently, the import function examines a Card
's subtypes, gets or creates an appropriate CardSubtype
object, and adds a many-to-many linkage for each such CardSubtype
. However, we should also take care to delete the many-to-many linkage for any subtypes that have been removed since the last update.
(The same logic applies for supertypes and types.)
Suppose the import is run multiple times, and MTGJSON has updated some cards' data in the interim. Unfortunately, these changes will not be picked up by the import script. This is especially obvious from the fact that, under current conditions, our latest field (loyalty
) will not be added to any existing Card
objects.
As a side consequence, the initial_import.py
file should likely be renamed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.