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

Added Solo-mode search and restricted Format Search #188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions cardDatabase/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,22 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
class RaceAdmin(admin.ModelAdmin):
search_fields = ['name']


class ArtistAdmin(admin.ModelAdmin):
search_fields = ['name']

class SetAdmin(admin.ModelAdmin):
search_fields = ['name', 'code']

class FormatAdmin(admin.ModelAdmin):
autocomplete_fields = ['sets']
search_fields = ['sets__name', 'sets__code', 'sets']


admin.site.register(OneTimeEffect)
admin.site.register(Card, CardAdmin)
admin.site.register(Tag)
admin.site.register(Set, SetAdmin)
admin.site.register(Cluster)
admin.site.register(AbilityText, AbilityTextAdmin)
admin.site.register(AbilityStyle)
admin.site.register(Profile)
Expand All @@ -88,7 +96,7 @@ class ArtistAdmin(admin.ModelAdmin):
admin.site.register(UserDeckListZone)
admin.site.register(SpoilerSeason)
admin.site.register(BannedCard, BannedCardAdmin)
admin.site.register(Format)
admin.site.register(Format, FormatAdmin)
admin.site.register(CombinationBannedCards, CombinationBannedCardsAdmin)
admin.site.register(Ruling, RulingAdmin)
admin.site.register(Restriction)
Expand Down
12 changes: 8 additions & 4 deletions cardDatabase/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
from cardDatabase.models.Banlist import Format
from cardDatabase.management.commands.importjson import remove_punctuation

def get_formats():
format_values = Format.objects.values('name')
format_map = map(lambda x : (x['name'], x['name']), format_values)

return list(format_map)

class SearchForm(forms.Form):
generic_text = forms.CharField(label='', strip=True,
widget=forms.TextInput(attrs={'placeholder': 'Search...'}), required=False)
format = forms.ChoiceField(required=False, choices=get_formats(), widget=forms.HiddenInput())


def get_races():
Expand All @@ -23,11 +29,7 @@ def get_races():

return list(race_map)

def get_formats():
format_values = Format.objects.values('name')
format_map = map(lambda x : (x['name'], x['name']), format_values)

return list(format_map)


def get_keywords_choices():
Expand All @@ -51,6 +53,7 @@ class AdvancedSearchForm(forms.Form):
sort_by = forms.ChoiceField(label='Sort results by:', choices=CONS.DATABASE_SORT_BY_CHOICES, required=False)
pick_period = forms.ChoiceField(label='Popularity time period:', choices=CONS.PICK_PERIOD_CHOICES, required=False)
reverse_sort = forms.BooleanField(label='Reverse sorting:', required=False)
solo_mode = forms.BooleanField(label='Solo Mode:', required=False)
colours = forms.MultipleChoiceField(label='Color(s):', choices=CONS.COLOUR_CHOICES, required=False)
colour_match = forms.ChoiceField(label='Color(s) match:', choices=CONS.DATABASE_COLOUR_MATCH_CHOICES, required=False)
colour_combination = forms.ChoiceField(label='Color combinations:', choices=CONS.DATABASE_COLOUR_COMBINATION_CHOICES, required=False)
Expand All @@ -64,6 +67,7 @@ class AdvancedSearchForm(forms.Form):
atk_comparator = forms.ChoiceField(required=False, choices=CONS.ATK_DEF_COMPARATOR_CHOICES)
def_value = forms.IntegerField(label='DEF', required=False, min_value=0, widget=forms.NumberInput(attrs={'placeholder': 'Defense'}))
def_comparator = forms.ChoiceField(required=False, choices=CONS.ATK_DEF_COMPARATOR_CHOICES)
format = forms.ChoiceField(required=False, choices=get_formats())
keywords = forms.MultipleChoiceField(label='Keyword(s):', choices=get_keywords_choices(), required=False)

class DecklistSearchForm(forms.Form):
Expand Down
95 changes: 95 additions & 0 deletions cardDatabase/migrations/0059_auto_20250225_1734.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Generated by Django 3.2.6 on 2025-02-25 17:34

from django.db import migrations, models
from django.db.models import Q
from fowsim import constants as CONS


class Migration(migrations.Migration):

dependencies = [
('cardDatabase', '0058_merge_20250208_1750'),
]

