Skip to content

Instantly share code, notes, and snippets.

@ceolson01
ceolson01 / .vimrc
Created August 23, 2016 13:52
Python .vimrc
set nocompatible " required
filetype off " required
" split layouts
set splitbelow
set splitright
" split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
@ceolson01
ceolson01 / pagination.html
Last active April 17, 2016 16:03
Django & Bootstrap Pagination for Large Number of Pages
{% if listings.has_previous or listings.has_next %}
<div class="text-center">
<ul class="pagination pagination-sm">
{% if listings.has_previous %}
<li><a href="?page=1">1</a></li>
<li><a href="?page={{ listings.previous_page_number }}">‹</a></li>
{% endif %}
{% for i in paginator.page_range %}
{% if i < listings.number and i >= listings.number|add:"-4" and i != listings.number and i != 1 %}
@ceolson01
ceolson01 / style.css
Created March 27, 2016 02:36
WordPress Toolbar with Sticky Header fix
.admin-bar .navbar-fixed-top {
top: 46px;
}
@media screen and (min-width: 783px) {
.admin-bar .navbar-fixed-top {
top: 32px;
}
}
@ceolson01
ceolson01 / mixins.py
Created March 19, 2016 15:05
Django Group Required Mixin
from django.core.exceptions import PermissionDenied
class GroupRequiredMixin(object):
"""
group_required - list of strings, required param
"""
group_required = None
@ceolson01
ceolson01 / forms.py
Created March 19, 2016 15:04
Django Simple Model Versioning
class NewsStoryForm(forms.ModelForm):
# ...form fields
def is_valid(self):
valid = super(NewsStoryForm, self).is_valid()
story = self.instance
form_version = self.cleaned_data.get('version', None)
latest_version = Story.objects.get(pk=story.pk).version
@ceolson01
ceolson01 / models.py
Last active August 23, 2016 22:12
Django Simple Slugify Method
from django.utils.text import slugify
def save(self, *args, **kwargs):
if not self.slug:
potential_slug = orig = slugify(self.title)
if Story.objects.filter(slug=potential_slug).exists():
slug_counter = 1
while Story.objects.filter(slug=potential_slug).exists():
potential_slug = '%s-%d' % (orig, slug_counter)