# Path: dzhops/settings.py
# BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SECRET_KEY = '2vuicou20ne9t&h)#c2!7sz4cc+6hcfxfmy!4agjs7@7-$nddq'
# DEBUG = True
# TEMPLATE_DEBUG = True
# ALLOWED_HOSTS = []
# SESSION_SAVE_EVERY_REQUEST = True
# SESSION_EXPIRE_AT_BROWSER_CLOSE = True
# INSTALLED_APPS = (
#     'django.contrib.admin',
#     'django.contrib.auth',
#     'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     'django.contrib.messages',
#     'django.contrib.staticfiles',
#     'index',
#     'dzhops',
#     'hostlist',
#     'replacedata',
#     'saltstack',
#     'record',
#     'newtest',
# )
# MIDDLEWARE_CLASSES = (
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.locale.LocaleMiddleware',
#     'django.middleware.common.CommonMiddleware',
#     'django.middleware.csrf.CsrfViewMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.messages.middleware.MessageMiddleware',
#     'django.middleware.clickjacking.XFrameOptionsMiddleware',
# )
# ROOT_URLCONF = 'dzhops.urls'
# WSGI_APPLICATION = 'dzhops.wsgi.application'
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.mysql',
#         'NAME': 'dzhops',
#         'USER': 'dzhops',
#         'PORT': 33066,
#         'HOST': 'db-dev.dzh-inc.com',
#         'PASSWORD': 'dzhops',
#     }
# }
# LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'Asia/Shanghai'
# USE_I18N = True
# USE_L10N = True
# USE_TZ = False
# STATICFILES_DIRS = (
#     BASE_DIR + '/static',
# )
# STATIC_URL = '/static/'
# TEMPLATE_DIRS = (
#     os.path.join(BASE_DIR, 'templates'),
# )
# SALT_API = {
#     'url': 'http://10.15.201.102:18000/',
#     'user': 'zhaogb',
#     'password': 'zhaogb'
# }
# LOGGING = {
#     'version': 1,
#     'disable_existing_loggers': True,
#     'formatters': {
#         'standard': {
#             'format': '%(asctime)s %(levelname)s %(module)s %(funcName)s %(lineno)d %(message)s'
#         },
#         'simple': {
#             'format': '%(levelname)s %(message)s'
#         },
#     },
#     'filters': {
#         'require_debug_false': {
#             '()': 'django.utils.log.RequireDebugFalse'
#         },
#     },
#     'handlers': {
#         'mail_admins': {
#             'level': 'ERROR',
#             'filters': ['require_debug_false'],
#             'class': 'django.utils.log.AdminEmailHandler'
#         },
#         'log_handler': {
#             'level': 'DEBUG',
#             'class': 'logging.handlers.RotatingFileHandler',
#             'filename': os.path.join(BASE_DIR, 'log', 'dzhops.log'),
#             'formatter': 'standard',
#         },
#     },
#     'loggers': {
#         'django.request': {
#             'handlers': ['mail_admins'],
#             'level': 'ERROR',
#             'propagate': True,
#         },
#         'dzhops': {
#             'handlers': ['log_handler'],
#             'level': 'DEBUG',
#             'propagate': False
#         },
#     }
# }


from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate
from dzhops import settings
from index.models import MiniKeys, ProcStatus, ServStatus
from index.forms import ChangePasswordForms, UploadFileForm
from record.models import OperateRecord
import Image
import os
import shutil
import logging
    try:
        standard_size = (58, 58)
        file_type = '.jpg'
        user_pic_list = [username, file_type]
        log.debug(str(user_pic_list))
        user_pic_str = ''.join(user_pic_list)
        log.debug('37')
        log.debug('user_pic_path: %s' % str(settings.STATICFILES_DIRS))
        user_pic_path = os.path.join(settings.STATICFILES_DIRS[0], 'img', user_pic_str)
        im = Image.open(img)
        im_new = im.resize(standard_size, Image.ANTIALIAS)
        im_new.save(user_pic_path, 'JPEG', quality=100)
        log.info('The user pic resize successed')
        try:
            all_static = settings.STATIC_ROOT
            all_static_url = os.path.join(all_static, 'img')
        except AttributeError, e:
            all_static_url = ''
            log.info('The config settings.py no STATIC_ROOT attribute')
        if all_static_url and os.path.exists(all_static_url):
            shutil.copy(user_pic_path, all_static_url)
            log.info('The user picture copy to all_static_url')
        else:
            log.debug('The all_static_url is None or do not exist')
    except Exception, e:
        log.error(str(e))


def handle_uploaded_file(f, filename):
    picname = '%s.jpg' % filename

