# Path: grnglow/settings.py
# QINIU_FILE_PREFIX = 'grnglow'
# QINIU_IMG_URL = ''
# DEBUG = True
# TEMPLATE_DEBUG = DEBUG
# HOME_PAGE_URL = 'http://127.0.0.1:8000/'  # 主页的URL
# PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))  # 项目的根目录地址
# DEFAULT_CHARSET = 'utf-8'
# ADMINS = (
#     # ('Your Name', 'your_email@domain.com'),
# )
# MANAGERS = ADMINS
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(PROJECT_PATH, 'db.sqlite3'),
#     }
# }
# TIME_ZONE = 'Asia/Shanghai'
# LANGUAGE_CODE = 'en-us'
# SITE_ID = 1
# USE_I18N = True
# USE_L10N = True
# MEDIA_ROOT = os.path.join(PROJECT_PATH, 'static')
# MEDIA_PARENT_PATH = PROJECT_PATH.replace('\\', '/')
# PHOTOS_RELATIVE_PATH = '/static/photos/'  # 上传图片保存的目录相对于站点的路径
# UPLOAD_PHOTOS_PATH = (os.path.join(MEDIA_ROOT, 'photos')).replace('\\', '/') + '/'  # 上传图片保存的目录
# UPLOAD_AVATAR_PATH = (os.path.join(MEDIA_ROOT, 'avatars')).replace('\\', '/') + '/'  # 上传头像保存的目录
# AVATAR_RELATIVE_PATH = '/static/avatars/'  # 头像存放位置的相对路径
# DEFAULT_AVATAR_LOC = AVATAR_RELATIVE_PATH + 'avatar_default.gif'
# DEFAULT_AVATAR_SQUARE_LOC = AVATAR_RELATIVE_PATH + 'avatar_default_square.gif'
# MEDIA_URL = HOME_PAGE_URL + 'static/'
# ADMIN_MEDIA_PREFIX = HOME_PAGE_URL + 'static/admin/'
# SECRET_KEY = 'sdfh457aSDG239-ghks2346sdhey235dsfhfdasdt3463w2sdga'
# 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.middleware.csrf.CsrfResponseMiddleware',
#     # 'django.contrib.auth.middleware.AuthenticationMiddleware',
#     # 'django.contrib.messages.middleware.MessageMiddleware',
#     'grnglow.glow.auth.middleware.AuthenticationMiddleware',
#     'django.middleware.locale.LocaleMiddleware',  # 加上这条，让admin支持本地语言
# )
# ROOT_URLCONF = 'grnglow.urls'
# 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.
# )
# INSTALLED_APPS = (
#     # 'django.contrib.auth',
#     # 'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     # 'django.contrib.sites',
#     # 'django.contrib.messages',
#     # Uncomment the next line to enable the admin:
#     # 'django.contrib.admin',
#     # Uncomment the next line to enable admin documentation:
#     # 'django.contrib.admindocs',
#     'grnglow.glow',
#     # 'south',
# )
# 
# Path: grnglow/glow/models/usertag.py
# class UserTag(models.Model):
#     """
#     用户标签的数据模型
#     """
#     user = models.ForeignKey(User)
#     tag = models.ForeignKey(Tag)
#     used_count = models.IntegerField(default=1)
#     created_at = models.DateTimeField(auto_now_add=True)
#         
#     def __unicode__(self):
#         return str(self.id)
#     
#     class Meta:
#         ordering = ['id']
#         app_label = 'glow'


import datetime
import qiniu.io
import qiniu.rs
import math
from StringIO import StringIO
from PIL import Image
from django.db import models
from grnglow import settings
from album import Album
from grnglow.glow.models.usertag import UserTag
from tag import Tag
from user import User
        from grnglow.glow.util import util
        from grnglow.glow.models.comment import Comment
                usertag.delete()
            else:
                t.save()

            if t.used_count <= 0:
                t.delete()
            else:
                usertag.save()
        i = 0
        for t in tag_list:
            t = t.strip()  # 去掉两端的空格
            if t == '' or tag_list.index(t) != i:
                continue  # 空字符串不是标签，存在重复，去掉重复的

            i += 1  # 序号计数

            # 统计标签
            try:
                tt = Tag.objects.get(name=t)
            except Tag.DoesNotExist:
                tt = Tag(name=t)  # 该标签首次出现，创建
            else:
                tt.used_count += 1  # 该标签已存在，增加使用计数

            tt.save()
            self.tags.add(tt)  # 为照片添加标签

            # 为该用户添加使用的标签
            try:
                usertag = UserTag.objects.get(user=self.owner, tag=tt)

# Path: grnglow/settings.py
# QINIU_FILE_PREFIX = 'grnglow'
# QINIU_IMG_URL = ''
# DEBUG = True
# TEMPLATE_DEBUG = DEBUG
# HOME_PAGE_URL = 'http://127.0.0.1:8000/'  # 主页的URL
# PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))  # 项目的根目录地址
# DEFAULT_CHARSET = 'utf-8'
# ADMINS = (
#     # ('Your Name', 'your_email@domain.com'),
# )
# MANAGERS = ADMINS
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(PROJECT_PATH, 'db.sqlite3'),
#     }
# }
# TIME_ZONE = 'Asia/Shanghai'
# LANGUAGE_CODE = 'en-us'
# SITE_ID = 1
# USE_I18N = True
# USE_L10N = True
# MEDIA_ROOT = os.path.join(PROJECT_PATH, 'static')
# MEDIA_PARENT_PATH = PROJECT_PATH.replace('\\', '/')
# PHOTOS_RELATIVE_PATH = '/static/photos/'  # 上传图片保存的目录相对于站点的路径
# UPLOAD_PHOTOS_PATH = (os.path.join(MEDIA_ROOT, 'photos')).replace('\\', '/') + '/'  # 上传图片保存的目录
# UPLOAD_AVATAR_PATH = (os.path.join(MEDIA_ROOT, 'avatars')).replace('\\', '/') + '/'  # 上传头像保存的目录
# AVATAR_RELATIVE_PATH = '/static/avatars/'  # 头像存放位置的相对路径
# DEFAULT_AVATAR_LOC = AVATAR_RELATIVE_PATH + 'avatar_default.gif'
# DEFAULT_AVATAR_SQUARE_LOC = AVATAR_RELATIVE_PATH + 'avatar_default_square.gif'
# MEDIA_URL = HOME_PAGE_URL + 'static/'
# ADMIN_MEDIA_PREFIX = HOME_PAGE_URL + 'static/admin/'
# SECRET_KEY = 'sdfh457aSDG239-ghks2346sdhey235dsfhfdasdt3463w2sdga'
# 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.middleware.csrf.CsrfResponseMiddleware',
#     # 'django.contrib.auth.middleware.AuthenticationMiddleware',
#     # 'django.contrib.messages.middleware.MessageMiddleware',
#     'grnglow.glow.auth.middleware.AuthenticationMiddleware',
#     'django.middleware.locale.LocaleMiddleware',  # 加上这条，让admin支持本地语言
# )
# ROOT_URLCONF = 'grnglow.urls'
# 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.
# )
# INSTALLED_APPS = (
#     # 'django.contrib.auth',
#     # 'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     # 'django.contrib.sites',
#     # 'django.contrib.messages',
#     # Uncomment the next line to enable the admin:
#     # 'django.contrib.admin',
#     # Uncomment the next line to enable admin documentation:
#     # 'django.contrib.admindocs',
#     'grnglow.glow',
#     # 'south',
# )
# 
# Path: grnglow/glow/models/usertag.py
# class UserTag(models.Model):
#     """
#     用户标签的数据模型
#     """
#     user = models.ForeignKey(User)
#     tag = models.ForeignKey(Tag)
#     used_count = models.IntegerField(default=1)
#     created_at = models.DateTimeField(auto_now_add=True)
#         
#     def __unicode__(self):
#         return str(self.id)
#     
#     class Meta:
#         ordering = ['id']
#         app_label = 'glow'


# Path: grnglow/glow/models/photo.py
import datetime
import qiniu.io
import qiniu.rs
import math
from StringIO import StringIO
from PIL import Image
from django.db import models
from grnglow import settings
from album import Album
from grnglow.glow.models.usertag import UserTag
from tag import Tag
from user import User
        from grnglow.glow.util import util
        from grnglow.glow.models.comment import Comment

                usertag.delete()
            else:
                t.save()

            if t.used_count <= 0:
                t.delete()
            else:
                usertag.save()
        i = 0
        for t in tag_list:
            t = t.strip()  # 去掉两端的空格
            if t == '' or tag_list.index(t) != i:
                continue  # 空字符串不是标签，存在重复，去掉重复的

            i += 1  # 序号计数

            # 统计标签
            try:
                tt = Tag.objects.get(name=t)
            except Tag.DoesNotExist:
                tt = Tag(name=t)  # 该标签首次出现，创建
            else:
                tt.used_count += 1  # 该标签已存在，增加使用计数

            tt.save()
            self.tags.add(tt)  # 为照片添加标签

            # 为该用户添加使用的标签
            try:
                usertag = UserTag.objects.get(user=self.owner, tag=tt)

            except UserTag.DoesNotExist: