"""
# coding=utf-8
Django settings for castaway project.
Generated by 'django-admin startproject' using Django 1.9.4.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
from django.contrib.staticfiles import finders
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
TEMPLATE_CONTEXT_PROCESSORS = TCP + [
'django.core.context_processors.request',
]
# Application definition
INSTALLED_APPS = [
'suit',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'castshop',
'suit_redactor',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'castaway.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
"django.core.context_processors.media",
"django.core.context_processors.static",
],
},
},
]
WSGI_APPLICATION = 'castaway.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'chzat',
'USER': ******
'PASSWORD': ******
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'ru-RU'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# SQL_STACKTRACE = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media')
MEDIA_URL = '/media/'
TEMPLATES_URL = os.path.join(BASE_DIR, 'castshop/templates/castshop/')
SUIT_CONFIG = {
# header
'ADMIN_NAME': 'Castaway Admin',
'HEADER_DATE_FORMAT': 'l, j. F Y',
'HEADER_TIME_FORMAT': 'H:i',
# 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/'},
),
# misc
'LIST_PER_PAGE': 15
}
# coding=utf-8
from getpass import getuser
from django.contrib import admin
import logging
# Register your models here.
# Register your models here.
from django.core.urlresolvers import reverse
from django.contrib.admin import ModelAdmin
from django.forms import ModelForm, TextInput
from suit.widgets import SuitSplitDateTimeWidget
from suit_redactor.widgets import RedactorWidget
from castshop import models
from castshop.models import Articles, Comments, Category, Tag
class PageForm(ModelForm):
class Meta:
widgets = {
'article_text': RedactorWidget(editor_options={'lang': 'en'}),
'article_date': SuitSplitDateTimeWidget
}
def make_published(modeladmin, request, queryset):
queryset.update(article_status='p', article_published=getuser(), article_status_ok=True)
make_published.short_description = 'Опублиовать'
def close_published(modeladmin,request,queryset):
queryset.update(article_status='w')
queryset.update(article_status_ok=False)
make_published.short_description = 'Снять с публикации'
#
# Опции отображения полей ситатей в админке
class ArticleComments (admin.StackedInline):
model = Comments
extra = 2
class ArticleAdmin(admin.ModelAdmin):
fields = ('article_title', 'article_slug', 'article_text','article_image' ,'article_category','article_tag','article_date','article_user')
inlines = [ArticleComments]
list_filter = ['article_date', 'article_status_ok']
actions = [make_published, close_published]
list_display = ['article_title','article_date', 'article_status','article_published','article_status_ok']
# list_editable = ['article_title', 'article_status']
save_on_top = True
search_fields = ['article_title','article_published' ]
prepopulated_fields = {"article_slug": ("article_title",)}
form = PageForm
class CategoryAdmin (admin.ModelAdmin):
prepopulated_fields = {"category_slug": ("category_name",)}
admin.site.register(Articles,ArticleAdmin)
admin.site.register(Category,CategoryAdmin)
admin.site.register(Tag)
#!/usr/bin/python
# coding=utf-8
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
# Create your models here.
class Category(models.Model):
class Meta:
db_table = 'category'
verbose_name = 'Категория'
verbose_name_plural = 'Категории'
category_name = models.CharField(max_length=100)
category_slug = models.SlugField()
def __unicode__(self):
return self.category_name
class Tag(models.Model):
tag = models.CharField(max_length=50)
def __unicode__(self):
return self.tag
class Articles (models.Model):
class Meta:
db_table = 'articles'
verbose_name_plural = 'Статьи'
verbose_name = 'Статья'
ordering = ['-article_date']
STATUS_CHOICES = (
('d', 'Черновик'),
('p', 'Опублиованно'),
('w', 'Снято'),
)
article_title = models.CharField(max_length=200, verbose_name='Заголовок')
article_slug = models.SlugField(default='')
article_text = models.TextField(verbose_name='Содержание' )
article_image = models.ImageField(upload_to='blog', blank=True, null=True)
article_user = models.ForeignKey(User, verbose_name='Автор')
article_date = models.DateTimeField(verbose_name='Дата поста')
article_like = models.IntegerField(default=0)
article_status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='d', verbose_name='Статус')
article_published = models.CharField(max_length=50, default= u'Не один пользователь не опублиовал статью', verbose_name='Опубликовал')
article_status_ok = models.BooleanField(default=False, verbose_name='В сети')
article_category = models.ManyToManyField(Category, default='', verbose_name='Категория')
article_tag = models.ManyToManyField(Tag, default='', verbose_name='Теги')
def _unicode_(self):
return self.article_title
class Comments (models.Model):
class Meta:
db_table = 'comments'
comments_text = models.TextField()
comments_articles = models.ForeignKey(Articles)