# Path: dzhops/settings.py
# BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SECRET_KEY = '2vuicou20ne9t&h)#c2!7sz4cc+6hcfxfmy!4agjs7@7-$nddq'
# DEBUG = True
# TEMPLATE_DEBUG = True
# ALLOWED_HOSTS = []
# SESSION_SAVE_EVERY_REQUEST = True
# SESSION_EXPIRE_AT_BROWSER_CLOSE = True
# INSTALLED_APPS = (
#     'django.contrib.admin',
#     'django.contrib.auth',
#     'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     'django.contrib.messages',
#     'django.contrib.staticfiles',
#     'index',
#     'dzhops',
#     'hostlist',
#     'replacedata',
#     'saltstack',
#     'record',
#     'newtest',
# )
# MIDDLEWARE_CLASSES = (
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.locale.LocaleMiddleware',
#     'django.middleware.common.CommonMiddleware',
#     'django.middleware.csrf.CsrfViewMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.messages.middleware.MessageMiddleware',
#     'django.middleware.clickjacking.XFrameOptionsMiddleware',
# )
# ROOT_URLCONF = 'dzhops.urls'
# WSGI_APPLICATION = 'dzhops.wsgi.application'
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.mysql',
#         'NAME': 'dzhops',
#         'USER': 'dzhops',
#         'PORT': 33066,
#         'HOST': 'db-dev.dzh-inc.com',
#         'PASSWORD': 'dzhops',
#     }
# }
# LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'Asia/Shanghai'
# USE_I18N = True
# USE_L10N = True
# USE_TZ = False
# STATICFILES_DIRS = (
#     BASE_DIR + '/static',
# )
# STATIC_URL = '/static/'
# TEMPLATE_DIRS = (
#     os.path.join(BASE_DIR, 'templates'),
# )
# SALT_API = {
#     'url': 'http://10.15.201.102:18000/',
#     'user': 'zhaogb',
#     'password': 'zhaogb'
# }
# LOGGING = {
#     'version': 1,
#     'disable_existing_loggers': True,
#     'formatters': {
#         'standard': {
#             'format': '%(asctime)s %(levelname)s %(module)s %(funcName)s %(lineno)d %(message)s'
#         },
#         'simple': {
#             'format': '%(levelname)s %(message)s'
#         },
#     },
#     'filters': {
#         'require_debug_false': {
#             '()': 'django.utils.log.RequireDebugFalse'
#         },
#     },
#     'handlers': {
#         'mail_admins': {
#             'level': 'ERROR',
#             'filters': ['require_debug_false'],
#             'class': 'django.utils.log.AdminEmailHandler'
#         },
#         'log_handler': {
#             'level': 'DEBUG',
#             'class': 'logging.handlers.RotatingFileHandler',
#             'filename': os.path.join(BASE_DIR, 'log', 'dzhops.log'),
#             'formatter': 'standard',
#         },
#     },
#     'loggers': {
#         'django.request': {
#             'handlers': ['mail_admins'],
#             'level': 'ERROR',
#             'propagate': True,
#         },
#         'dzhops': {
#             'handlers': ['log_handler'],
#             'level': 'DEBUG',
#             'propagate': False
#         },
#     }
# }


# Path: index/views.py
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate
from dzhops import settings
from index.models import MiniKeys, ProcStatus, ServStatus
from index.forms import ChangePasswordForms, UploadFileForm
from record.models import OperateRecord
import Image
import os
import shutil
import logging

    try:
        standard_size = (58, 58)
        file_type = '.jpg'
        user_pic_list = [username, file_type]
        log.debug(str(user_pic_list))
        user_pic_str = ''.join(user_pic_list)
        log.debug('37')
        log.debug('user_pic_path: %s' % str(settings.STATICFILES_DIRS))
        user_pic_path = os.path.join(settings.STATICFILES_DIRS[0], 'img', user_pic_str)
        im = Image.open(img)
        im_new = im.resize(standard_size, Image.ANTIALIAS)
        im_new.save(user_pic_path, 'JPEG', quality=100)
        log.info('The user pic resize successed')
        try:
            all_static = settings.STATIC_ROOT
            all_static_url = os.path.join(all_static, 'img')
        except AttributeError, e:
            all_static_url = ''
            log.info('The config settings.py no STATIC_ROOT attribute')
        if all_static_url and os.path.exists(all_static_url):
            shutil.copy(user_pic_path, all_static_url)
            log.info('The user picture copy to all_static_url')
        else:
            log.debug('The all_static_url is None or do not exist')
    except Exception, e:
        log.error(str(e))


def handle_uploaded_file(f, filename):
    picname = '%s.jpg' % filename

    filepath = os.path.join(settings.STATICFILES_DIRS[0], 'img', picname)