This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def partition(thelist, n): | |
try: | |
n = int(n) | |
list(thelist) | |
except (ValueError, TypeError): | |
return [thelist] | |
p = len(thelist) / n | |
return [thelist[p*i:p*(i+1)] for i in range(n - 1)] + [thelist[p*(i+1):]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def partition_horizontal(thelist, n): | |
""" | |
break a list into 'n' pieces horizontally | |
""" | |
try: | |
n = int(n) | |
thelist = list(thelist) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic import ListView | |
from braces.views import LoginRequiredMixin, GroupRequiredMixin | |
from django_tables2 import RequestConfig | |
from .models import Customer | |
from .tables import CustomerTable | |
class CustomerListView(LoginRequiredMixin, GroupRequiredMixin, ListView): | |
model = Customer | |
template_name = 'customer_list.html' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import django_tables2 as tables | |
from django_tables2.utils import A | |
from .models import Customer | |
class CustomerTable(tables.Table): | |
account_number = tables.LinkColumn('customer-detail', args=[A('pk')]) | |
customer_first_name = tables.LinkColumn('customer-detail', args=[A('pk')]) | |
customer_last_name = tables.LinkColumn('customer-detail', args=[A('pk')]) | |
customer_email = tables.LinkColumn('customer-detail', args=[A('pk')]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_tables2 import SingleTableView | |
from django_tables2.config import RequestConfig | |
class PagedFilteredTableView(SingleTableView): | |
filter_class = None | |
formhelper_class = None | |
context_filter_name = 'filter' | |
def get_queryset(self, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# filters.py | |
import django_filters | |
from .models import Customer | |
class CustomerListFilter(django_filters.FilterSet): | |
class Meta: | |
model = Customer | |
fields = ['account_number', 'customer_first_name', 'customer_last_name', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic import ListView | |
from django.core.exceptions import ObjectDoesNotExist | |
from django.db.models.query_utils import Q | |
from django_tables2 import RequestConfig | |
from braces.views import LoginRequiredMixin, GroupRequiredMixin | |
from .tables import CustomerTable | |
from .filters import CustomerListFilter | |
from .utils import PagedFilteredTableView | |
from .models import Customer | |
from .forms import CustomerListFormHelper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic import DetailView | |
from .models import Customer | |
class CustomerDetailView(LoginRequiredMixin, DetailView): | |
def _allowed_methods(self): | |
return [m.upper() for m in self.http_method_names if hasattr(self, m)] | |
@classonlymethod | |
def as_view(cls, **initkwargs): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "base.html" %} | |
{% load bootstrap3 %} | |
{% load querystring from django_tables2 %} | |
{% load title from django_tables2 %} | |
{% load trans blocktrans from i18n %} | |
{% block "content" %} | |
{% if table.page %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py | |
from django.db import models | |
class Customer(models.Model): | |
company = models.ForeignKey('Company', null=False) | |
customer_first_name = models.CharField(null=False, blank=False, max_length=50) | |
customer_last_name = models.CharField(null=False, blank=False, max_length=50) | |
customer_email = models.CharField(null=False, blank=False, max_length=80) |
OlderNewer