def initClusterAndSets(apps, schema_editor):
clusters = CONS.SET_DATA['clusters']
extraSets = CONS.SEARCH_SETS_INCLUDE
clusterObjects = apps.get_model('cardDatabase', 'Cluster')
setObjects = apps.get_model('cardDatabase', 'Set')
for cluster in clusters:
clusterName = cluster['name']
clusterEntity = None
clusterEntity, created = clusterObjects.objects.get_or_create(name=clusterName)
if created:
clusterEntity.save()
for set in cluster['sets']:
setName = set['name']
setCode = set['code']
if not setObjects.objects.filter(name=setName).exists():
setEntity, created = setObjects.objects.get_or_create(name=setName, code=setCode, parent_code=None, cluster=clusterEntity)
setEntity.save()
if setCode not in extraSets:
continue
subSets = extraSets[setCode]
for subSet in subSets:
if not setObjects.objects.filter(name=subSet).exists():
setEntity, created = setObjects.objects.get_or_create(name=subSet, code=subSet, parent_code=setCode, cluster=clusterEntity)
setEntity.save()

def initParadox(apps, schema_editor):
paradoxInitialSets=[
'HSD',
'NWE',
'TUS',
'H2 Buy a Box',
'H2 Prerelease Party',
'TWS',
'H3 Buy a Box',
'H3 Prerelease Party'
'CMB',
'H4 Prerelease Party',
'H4 Buy a Box',
'CST',
'H5 Buy a Box',
'H5 Prerelease Party',
'JRP',
'H6 Prerelease Party',
'TSD1',
'TSD2',
'TTT',
'T1 Buy a Box',
'TSR',
'T2 Buy a Box',
'TEU',
'T3 Buy a Box',
'MP02',
]
formats = apps.get_model('cardDatabase', 'Format')
paradox = formats.objects.get(name='Paradox')
sets = apps.get_model('cardDatabase', 'Set')
setQuery = Q()
for s in paradoxInitialSets:
setQuery |= Q(code=s)

paradox.sets.set(sets.objects.filter(setQuery).all())
paradox.save()

operations = [
migrations.AddField(
model_name='card',
name='ability_styles',
field=models.ManyToManyField(blank=True, related_name='cards', through='cardDatabase.CardAbility', to='cardDatabase.AbilityStyle'),
),
migrations.AddField(
model_name='format',
name='sets',
field=models.ManyToManyField(related_name='sets', to='cardDatabase.Set'),
),
migrations.AddField(
model_name='set',
name='parent_code',
field=models.CharField(max_length=200, null=True),
),
migrations.RunPython(initClusterAndSets),
migrations.RunPython(initParadox),
]
1 change: 1 addition & 0 deletions cardDatabase/models/Banlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class Format(models.Model):
name = models.TextField(blank=False, null=False, default='')
sets = models.ManyToManyField('Set', related_name='sets')

def __str__(self):
return self.name
Expand Down
8 changes: 8 additions & 0 deletions cardDatabase/models/CardType.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ class Cluster(models.Model):
class Meta:
app_label = 'cardDatabase'

def __str__(self):
return self.name

name = models.CharField(max_length=200, null=False, blank=False)


class Set(models.Model):
class Meta:
app_label = 'cardDatabase'

def __str__(self):
return self.name

name = models.CharField(max_length=200, null=False, blank=False)
code = models.CharField(max_length=200, null=False, blank=False)
parent_code = models.CharField(max_length=200, null=True)
cluster = models.ForeignKey('Cluster', on_delete=models.CASCADE)


Expand Down Expand Up @@ -108,6 +115,7 @@ class Meta:
DEF = models.IntegerField(null=True, blank=True)
types = models.ManyToManyField('Type', related_name='types')
ability_texts = models.ManyToManyField('AbilityText', related_name='cards', blank=True, through=CardAbility)
ability_styles = models.ManyToManyField('AbilityStyle', related_name='cards', blank=True, through=CardAbility)
colours = models.ManyToManyField('CardColour', related_name='cards', blank=False)
tag = models.ManyToManyField('Tag', related_name='cards', blank=True)
artists = models.ManyToManyField('CardArtist', related_name='cards', blank=True)
Expand Down
13 changes: 13 additions & 0 deletions cardDatabase/static/css/database_base.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ input[type="checkbox"].fow-checkbox,
input[type="checkbox"][name="text_exactness"],
input[type="checkbox"][name="sort_by"],
input[type="checkbox"][name="pick_period"],
input[type="checkbox"][name="solo_mode"],
input[type="checkbox"][name="reverse_sort"],
input[type="checkbox"][name="colour_match"],
input[type="checkbox"][name="colour_combination"]{
Expand Down Expand Up @@ -187,6 +188,14 @@ input:checked + .selected-backgrounds{
display: inline-block;
}

.solo-mode-input, .solo-mode-label{
display: inline-block;
}

.format-select{
margin-top: 10px;
}

.referred-card{
width: max-content;
}
Expand All @@ -199,6 +208,10 @@ input:checked + .selected-backgrounds{
pointer-events: auto;
}

#id_solo_mode{
pointer-events: auto;
}

