Skip to content

Commit

Permalink
Merge pull request #265 from jwjacobson/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jwjacobson authored Apr 16, 2024
2 parents 9512afc + 4fcc043 commit bcdc273
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 25 deletions.
120 changes: 120 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "jazztunes_test"
version = "0.0.1"
dependencies = [
"asgiref==3.7.2",
"asttokens==2.4.1",
"attrs==23.2.0",
"build==1.1.1",
"certifi==2024.2.2",
"cffi==1.16.0",
"cfgv==3.4.0",
"charset-normalizer==3.3.2",
"cli-helpers==2.3.1",
"click==8.1.7",
"configobj==5.0.8",
"coverage[toml]==7.4.4",
"cryptography==42.0.5",
"decorator==5.1.1",
"defusedxml==0.7.1",
"distlib==0.3.8",
"dj-database-url==2.1.0",
"django==5.0.3",
"django-allauth==0.61.1",
"django-bootstrap5==23.4",
"django-debug-toolbar==4.3.0",
"executing==2.0.1",
"filelock==3.13.1",
"gunicorn==21.2.0",
"identify==2.5.35",
"idna==3.6",
"iniconfig==2.0.0",
"ipdb==0.13.13",
"ipython==8.22.2",
"jedi==0.19.1",
"markdown-it-py==3.0.0",
"matplotlib-inline==0.1.6",
"mdurl==0.1.2",
"nodeenv==1.8.0",
"oauthlib==3.2.2",
"packaging==24.0",
"parso==0.8.3",
"pexpect==4.9.0",
"pgspecial==2.1.1",
"pip-tools==7.4.1",
"platformdirs==4.2.0",
"pluggy==1.4.0",
"pre-commit==3.6.2",
"prompt-toolkit==3.0.43",
"psycopg==3.1.18",
"psycopg2==2.9.9",
"ptyprocess==0.7.0",
"pure-eval==0.2.2",
"pycparser==2.21",
"pygments==2.17.2",
"pyjwt[crypto]==2.8.0",
"pyproject-hooks==1.0.0",
"pytest==8.1.1",
"pytest-cov==4.1.0",
"pytest-django==4.8.0",
"pytest-env==1.1.3",
"python-dateutil==2.9.0.post0",
"python-decouple==3.8",
"python-dotenv==1.0.1",
"python-http-client==3.3.7",
"python3-openid==3.2.0",
"pytzdata==2020.1",
"pyyaml==6.0.1",
"requests==2.31.0",
"requests-oauthlib==1.4.0",
"rich==13.7.1",
"ruff==0.3.3",
"sendgrid==6.11.0",
"sentry-sdk==1.42.0",
"setproctitle==1.3.3",
"shellingham==1.5.4",
"six==1.16.0",
"sqlparse==0.4.4",
"stack-data==0.6.3",
"starkbank-ecdsa==2.2.0",
"tabulate[widechars]==0.9.0",
"traitlets==5.14.2",
"typer==0.9.0",
"typing-extensions==4.10.0",
"url-normalize==1.4.3",
"urllib3==1.26.18",
"virtualenv==20.25.1",
"wcwidth==0.1.9",
"wheel==0.43.0",
"whitenoise==6.6.0"
]
requires-python = ">=3.11"
authors = [
{ name="Jeff Jacobson", email="[email protected]" },
]
description = "A jazz repertoire management app"
readme = "README.md"
license = {file = "LICENSE"}
keywords = ["jazz", "repertoire", "music", "practice", "standards"]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Natural Language :: English",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: JavaScript",
"Programming Language :: Python :: 3.11",
"Topic :: Other/Nonlisted Topic"
]

[project.urls]
Homepage = "https://github.com/jwjacobson/jazztunes"
Issues = "https://github.com/jwjacobson/jazztunes/issues"
6 changes: 0 additions & 6 deletions test.sql

This file was deleted.

7 changes: 6 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from tune.models import Tune


def test_tune_field_access():
@pytest.fixture()
def tune_object():
tune = Tune(
title="test title",
composer="test composer",
Expand All @@ -14,7 +15,11 @@ def test_tune_field_access():
meter=4,
year=2023,
)
return tune


def test_tune_field_access(tune_object):
tune = tune_object
assert tune.title == "test title"
assert tune.composer == "test composer"
assert tune.key == "C"
Expand Down
20 changes: 19 additions & 1 deletion tune/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# jazztunes -- A jazz repertoire management app
# Copyright (C) 2024 Jeff Jacobson <[email protected]>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.


from django.contrib import admin
from tune.models import Tune, RepertoireTune, Tag

Expand All @@ -19,4 +37,4 @@ class RepertoireTuneAdmin(admin.ModelAdmin):
@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
list_display = ["name"]
search_fields = ('name',)
search_fields = ("name",)
17 changes: 17 additions & 0 deletions tune/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# jazztunes -- A jazz repertoire management app
# Copyright (C) 2024 Jeff Jacobson <[email protected]>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from django.apps import AppConfig


