class SuccessMessageMixin(object):
"""
Adds a success message on successful form submission.
"""
success_message = ''
def form_valid(self, form):
response = super(SuccessMessageMixin, self).form_valid(form)
success_message = self.get_success_message(form.cleaned_data)
if success_message:
messages.success(self.request, success_message)
return response
def get_success_message(self, cleaned_data):
return self.success_message % cleaned_data
class CategoryView(TemplateView):
template_folder = 'build'
template_name = 'build/category.html'
...
def get_template_names(self):
template = self.template_name
category_template = '{folder}/{slug}/category.html'.format(folder=self.template_folder, slug=self.category.slug)
return [category_template, template]
...
rows, err := DB.Query("SELECT EXISTS (SELECT id FROM users WHERE login=?)", login)
if result == true {
return isLoginAvailable(login)
} else {
return false
}
return result && isLoginAvailable(login)
from haystack import indexes
from .models import Post
from django.utils import timezone
class PostIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
content = indexes.CharField(model_attr='content')
def get_model(self):
return Post
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(datetime__lte=timezone.now())