Skip to content

Instantly share code, notes, and snippets.

@SmileyChris
SmileyChris / urls.py
Last active June 18, 2018 22:23 — forked from rixx/urls.py
Delivering static files on fixed URL in Django
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()
@SmileyChris
SmileyChris / ok.py
Last active May 29, 2018 00:35 — forked from converge/ok.py
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
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)
################entering some data the first time to my form doesnt work, it gives this error:
IntegrityError at /job/add/article/
(1048, "Column 'author_id' cannot be null")
Request Method: POST
Request URL: http://localhost:8000/job/add/article/
Django Version: 1.4.3
@SmileyChris
SmileyChris / fields.py
Created February 14, 2012 00:04 — forked from insin/fields.py
Formatting horrible if
def run_validators(self, value):
if value in validators.EMPTY_VALUES:
return
errors = []
for v in self.validators:
try:
v(value)
except ValidationError, e:
message = None
if hasattr(e, 'code'):
{% if user %}
<div class="left_column">
{% endif %}
{% block content %}
{% endblock %}
{% if user %}
</div>
<div class="right_column">
<div class="sidebar_header user_info">
<h2>Welcome.</h2>