Commits

Steve Losh committed df25941

Add a repo request form.

  • Participants
  • Parent commits d8f974b

Comments (0)

Files changed (17)

feedback/forms.py

+from django.forms import ModelForm
+
+from noodlebucket.feedback.models import FeedbackRepoRequest
+
+
+class FeedbackRepoRequestForm(ModelForm):
+    class Meta:
+        model = FeedbackRepoRequest
+    
+
+from django.conf.urls.defaults import *
+
+
+urlpatterns = patterns('noodlebucket.feedback.views',
+    url(r'request/$', 'request_repo', name='request-repo'),
+)

feedback/views.py

+from django.core.urlresolvers import reverse
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+
+from noodlebucket.feedback.forms import FeedbackRepoRequestForm
+
+def request_repo(request):
+    """Request that a repository be added to Noodle Bucket."""
+    
+    if request.method == 'POST':
+        form = FeedbackRepoRequestForm(request.POST)
+        if form.is_valid():
+            form.save()
+            
+            return HttpResponseRedirect(reverse('thanks-request-repo'))
+    else:
+        form = FeedbackRepoRequestForm()
+    
+    return render_to_response(
+        'feedback/request_repo.html',
+        { 'form': form },
+        context_instance=RequestContext(request)
+    )
+

media/css/base.css

     font-style: italic;
     color: #666;
 }
+
+form div.field textarea {
+    width: 30em;
+}
+form div.field ul.errorlist {
+    list-style-type: none;
+    display: inline;
+    font-family: Palatino, "Palatino Linotype";
+    line-height: 0em;
+}
+form div.field ul.errorlist li {
+    display: inline;
+    margin-left: 1em;
+    color: #E2003B;
+    font-style: italic;
+}
     'django.contrib.flatpages',
     'django.contrib.markup',
     'noodlebucket.feedback',
+    'noodlebucket.util',
     'gravatar',
     'typogrify',
 )

templates/aardvark/fields/checkbox.html

+<li>
+    <label>
+        <input id="{{ field.auto_id }}" type="checkbox" class="checkbox"
+               name="{{ field.html_name }}"
+               {% if checked %}checked="checked"{% endif %} />
+        {% firstof label field.label %}
+        {{ field.errors }}
+        <span class="form-help-text">{{ field.help_text }}</span>
+    </label>
+</li>

templates/aardvark/fields/password.html

+<div class="field">
+    <label for="{{ field.auto_id }}">{% firstof label field.label %} {{ field.errors }}</label>
+    <input type="password" class="password" id="{{ field.auto_id }}" 
+           name="{{ field.html_name }}" />
+    {% if field.help_text %}
+        <p class="form-help-text">{{ field.help_text }}</p>
+    {% endif %}
+</div>

templates/aardvark/fields/radio.html

+<label>{{ label }} {{ field.errors }}</label>
+<ul class="fields">
+    {% for choice in field.field.choices %}
+        <li>
+            <label>
+            <input type="radio" class="radio"
+                   name="{{ field.html_name }}"
+                   value="{{ choice.0 }}"
+                   {% ifequal selected choice.0 %}checked="checked"{% endifequal %} />
+            {{ choice.1 }}
+            </label>
+        </li>
+    {% endfor %}
+</ul>
+{% if field.help_text %}
+    <p class="form-help-text">{{ field.help_text }}</p>
+{% endif %}

templates/aardvark/fields/text-date.html

+<div class="field">
+    <label for="{{ field.auto_id }}">{% firstof label field.label %} {{ field.errors }}</label>
+    <input type="text" class="text" id="{{ field.auto_id }}" 
+           name="{{ field.html_name }}"
+           value="{% if initial %}{{ initial }}{% endif %}" />
+    {% if field.help_text %}
+        <p class="form-help-text">{{ field.help_text }}</p>
+    {% endif %}
+</div>
+
+<script type="text/javascript">
+    $(document).ready(function() {
+        $('#{{ field.auto_id }}').datepicker({
+            dateFormat: 'yy-mm-dd',
+            minDate: '-0d',
+            firstDay: 1
+        });
+    });
+</script>

templates/aardvark/fields/text-datetime.html

