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

Current status of play view/form/template (non-functional) #122

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

jwjacobson
Copy link
Owner

No description provided.

@jwjacobson jwjacobson merged commit c49089d into main Jan 4, 2024
Copy link
Collaborator

@bbelderbos bbelderbos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, will run the app to see this in action ...


def __init__(self, *args, **kwargs):
matching_tunes_queryset = kwargs.pop("matching_tunes_queryset", None)
super(PlayForm, self).__init__(*args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Py 2, starting v3 you can do super()

play_form = PlayForm(initial={"suggested_tune": suggested_tune})
return render(request, "tune/play.html", locals())
# play_form = PlayForm([tune.id for tune in tunes])
suggested_tune = tunes.first()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where I said tunes[0] previously, first() and last() also work

matching_tunes_queryset = RepertoireTune.objects.filter(id__in=matching_tunes)
play_form = PlayForm(
request.POST or None,
initial={"matching_tunes": matching_tunes},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to run this, so here you want to form pre-populated ...

if choice == "Play!":
suggested_tune.last_played = timezone.now()
suggested_tune.save()
messages.success(request, f"Played {suggested_tune.tune.title}!")
else:
print(f"playform invalid: {play_form.errors}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error should show up in the form in the template?

@@ -18,7 +18,10 @@
<p> Okay? </p>
<form method="post" action="{% url 'tune:tune_play' %}">
{% csrf_token %}
{{ play_form.suggested_tune }}
{% for value in play_form.initial.matching_tunes %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can not be done with the model form out of the box?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants