-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add api to add tags dynamically (#75)
- Loading branch information
Showing
13 changed files
with
133 additions
and
64 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
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,26 @@ | ||
import requests | ||
from loguru import logger | ||
from taggit.models import Tag | ||
|
||
|
||
def get_tags_from_gt_api() -> list: | ||
"""Gets tags from GameTools api.""" | ||
all_tags_json = requests.get( | ||
"https://api.gametools.network/bf2042/availabletags/?lang=en-us" | ||
).json()["availableTags"] | ||
return [ | ||
tag_dict["metadata"]["translations"][0]["localizedText"] | ||
for tag_dict in all_tags_json | ||
] | ||
|
||
|
||
def save_tags_from_gt_api(): | ||
"""Saves non existing tags in db""" | ||
tags_added = [] | ||
for tag in get_tags_from_gt_api(): | ||
if not Tag.objects.filter(name__exact=tag).exists(): | ||
Tag(name=tag).save() | ||
tags_added.append(tag) | ||
else: | ||
logger.debug(f"{tag} exists in db") | ||
logger.debug(f"Added Tags :- {tags_added}") |
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,16 @@ | ||
# Generated by Django 3.2.12 on 2022-09-20 10:42 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0050_auto_20220919_1727"), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name="AvailableTags", | ||
), | ||
] |
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
<div id="{{ name }}InputContainer" class="w-full flex flex-row items-center bg-card-bg h-9 text-white rounded"> | ||
<div id="{{ html_id }}_on_deck" class="results_on_deck flex flex-row items-center gap-x-1"></div> | ||
<label for="{{ html_id }}_text"></label><input class="w-full px-2 rounded bg-transparent border-0 focus:ring-0 disabled:bg-[#1f1f1f] placeholder:font-medium placeholder:text-sm" | ||
type="text" name="{{ name }}_text" id="{{ html_id }}_text" value="" autocomplete="off" | ||
placeholder="{{ name|capfirst }}" onkeydown="handleKeyDown(this, event)"/> | ||
<div id="{{ name }}InputContainer" class="w-full flex flex-row items-center bg-card-bg min-h-9 text-white rounded flex-wrap"> | ||
<div id="{{ html_id }}_on_deck" class="results_on_deck flex flex-row flex-wrap items-center gap-x-1 gap-y-1 max-w-fit"></div> | ||
<input class="min-w-[30px] px-2 rounded bg-transparent border-0 focus:ring-0 disabled:bg-[#1f1f1f] placeholder:font-medium placeholder:text-sm" | ||
type="text" name="{{ name }}_text" id="{{ html_id }}_text" value="" autocomplete="off" | ||
placeholder="{{ name|capfirst }}" onkeydown="handleKeyDown(this, event)"/> | ||
<input type="hidden" class="bg-card-bg text-white" name="{{ name }}" id="{{ html_id }}" value="{{ current_ids }}" | ||
data-ajax-select="autocompleteselectmultiple" data-plugin-options="{{ data_plugin_options }}"/> | ||
</div> | ||
{% block extra_script %} | ||
<script type="application/javascript"> bindTriggers("{{ html_id }}") </script> | ||
{% endblock %} | ||
|
||
{% block help %}{% if help_text %}<p class="help">{{ help_text }}</p>{% endif %}{% endblock %} |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from core.helper import get_tags_from_gt_api | ||
from django.core.management import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Command that is used to develop other command and test stuff""" | ||
|
||
def handle(self, *args, **options): # noqa: D102 | ||
print("pass") | ||
print(get_tags_from_gt_api()) |
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