Make it possible to pre-select a mailinglist in the subcription form

This is done by putting #<id> at the end of the URL.
This commit is contained in:
Magnus Hagander
2013-06-20 17:12:43 +02:00
parent e852cb5eff
commit bfd7911aa6
5 changed files with 19 additions and 3 deletions

View File

@ -3,6 +3,8 @@ from django import forms
from models import MailingList
class SubscribeForm(forms.Form):
jquery = True
email = forms.EmailField(max_length=100,required=True,label="Email address")
action = forms.ChoiceField(required=True, choices=(('subscribe','Subscribe'),('unsubscribe','Unsubscribe')))
receive = forms.BooleanField(required=False, label="Receive mail", initial=True)

View File

@ -46,9 +46,10 @@ def subscribe(request):
# GET, so render up the form
form = SubscribeForm()
return render_to_response('base/form.html', {
return render_to_response('lists/subscribe_form.html', {
'form': form,
'operation': 'Subscribe',
'jquery': True,
'form_intro': """
Please do not subscribe to mailing lists using e-mail accounts protected by
mail-back anti-spam systems. These are extremely annoying to the list maintainers

View File

@ -58,6 +58,7 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
'markdownfields': markdownfields,
'form_intro': hasattr(form, 'form_intro') and form.form_intro or None,
'toggle_fields': hasattr(form, 'toggle_fields') and form.toggle_fields or None,
'jquery': hasattr(form, 'jquery') and form.jquery or None,
'savebutton': (itemid == "new") and "New" or "Save",
'operation': (itemid == "new") and "New" or "Edit",
}, NavContext(request, navsection))

View File

@ -42,6 +42,9 @@
{% block extrahead %}
{{ block.super }}
{%if toggle_fields or jquery %}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js"></script>
{%endif%}
{%if markdownfields%}
<link rel="stylesheet" type="text/css" href="/media/css/showdown_preview.css" />
<script type="text/javascript" src="/media/showdown/showdown.js"></script>
@ -54,7 +57,6 @@
}
</script>
{%if toggle_fields %}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js"></script>
<script language="javascript">
{%for f in toggle_fields%}
function toggle_{{f.name}}() {

View File

@ -0,0 +1,10 @@
{%extends "base/form.html"%}
{% block extrahead %}
{{ block.super }}
<script language="javascript">
$(function() {
var part = document.URL.substring(document.URL.indexOf('#')+1);
$('#id_lists').val(part);
});
</script>
{%endblock%}