def edit(request, theme_id): """ This is ripped out of Google's example. This is ugly and I hate it. """ user = users.GetCurrentUser() theme = None editing = False if theme_id: editing = True theme = Theme.theme(theme_id=theme_id) if theme is None: return http.HttpResponseNotFound('No theme exists with that key (%r)' % theme_id) form = ThemeForm(data=request.POST or None, instance=theme) if not request.POST: return respond(request, user, 'themes/new', { 'form': form, 'theme': theme, 'language': 'python', 'code': SNIPPETS['python'] }) errors = form.errors if not errors: try: theme = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err)
def rate(request, theme_id): user = users.GetCurrentUser() theme = Theme.theme(theme_id=theme_id) rating = request.POST.get('rating', 0.0) theme.rate(rating) theme.save() return HttpResponse()
def get(request, theme_id): user = users.GetCurrentUser() theme = Theme.theme(theme_id=theme_id) lang = 'python' return respond(request, user, 'themes/theme', { 'user': user, 'theme': theme, 'code': tokenize_to_html(SNIPPETS[lang]) })