Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #96 from rossbruniges/final-push
Browse files Browse the repository at this point in the history
Final push
  • Loading branch information
rossbruniges committed Dec 11, 2012
2 parents 9a6a213 + 23c3487 commit b6474e8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 54 deletions.
12 changes: 12 additions & 0 deletions gameon/base/templates/base.html
Expand Up @@ -17,6 +17,18 @@
{% block page_css %}{% endblock %}
<link rel="icon" href="{{ static('base/img/favicon.ico') }}" />
{% block social_meta %}{% endblock %}
{% if not APP_MSG %}
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35433268-16']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
{% endif %}
</head>
<body id="{% block page_id %}{% endblock %}" class="{% block section_class %}{% endblock %}">
<script type="text/javascript">
Expand Down
16 changes: 10 additions & 6 deletions gameon/submissions/forms.py
@@ -1,7 +1,7 @@
from django import forms
from django.forms.models import ModelChoiceField

from gameon.submissions.widgets import CategorySelectWidget, AdvancedFileInput
from gameon.submissions.widgets import CategorySelectWidget

from gameon.submissions.models import Entry, Category

Expand All @@ -16,7 +16,7 @@
'url': forms.TextInput(attrs={'aria-describedby': 'info_url'}),
'description': forms.Textarea(attrs={'aria-describedby': 'info_description',
'data-maxlength': '1000'}),
'thumbnail': AdvancedFileInput(attrs={'aria-describedby': 'info_description'}),
'thumbnail': forms.FileInput(attrs={'aria-describedby': 'info_description'}),
'video_url': forms.TextInput(attrs={'aria-describedby': 'info_description'}),
'team_members': forms.Textarea(attrs={'aria-describedby': 'info_team_members',
'data-maxlength': '250'}),
Expand All @@ -36,10 +36,14 @@ def clean_thumbnail(self):
# ensure that people can't upload a HUGE file
# hopefully we can top and tail this with a LimitRequestBody setting in
# apache (http://stackoverflow.com/a/6195637/1308104)
thumb = self.cleaned_data.get('thumbnail', False)
if thumb and thumb._size > 2 * 1024 * 1024:
raise forms.ValidationError("That file is a bit big - please use one under 2mb")
return thumb
thumb = self.cleaned_data.get('thumbnail')
if thumb and thumb != False:
try:
if thumb._size > 2 * 1024 * 1024:
raise forms.ValidationError("That file is a bit big - please use one under 2mb")
return thumb
except AttributeError:
return thumb

class Meta:
model = Entry
Expand Down
3 changes: 2 additions & 1 deletion gameon/submissions/templates/submissions/create.html
Expand Up @@ -58,7 +58,8 @@ <h1 class="busta shout">{% block view_title %}Submit Your Game{% endblock %}</h1
<span class="extra meta" id="info_thumbnail">(maximum 2mb file size)</span>
</label>
</div>
<div>
<div class="cf">
{% block image_preview %}{% endblock %}
{{ form.thumbnail }}
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions gameon/submissions/templates/submissions/edit.html
Expand Up @@ -5,6 +5,14 @@

{% block view_title %}Edit Your Game{% endblock %}

{% block image_preview %}
{% if form.thumbnail.value %}
<p class="meta"><strong>Current image:</strong></p>
<span class="frame"><img src="{{ MEDIA_URL }}{{ form.thumbnail.value() }}" alt="" /></span>
<p class="meta">Fancy a change? Feel free to upload a different thumbnail:</p>
{% endif %}
{% endblock %}

{% block cta_box %}
<span>Ready to edit?</span>
<input type="submit" name="submit" class="cta" value="Edit my Game!" />
Expand Down
47 changes: 0 additions & 47 deletions gameon/submissions/widgets.py
Expand Up @@ -4,53 +4,6 @@

from gameon.submissions.models import Category

from django.utils.html import escape, conditional_escape
from django.forms.widgets import ClearableFileInput, CheckboxInput


# The ClearableFieldWidget is pretty horrible - trying to make it a bit nicer
class AdvancedFileInput(ClearableFileInput):

def __init__(self, *args, **kwargs):

self.url_length = kwargs.pop('url_length', 30)
self.preview = kwargs.pop('preview', True)
self.image_width = kwargs.pop('image_width', 100)
super(AdvancedFileInput, self).__init__(*args, **kwargs)

def render(self, name, value, attrs=None,):

substitutions = {
'initial_text': "<p class='meta'>Right now you have</p>",
'input_text': '<span class="meta">Change this</span>',
'clear_template': '',
'clear_checkbox_label': '<span class="meta">Delete this</span>',
}
template = u'%(input)s'

substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs)

if value and hasattr(value, "url"):

template = self.template_with_initial
if self.preview:
substitutions['initial'] = (u'<span class="frame">\
<img src="{0}" width="{2}"></span>'.format
(escape(value.url), '...' + escape(force_unicode(value))[-self.url_length:],
self.image_width))
else:
substitutions['initial'] = (u'<a href="{0}">{1}</a>'.format
(escape(value.url), '...' + escape(force_unicode(value))[-self.url_length:]))
if not self.is_required:
checkbox_name = self.clear_checkbox_name(name)
checkbox_id = self.clear_checkbox_id(checkbox_name)
substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
substitutions['clear_template'] = self.template_with_clear % substitutions

return mark_safe(template % substitutions)


# Used to display the category description with each category in a RadioSelect widget
class CategorySelectRenderer(RadioFieldRenderer):
Expand Down

0 comments on commit b6474e8

Please sign in to comment.