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 random | |
from typing import Optional, Any, List, Tuple | |
consonant_initial_digraphs = set( | |
["ch", "sh", "th", "thr", "ph", "wh", "ck", "kn", "wr"] | |
) | |
consonant_final_digraphs = set(["ch", "ng", "sh", "th", "tch"]) | |
vowel_digraphs = [ | |
"ai", |
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 os | |
import mimetypes | |
from django.contrib.staticfiles.storage import staticfiles_storage | |
from django.http import Http404, FileResponse | |
def static_file(request, path, content_type=None): | |
if not staticfiles_storage.exists(path): | |
raise Http404() |
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
class AccountsStatisticsDetail(TemplateView): | |
template_name = 'grow/accountsstatistics.html' | |
def get_context_data(self, **kwargs): | |
context = super().get_context_data(**kwargs) | |
username = self.kwargs.get('username') | |
if username: | |
context['username'] = username | |
context['account_stats'] = ( | |
AccountsStatistics.objects |
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
def user_in_group(user, group_id=None, group_id_list=None): | |
if group_id_list is None: | |
group_id_list = set(group_id] | |
if not hasattr(user, 'group_ids'): | |
user.group_ids = set(user.groups.values_list('pk', flat=True)) | |
return user.group_ids.intersection(group_id_list) |
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
__module_name__ = 'Filter' | |
__module_version__ = '1.0.custom' | |
__module_description__ = 'Filters join/part/voice messages' | |
import hexchat | |
import collections | |
from time import time | |
last_seen = {} # For each entry: the key is the user's nickname, the entry | |
# is a list: element 0: last seen time |
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 re | |
array_qs = re.compile(r'(\w+)\[(\d*)\]$') | |
class UnPHPify(object): | |
def process_request(self, request): | |
""" | |
Iterate request.GET, request.POST and request.FILES and amend the dict |
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
class UpdateOrCreateMixin(object): | |
""" | |
A view mixin to allow views that use SingleObjectMixin to not fail if no pk/slug is provided. | |
Primarily useful for making an UpdateView that can create objects too. For example:: | |
class MyView(UpdateOrCreateMixin, UpdateView): | |
... | |
url(r'^add/$', MyView.as_view(), name='my-add-view'), |
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
""" | |
Smarter django-pipeline finders. | |
In your settings file, you'll want something like this: | |
# Exclude pipelined sources from being found as static files. | |
STATICFILES_FINDERS = ( | |
'pipeline_finders.PipelineFileSystemFinder', | |
'pipeline_finders.PipelineAppDirectoriesFinder', | |
'pipeline_finders.PipelineFinder', |
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
@register.assignment_tag | |
def flatpages(a, b, *order_first): | |
""" | |
Get the flatpages, optionally with specific ones ordered first. | |
Usage:: | |
{% flatpages '/home/' '/about/' as flatpages %} | |
{% for flatpage in flatpages %}...{% endfor %} | |
""" |
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 .conf_base import AppSettings | |
class Settings(AppSettings): | |
YOUR_SETTING = True | |
""" | |
Give each setting some documentation for sphinx autodoc if you like. | |
""" | |
NewerOlder