.help-tooltip{
display: inline-block;
padding-left: 10px;
Expand Down
5 changes: 5 additions & 0 deletions cardDatabase/static/js/database_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ function initDatabaseBase(){
event.preventDefault();
select_format_sets(FOWDB_SET_JSON.clusters, false);
});

$('#format-select').on('change', function (event) {
select_format_sets(FOWDB_SET_JSON.clusters, false);
});

$('.help-tooltip').on('click', function(event){
if (event.target === this || event.target.matches('.tooltip-icon')) {
$(this).addClass('show');
Expand Down
17 changes: 14 additions & 3 deletions cardDatabase/static/js/edit_decklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,22 @@ $(function() {
});
}

function handleSubmit(event){
function handleBaseSubmit(event){
event.preventDefault();
let params = form_to_url_params(this);
let search_url = window.location.origin + '/search/' + '?' + params.toString() + '&format=' + $('#deck-format-input').val();
requestAndSetDatabaseContent(search_url)
}

function handleAdvancedSubmit(event){
event.preventDefault();
let params = form_to_url_params(this);
let search_url = window.location.origin + '/search/' + '?' + params.toString();
requestAndSetDatabaseContent(search_url)
}
$('#advanced-form, #basic-form').on('submit', handleSubmit);

$('#basic-form').on('submit', handleBaseSubmit);
$('#advanced-form').on('submit', handleAdvancedSubmit);

function requestAndSetDatabaseContent(search_url){
$.ajax({
Expand All @@ -256,7 +265,9 @@ $(function() {
} else {
setupCardOverlay();
}
$('#advanced-form, #basic-form').on('submit', handleSubmit)

$('#basic-form').on('submit', handleBaseSubmit);
$('#advanced-form').on('submit', handleAdvancedSubmit);
}
})
}
Expand Down
36 changes: 35 additions & 1 deletion cardDatabase/templates/cardDatabase/html/database_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
</label>
{% endfor %}
</div>
<div class="fieldWrapper solo-mode-container">
<div class="solo-mode-input">
{{ advanced_form.solo_mode }}
</div>
<label class="solo-mode-label" for="id_solo_mode">
Solo Mode
</label>
</div>
<div class="fieldWrapper select-sort-by">
<div class="sort-by-title field-title">
Sort by:
Expand Down Expand Up @@ -167,7 +175,7 @@
</select>
</div>
<div class="fieldWrapper sets-select">
<select class="mdb-select md-form" multiple form="advanced-form" name="sets" searchable="Search here...">
<select class="mdb-select md-form" multiple form="advanced-form" id="set-select" name="sets" searchable="Search here...">
{% for cluster in sets_json.clusters reversed %}
<optgroup label="{{ cluster.name }} Cluster">
{% for set in cluster.sets reversed %}
Expand All @@ -189,6 +197,32 @@
Clear All Sets
</button>
</div>
<div class="format-select fieldWrapper">
<div class="format-inputs">
<div class="format-label field-title">
Format
</div>
<div class="format">
<select id="format-select" name="format">
<option value="" {% if not advanced_form_data.format %}selected{% endif %}>No Format</option>
{% for format in format_list %}
<option value="{{ format.name }}"
{# This is so that that if the format is given intitally via on edit_decklist we set it to the format of the deck #}
{% if decklist %}
{% if not advanced_form_data.format and decklist.deck_format.name == format.name %}
selected
{% endif %}
{% elif advanced_form_data.format == format.name %}
selected
{% endif %}
>
{{ format.name }}
</option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="fieldWrapper card-type-select">
<select class="mdb-select md-form" multiple form="advanced-form" name="card_type" searchable="Search here...">
{% for deck_group in card_types_list %}
Expand Down
Loading