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 io | |
from PIL import Image | |
from django.core.urlresolvers import reverse | |
from django.conf import settings | |
from rest_framework import status | |
from rest_framework.test import APITestCase |
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 import forms | |
from django.utils.safestring import mark_safe | |
class CustomModelChoiceField(forms.ModelChoiceField): | |
def label_from_instance(self, obj): | |
return mark_safe("My Object custom label <strong>%i</strong>" % obj.id) | |
class MyForm(forms.ModelForm): | |
my_field = CustomModelChoiceField(label=_('The form label'), queryset=MyModel.objects.filter(), widget=forms.RadioSelect, empty_label=None) |
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
# year and month are variables | |
year = 2015 | |
month = 7 # August (0 indexed) | |
startDate = moment([year, month]) | |
# Get the first and last day of the month | |
firstDay = moment(startDate).startOf('month') | |
endDay = moment(startDate).endOf('month') | |
# Create a range for the month we can iterate through |
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 export_profile(request): | |
import csv, StringIO, datetime | |
date = datetime.datetime.now() | |
# Create the HttpResponse object with the appropriate CSV header. | |
response = HttpResponse(content_type='text/csv') | |
response['Content-Disposition'] = 'attachment; filename="profiles-%s.csv"' % (date.strftime('%d-%m-%Y')) | |
writer = csv.writer(response) |
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 CategoryListFilter(SimpleListFilter): | |
# USAGE | |
# In your admin class, pass trhe filter class as tuple for the list_filter attribute: | |
# | |
# list_filter = (CategoryListFilter,) | |
# Human-readable title which will be displayed in the | |
# right admin sidebar just above the filter options. |
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
var myApp = angular.module('myApp').config(function($httpProvider) { | |
$httpProvider.defaults.headers.post['X-CSRFToken'] = $('input[name=csrfmiddlewaretoken]').val(); | |
}); |
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
<div class="slideshow"> | |
<ul class="bxslider"> | |
{% for image in images %} | |
<li><img src="{{image.url}}" alt=""></li> | |
{% endfor %} | |
</ul> | |
<div class="gallery-thumbs-container"> | |
<ul id="gallery-thumbs" class="gallery-thumbs-list"> | |
{% for image in images %} | |
<li class="thumb-item"> |
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
# Tested in Django 1.6 | |
class ImportForm(forms.Form): | |
csv_file = forms.FileField(label=_('Select CSV file')) | |
def clean_csv_file(self): | |
f = self.cleaned_data['csv_file'] | |
if not f.content_type in ['text/csv',]: | |
raise forms.ValidationError(_("The file type is not accepted.")) |
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
# Example integration of a background-image uploader | |
# Author: Guillaume Piot | |
# Email: guillaume@cotidia.com | |
# Company: Cotidia Ltd | |
# Licence: MIT | |
# | |
# The div holder is absolute positioned within the parent div | |
# | |
# <div class="[ article__image ] [ article-image ] [ editable ] [ parallax ]" data-name="article_image"> | |
# <div |
NewerOlder