Expand Down
17 changes: 17 additions & 0 deletions tune/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# jazztunes -- A jazz repertoire management app
# Copyright (C) 2024 Jeff Jacobson <[email protected]>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from django.forms import ModelForm
from django import forms
from .models import Tune, RepertoireTune
Expand Down
17 changes: 17 additions & 0 deletions tune/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# jazztunes -- A jazz repertoire management app
# Copyright (C) 2024 Jeff Jacobson <[email protected]>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from django.db import models
from django.contrib.auth import get_user_model

Expand Down
17 changes: 17 additions & 0 deletions tune/signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# jazztunes -- A jazz repertoire management app
# Copyright (C) 2024 Jeff Jacobson <[email protected]>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.utils import timezone
Expand Down
2 changes: 1 addition & 1 deletion tune/templates/tune/_another_button.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="playTuneWrapper">
<div class="card bg-danger border-primary" style="max-width: 22rem; border-radius: 0;">
<div class="card bg-danger border-primary" style="height: 200px; max-width: 22rem; border-radius: 0;">
<div class="card-body">
{% if selected_tune %}
<h5 class = "card-title">You should play</h5>
Expand Down
8 changes: 4 additions & 4 deletions tune/templates/tune/play.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</div>


<div class="row d-flex align-items-stretch">
<div class="col-md-6">
<div class="card bg-success-subtle border-primary" style="max-width: 18rem; border-radius: 0;">
<div class="row align-items-start g-0">
<div class="col-3">
<div class="card bg-success-subtle border-primary" style="height: 200px; max-width: 18rem; border-radius: 0;">
<div class="card-body">
<h5 class="card-title">Tune Search</h5>
<div>
Expand All @@ -39,7 +39,7 @@ <h5 class="card-title">Tune Search</h5>
</div>
</div>
</div>
<div id="tunes" class="col-md-6">
<div id="tunes" class="col-3">
</div>
</div>
{% endblock %}
18 changes: 18 additions & 0 deletions tune/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# jazztunes -- A jazz repertoire management app
# Copyright (C) 2024 Jeff Jacobson <[email protected]>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.


from django.urls import path
from tune import views

Expand Down
43 changes: 31 additions & 12 deletions tune/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# jazztunes -- A jazz repertoire management app
# Copyright (C) 2024 Jeff Jacobson <[email protected]>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from random import choice

from django.contrib import messages
Expand All @@ -9,7 +26,6 @@
from django.utils import timezone
from django.conf import settings
from django.http import HttpResponse
from django.template.loader import render_to_string

from .models import Tune, RepertoireTune
from .forms import TuneForm, RepertoireTuneForm, SearchForm
Expand Down Expand Up @@ -60,7 +76,7 @@ def return_search_results(request, search_terms, tunes, search_form, timespan=No
if len(search_terms) > Tune.MAX_SEARCH_TERMS:
messages.error(
request,
f"Your query is too long ({len(search_terms)} terms, maximum of {Tune.MAX_SEARCH_TERMS}). Consider using advanced search for more granularity.",
f"Your query is too long ({len(search_terms)} terms, maximum of {Tune.MAX_SEARCH_TERMS}).",
)
return render(
request,
Expand Down Expand Up @@ -214,28 +230,31 @@ def get_random_tune(request):
)
search_form = SearchForm(request.POST or None)

# A flatter way to validate the form, rather than indenting everything under it
if not search_form.is_valid():
return HttpResponse("Invalid search", status=400)
# This should never trigger
messages.error(request, "Invalid search")
return render(request, "tune/play.html")

search_terms = search_form.cleaned_data["search_term"].split(" ")
timespan = search_form.cleaned_data.get("timespan", None)
result_dict = return_search_results(request, search_terms, tunes, search_form, timespan)

if "error" in result_dict:
return render(request, result_dict["template"], result_dict)
messages.error(request, result_dict["error"])
return render(request, result_dict["template"])

tunes = result_dict.get("tunes")

if not tunes:
return HttpResponse("No tunes found", status=404)

selected_tune = choice(tunes)
remaining_rep_tunes_ids = [tune.id for tune in tunes if tune != selected_tune]
request.session["rep_tunes"] = remaining_rep_tunes_ids
if tunes:
selected_tune = choice(tunes)
remaining_rep_tunes_ids = [tune.id for tune in tunes if tune != selected_tune]
request.session["rep_tunes"] = remaining_rep_tunes_ids
else:
selected_tune = None
request.session.save()

html = render_to_string("tune/_play_card.html", {"selected_tune": selected_tune}, request)
return HttpResponse(html)
return render(request, "tune/_play_card.html", {"selected_tune": selected_tune})


@login_required
Expand Down

0 comments on commit bcdc273

Please sign in to comment.