Skip to content

Instantly share code, notes, and snippets.

@deronsizemore
Last active December 30, 2015 18:08
Show Gist options
  • Save deronsizemore/bd27d9fda59a28ad7ae2 to your computer and use it in GitHub Desktop.
Save deronsizemore/bd27d9fda59a28ad7ae2 to your computer and use it in GitHub Desktop.
from django.contrib import admin
from django.forms import TextInput, Textarea
from django import forms
from django.forms import ModelForm, Media
from blog.models import Post
from suit.widgets import SuitDateWidget, SuitTimeWidget, SuitSplitDateTimeWidget, LinkedSelect, EnclosedInput
from suit_ckeditor.widgets import CKEditorWidget
class PostForm(forms.ModelForm):
class Meta:
model = Post
ck_editor_toolbar = [
{ 'name': 'styles', 'items': [ 'Format' ] },
{ 'name': 'basicstyles', 'items': [ 'Bold', 'Italic' ] },
{ 'name': 'paragraph', 'items': [ 'NumberedList', 'BulletedList', '-', 'Blockquote'] },
{ 'name': 'colors', 'items': [ 'TextColor' ] },
{ 'name': 'links_image', 'items': [ 'Image', '-', 'Link' ] },
{ 'name': 'editing', 'items': [ 'Find', 'Replace', '-', 'Scayt' ] },
{ 'name': 'tools', 'items': [ 'Maximize' ] },
{ 'name': 'document', 'items': [ 'Source' ] },
{ 'name': 'upload', 'items': [ 'filebrowser' ] },
# list of other buttons should be they needed later.
# JustifyLeft, JustifyCenter, JustifyRight, Underline, Strike
]
ck_editor_config = {
# 'autoGrow_minHeight': 100,
# 'autoGrow_maxHeight': 250,
'height': '300',
# 'extraPlugins': 'autogrow',
'toolbar': ck_editor_toolbar}
widgets = {
'pub_date': SuitSplitDateTimeWidget,
'author': LinkedSelect,
'title': TextInput(attrs={'class': 'span12'}),
'slug': TextInput(attrs={'class': 'span12'}),
'body': CKEditorWidget(editor_options=ck_editor_config),
}
class Media:
js = ('filebrowser/js/FB_CKEditor.js')
css = {
'all': ('filebrowser/css/suit-filebrowser.css',)
}
class PostAdmin(admin.ModelAdmin):
form = PostForm
list_display = ('active', 'title', 'pub_date')
list_display_links = ['title']
list_editable = ['active']
list_filter = ['pub_date', 'active']
search_fields = ['title', 'summary', 'body']
date_hierarchy = 'pub_date'
admin.site.register(Post, PostAdmin)
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import MaxLengthValidator
from django.template.defaultfilters import slugify
from filebrowser.fields import FileBrowseField
from datetime import datetime
import watson
class Post(models.Model):
active = models.BooleanField(default=True)
pub_date = models.DateTimeField('date published', default=datetime.now, blank=True)
author = models.ForeignKey(User, blank=False)
title = models.CharField(max_length=100, blank=True)
slug = models.SlugField(max_length=255, blank=True, default='')
large_image = FileBrowseField("Image", max_length=200, blank=True, null=True)
small_image_one = FileBrowseField("Image", max_length=200, blank=True, null=True)
small_image_two = FileBrowseField("Image", max_length=200, blank=True, null=True)
body = models.TextField()
def __unicode__(self):
return self.title
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super(Post, self).save(*args, **kwargs)
# for redirecting URL so slug is always shown
def get_absolute_url(self):
return "/detail/%s/%s" % (self.id, self.slug)
watson.register(Post)
# Django settings for golfledger project.
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
DEBUG = True
TEMPLATE_DEBUG = DEBUG
THUMBNAIL_DEBUG = True
# Django Suit configuration example
SUIT_CONFIG = {
# header
'ADMIN_NAME': 'Golf Ledger',
# 'HEADER_DATE_FORMAT': 'l, j. F Y',
'HEADER_TIME_FORMAT': 'h:i',
'MENU': (
{'app': 'home', 'label': 'Home'},
{'app': 'auth', 'label': 'Users', 'models': ('user', 'group')},
'accounts',
{'app': 'links', 'label': 'Links'},
{'app': 'blog', 'label': 'Blog'},
{'app': 'flatpages', 'label': 'Pages'},
{'app': 'django_comments', 'label': 'Comments'},
{'label': 'File Browser', 'icon':'icon-folder-open', 'url': '/admin/filebrowser/browse'},
)
# forms
# 'SHOW_REQUIRED_ASTERISK': True, # Default True
# 'CONFIRM_UNSAVED_CHANGES': True, # Default True
# menu
# 'SEARCH_URL': '/admin/auth/user/',
# 'MENU_ICONS': {
# 'sites': 'icon-leaf',
# 'auth': 'icon-lock',
# },
# 'MENU_OPEN_FIRST_CHILD': True, # Default True
# 'MENU_EXCLUDE': ('auth.group',),
# 'MENU': (
# 'sites',
# {'app': 'auth', 'icon':'icon-lock', 'models': ('user', 'group')},
# {'label': 'Settings', 'icon':'icon-cog', 'models': ('auth.user', 'auth.group')},
# {'label': 'Support', 'icon':'icon-question-sign', 'url': '/support/'},
# ),
}
# Filebrowser settings
FILEBROWSER_SUIT_TEMPLATE = True
FILEBROWSER_DIRECTORY = ''
FILEBROWSER_ADMIN_VERSIONS = ''
# Settings needed for Userena to work correctly
AUTHENTICATION_BACKENDS = (
'userena.backends.UserenaAuthenticationBackend',
'guardian.backends.ObjectPermissionBackend',
'django.contrib.auth.backends.ModelBackend',
)
ANONYMOUS_USER_ID = -1
AUTH_PROFILE_MODULE = 'accounts.MyProfile'
USERENA_SIGNIN_REDIRECT_URL = '/member/%(username)s/'
LOGIN_REDIRECT_URL = '/member/%(username)s/'
LOGIN_URL = '/member/signin/'
LOGOUT_URL = '/member/signout/'
USERENA_MUGSHOT_DEFAULT = ''
USERENA_MUGSHOT_SIZE = '200'
USERENA_HIDE_EMAIL = 'True'
# end Userena settings
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'golfledger.db', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Louisville'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = '/Users/Deron/Sites/golfledger/golfledger/assets/uploads/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/assets/uploads/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/assets/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/Users/Deron/Sites/golfledger/golfledger/assets/',
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '^&5=*k48w#iknz63@r&8%!-3hfy!r4sax7-&0&3zwpi52452*c'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
ROOT_URLCONF = 'golfledger.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'golfledger.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/Users/Deron/Sites/golfledger/golfledger/templates',
)
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'south',
'links',
'userena',
'guardian',
'sorl.thumbnail',
'accounts',
'blog',
'django_comments',
'favorites',
'likes',
'follows',
'watson',
'templatetags',
'embed_video',
'suit',
'filebrowser',
'suit_ckeditor',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment