From 4b1eba3cc2a09d1caecacd851c90fe7944fbe804 Mon Sep 17 00:00:00 2001
From: JW Jacobson <116485484+jwjacobson@users.noreply.github.com>
Date: Wed, 26 Jun 2024 13:43:41 -0400
Subject: [PATCH 5/8] Set blank=True on tags
---
README.md | 2 +-
tune/forms.py | 10 ----------
.../0006_alter_repertoiretune_tags.py | 19 +++++++++++++++++++
tune/models.py | 2 +-
4 files changed, 21 insertions(+), 12 deletions(-)
create mode 100644 tune/migrations/0006_alter_repertoiretune_tags.py
diff --git a/README.md b/README.md
index 28eb510..92f4da0 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ If you want to run jazztunes locally, take the following steps:
4. Activate the virtual environment ```.\venv\Scripts\activate``` (Windows) or ```source venv/bin/activate```
5. Install the necessary packages: ```pip install -r requirements.txt```
6. Create a .env file in the root directory with the variables (I've supplied a file, env-template, that shows what you need and has some default values)
-7. If you want to use the Public tune feature, you'll need to create a superuser: ```python manage.py createsuperuser```, then set that user's ID to ADMIN_USER_ID in .env (it will be 1 if it's the first user created). Then tunes you create as that user will also show up on the Public page. Creating a superuser is also a good idea because it gives you access to the [Django admin](https://docs.djangoproject.com/en/5.0/ref/contrib/admin/) interface.
+7. If you want to use the Public tune feature, you'll need to create a superuser: ```python manage.py createsuperuser```, then set that user's ID to ADMIN_USER_ID in .env (it will be 1 if it's the first user created, otherwise 2, etc.). Then tunes you create as that user will also show up on the Public page. Creating a superuser is also a good idea because it gives you access to the [Django admin](https://docs.djangoproject.com/en/5.0/ref/contrib/admin/) interface.
8. Run the program: ```python manage.py runserver ```
9. Ctrl-click on ```http://127.0.0.1:8000``` — This will open jazztunes in your default browser.
10. You can close the program by closing your browser and pressing Ctrl-C in the terminal running it.
diff --git a/tune/forms.py b/tune/forms.py
index 27d4ca1..65683b2 100644
--- a/tune/forms.py
+++ b/tune/forms.py
@@ -72,16 +72,6 @@ def clean_other_keys(self):
data = " ".join(formatted_data)
return data
- # def clean_tags(self):
- # data = self.cleaned_data["tags"]
- # if data is None:
- # return data
- # formatted_data = []
- # for tag in data.split():
- # formatted_data.append(tag.lower())
- # data = " ".join(formatted_data)
- # return data
-
class DateInput(forms.DateInput):
input_type = "date"
diff --git a/tune/migrations/0006_alter_repertoiretune_tags.py b/tune/migrations/0006_alter_repertoiretune_tags.py
new file mode 100644
index 0000000..98e3cf4
--- /dev/null
+++ b/tune/migrations/0006_alter_repertoiretune_tags.py
@@ -0,0 +1,19 @@
+# Generated by Django 5.0.4 on 2024-06-26 17:38
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("tune", "0005_tag_repertoiretune_tags"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="repertoiretune",
+ name="tags",
+ field=models.ManyToManyField(
+ blank=True, related_name="repertoire_tunes", to="tune.tag"
+ ),
+ ),
+ ]
diff --git a/tune/models.py b/tune/models.py
index 962b015..debb59c 100644
--- a/tune/models.py
+++ b/tune/models.py
@@ -165,7 +165,7 @@ class RepertoireTune(models.Model):
)
started_learning = models.DateTimeField(blank=True, null=True)
play_count = models.IntegerField(default=0)
- tags = models.ManyToManyField(Tag, related_name="repertoire_tunes")
+ tags = models.ManyToManyField(Tag, related_name="repertoire_tunes", blank=True)
class Meta:
unique_together = ("tune", "player")
From 13c856c2f3c74506db582f67590a627d98770261 Mon Sep 17 00:00:00 2001
From: JW Jacobson <116485484+jwjacobson@users.noreply.github.com>
Date: Wed, 26 Jun 2024 13:44:58 -0400
Subject: [PATCH 6/8] Set meter and year to render as empty strings if None
---
tune/templates/tune/list.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tune/templates/tune/list.html b/tune/templates/tune/list.html
index 2c122c7..b60fa12 100644
--- a/tune/templates/tune/list.html
+++ b/tune/templates/tune/list.html
@@ -84,8 +84,8 @@
{{ tune.tune.other_keys }} |
{{ tune.tune.song_form }} |
{{ tune.tune.style }} |
- {{ tune.tune.meter }} |
- {{ tune.tune.year }} |
+ {{ tune.tune.meter|default_if_none:"" }} |
+ {{ tune.tune.year|default_if_none:"" }} |
{% for tag in tune.tags.all %}
{{ tag.name }}
From 3f505426e32f55a1ca177b5fdfb1afb26d8a7b07 Mon Sep 17 00:00:00 2001
From: JW Jacobson <116485484+jwjacobson@users.noreply.github.com>
Date: Wed, 26 Jun 2024 13:56:30 -0400
Subject: [PATCH 7/8] Add help text to tags
---
.../0007_alter_repertoiretune_tags.py | 22 +++++++++++++++++++
tune/models.py | 7 +++++-
tune/templates/tune/form.html | 3 +++
3 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 tune/migrations/0007_alter_repertoiretune_tags.py
diff --git a/tune/migrations/0007_alter_repertoiretune_tags.py b/tune/migrations/0007_alter_repertoiretune_tags.py
new file mode 100644
index 0000000..6b3e141
--- /dev/null
+++ b/tune/migrations/0007_alter_repertoiretune_tags.py
@@ -0,0 +1,22 @@
+# Generated by Django 5.0.4 on 2024-06-26 17:52
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("tune", "0006_alter_repertoiretune_tags"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="repertoiretune",
+ name="tags",
+ field=models.ManyToManyField(
+ blank=True,
+ help_text="ctrl-click to select more than one",
+ related_name="repertoire_tunes",
+ to="tune.tag",
+ ),
+ ),
+ ]
diff --git a/tune/models.py b/tune/models.py
index debb59c..1330a9f 100644
--- a/tune/models.py
+++ b/tune/models.py
@@ -165,7 +165,12 @@ class RepertoireTune(models.Model):
)
started_learning = models.DateTimeField(blank=True, null=True)
play_count = models.IntegerField(default=0)
- tags = models.ManyToManyField(Tag, related_name="repertoire_tunes", blank=True)
+ tags = models.ManyToManyField(
+ Tag,
+ related_name="repertoire_tunes",
+ blank=True,
+ help_text="ctrl-click to select more than one",
+ )
class Meta:
unique_together = ("tune", "player")
diff --git a/tune/templates/tune/form.html b/tune/templates/tune/form.html
index 0d3010a..2c21670 100644
--- a/tune/templates/tune/form.html
+++ b/tune/templates/tune/form.html
@@ -40,6 +40,9 @@ {% if tune %}Edit{% else %}New{% endif %} Tune{{ field.label_tag }}
{{ field }}
{{ field.errors }}
+ {% if field.help_text %}
+ {{ field.help_text|safe }}
+ {% endif %}
{% if forloop.counter|divisibleby:2 %}
From 635cefc742d036f47ff6597319653a1e22c26611 Mon Sep 17 00:00:00 2001
From: JW Jacobson <116485484+jwjacobson@users.noreply.github.com>
Date: Wed, 26 Jun 2024 14:09:52 -0400
Subject: [PATCH 8/8] Add django.yml
---
.github/workflows/django.yml | 56 ++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
create mode 100644 .github/workflows/django.yml
diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml
new file mode 100644
index 0000000..c4085fc
--- /dev/null
+++ b/.github/workflows/django.yml
@@ -0,0 +1,56 @@
+name: jazztunes CI and Deployment
+
+on:
+ push:
+ branches: [ "main" ]
+
+jobs:
+ build-and-deploy:
+ environment: jazztunes
+ runs-on: ubuntu-latest
+ strategy:
+ max-parallel: 4
+ matrix:
+ python-version: [3.11, 3.12]
+
+ # Define service containers for running tests
+ services:
+ postgres:
+ image: postgres
+ env:
+ POSTGRES_USER: testuser
+ POSTGRES_PASSWORD: testpass
+ POSTGRES_DB: testdb
+ options: >-
+ --health-cmd pg_isready
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+ ports:
+ - 5432:5432
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v3
+ with:
+ python-version: ${{ matrix.python-version }}
+ - name: Install Dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install -r requirements.txt
+ - name: Run Tests
+ env:
+ DATABASE_URL: postgres://testuser:testpass@localhost:5432/testdb
+ ADMIN_USER_ID: ${{ secrets.ADMIN_USER_ID }}
+ ALLOWED_HOSTS: ${{ secrets.ALLOWED_HOSTS }}
+ SECRET_KEY: ${{ secrets.SECRET_KEY }}
+
+ run: |
+ pytest
+ - name: Deploy to Heroku
+ env:
+ HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
+ run: |
+ git fetch --unshallow || true
+ git push https://heroku:$HEROKU_API_KEY@git.heroku.com/${{ secrets.HEROKU_APP_NAME }}.git HEAD:main -f
\ No newline at end of file
|