+<div class="split-datetime-field">
+    {{ field.errors }}
+    
+    <div class="field split-datetime-date-field">
+        <label for="{{ field.auto_id }}_0">{% firstof label field.label %} Date</label>
+        <input type="text" class="text" id="{{ field.auto_id }}_0" 
+               name="{{ field.html_name }}_0"
+               value="{% if initial_date %}{{ initial_date }}{% endif %}" />
+
+    </div>
+
+    <div class="field split-datetime-time-field">
+        <label for="{{ field.auto_id }}_1">{% firstof label field.label %} Time</label>
+        <input type="text" class="text" id="{{ field.auto_id }}_1" 
+               name="{{ field.html_name }}_1"
+               value="{% if initial_time %}{{ initial_time }}{% endif %}" />
+    </div>
+
+    {% if field.help_text %}
+        <p class="form-help-text">{{ field.help_text }}</p>
+    {% endif %}
+</div>
+
+<script type="text/javascript">
+    $(function() {
+        $('#{{ field.auto_id }}_0').datepicker({
+            dateFormat: 'yy-mm-dd',
+            minDate: '-0d',
+            firstDay: 1
+        });
+    });
+</script>

templates/aardvark/fields/text.html

+<div class="field" id="{{ field.auto_id }}-container">
+    <label for="{{ field.auto_id }}">{% firstof label field.label %} {{ field.errors }}</label>
+    <input type="text" class="text" id="{{ field.auto_id }}" 
+           name="{{ field.html_name }}"
+           value="{% if initial %}{{ initial }}{% endif %}" />
+    {% if field.help_text %}
+        <p class="form-help-text">{{ field.help_text }}</p>
+    {% endif %}
+</div>

templates/aardvark/fields/textarea.html

+<div class="field" id="{{ field.auto_id }}-container">
+    <label for="{{ field.auto_id }}">{% firstof label field.label %} {{ field.errors }}</label>
+    <textarea id="{{ field.auto_id }}" rows="8"
+              name="{{ field.html_name }}">{% if initial %}{{ initial }}{% endif %}</textarea>
+    {% if field.help_text %}
+        <p class="form-help-text">{{ field.help_text }}</p>
+    {% endif %}
+</div>

templates/feedback/request_repo.html

+{% extends "base.html" %}
+{% load aardvark_fields %}
+
+{% block header %}Request a Repository{% endblock %}
+
+{% block content %}
+    <p>Want your repository in the bucket?  Request it here:</p>
+    
+    <form action="" method="post" accept-charset="utf-8">
+        {% aardvark form.author text label "Your Name" %}
+        {% aardvark form.repo_name text label "BitBucket repository (user/reponame)" %}
+        {% aardvark form.message textarea label "Why should I add your repo?" %}
+        
+        <p><input type="submit" value="Request &rarr;"></p>
+    </form>
+{% endblock %}
 urlpatterns = patterns('',
     url(r'^admin/', include(admin.site.urls)),
     url(r'^grappelli/', include('grappelli.urls')),
+    url(r'^feedback/', include('noodlebucket.feedback.urls')),
 )
 
 if settings.DEBUG:

util/__init__.py

Empty file added.

util/templatetags/__init__.py

Empty file added.

util/templatetags/aardvark_fields.py

+from django import template
+from django.template.loader import render_to_string
+
+
+register = template.Library()
+
+class AardvarkNode(template.Node):
+    def __init__(self, field, field_type, label=None):
+        self.field = template.Variable(field)
+        self.field_type = field_type.strip('"')
+        self.label = label.strip('"') if label else None
+    
+    def render(self, context):
+        field = self.field.resolve(context)
+        f = field.form
+        initial = field.data if f.data else f.initial.get(field.name, '')
+        
+        template = "aardvark/fields/%s.html" % self.field_type
+        
+        return render_to_string(template, {
+            'field': field,
+            'initial': initial,
+            'label': self.label,
+        })
+
+
+@register.tag
+def aardvark(parser, token):
+    """Render nice, aarvark-legs style form fields."""
+    
+    bits = token.split_contents()
+    tag_name = bits.pop(0)
+    
+    if len(bits) < 2:
+        raise template.TemplateSyntaxError(
+            u"'%s' tag requires a field and field type." % tag_name
+        )
+    
+    field = bits.pop(0)
+    field_type = bits.pop(0)
+    
+    if not len(bits) % 2 == 0:
+        raise template.TemplateSyntaxError(
+            u"'%s' tag requires paired arguments." % tag_name
+        )
+    
+    bits, kwargs = iter(bits), {}
+    
+    for bit in bits:
+        if bit == 'label':
+            kwargs['label'] = bits.next()
+    
+    return AardvarkNode(field, field_type, **kwargs)
+