@@ -5,6 +5,7 @@ from __future__ import division  | 
            ||
| 5 | 5 | 
                import os  | 
            
| 6 | 6 | 
                import random  | 
            
| 7 | 7 | 
                 | 
            
| 8 | 
                +import records  | 
            |
| 8 | 9 | 
                import shortuuid  | 
            
| 9 | 10 | 
                from curtail_uuid import CurtailUUID  | 
            
| 10 | 11 | 
                from django.conf import settings  | 
            
                @@ -34,6 +35,7 @@ from utils.thumbnail_utils import make_thumbnail  | 
            ||
| 34 | 35 | 
                from utils.url_utils import img_url, share_url  | 
            
| 35 | 36 | 
                 | 
            
| 36 | 37 | 
                 | 
            
| 38 | 
                +db = records.Database(settings.DATABASE_URL['default'])  | 
            |
| 37 | 39 | 
                r = settings.REDIS_CACHE  | 
            
| 38 | 40 | 
                 | 
            
| 39 | 41 | 
                 | 
            
                @@ -884,45 +886,62 @@ def pai2_home_api(request):  | 
            ||
| 884 | 886 | 
                     num = int(request.POST.get('num', settings.PAI2_HOME_PER_PAGE))
               | 
            
| 885 | 887 | 
                 | 
            
| 886 | 888 | 
                # 执行原生 SQL 语句,获取首页照片列表  | 
            
| 887 | 
                - cursor = connection.cursor()  | 
            |
| 888 | 
                - cursor.execute(PAI2_HOME_API.format(  | 
            |
| 889 | 
                + # cursor = connection.cursor()  | 
            |
| 890 | 
                + # cursor.execute(PAI2_HOME_API.format(  | 
            |
| 891 | 
                + # user_id=user_id,  | 
            |
| 892 | 
                + # offset=0,  | 
            |
| 893 | 
                + # rows=settings.PAI2_HOME_MAX_ROWS,  | 
            |
| 894 | 
                + # ))  | 
            |
| 895 | 
                + # rows = cursor.fetchall  | 
            |
| 896 | 
                +  | 
            |
| 897 | 
                + # 使用 records 执行原生 SQL 语句,获取首页照片列表  | 
            |
| 898 | 
                + rows = db.query(PAI2_HOME_API.format(  | 
            |
| 889 | 899 | 
                user_id=user_id,  | 
            
| 890 | 900 | 
                offset=0,  | 
            
| 891 | 901 | 
                rows=settings.PAI2_HOME_MAX_ROWS,  | 
            
| 892 | 
                - ))  | 
            |
| 893 | 
                - rows = cursor.fetchall()  | 
            |
| 902 | 
                + )).all()  | 
            |
| 894 | 903 | 
                 | 
            
| 895 | 904 | 
                # 首页照片分页  | 
            
| 896 | 905 | 
                rows, left = pagination(rows, page, num)  | 
            
| 897 | 906 | 
                 | 
            
| 898 | 907 | 
                # 首页照片信息  | 
            
| 899 | 
                -    rows = [{
               | 
            |
| 900 | 
                - 'group_id': row[0],  | 
            |
| 901 | 
                - 'group_name': row[1],  | 
            |
| 902 | 
                - 'group_default_avatar': row[2],  | 
            |
| 903 | 
                - 'group_avatar': row[3],  | 
            |
| 904 | 
                - 'group_from': row[4],  | 
            |
| 905 | 
                - 'photo_id': row[5],  | 
            |
| 906 | 
                - 'photo_url': img_url(row[6]),  | 
            |
| 907 | 
                - 'photo_w': row[7],  | 
            |
| 908 | 
                - 'photo_h': row[8],  | 
            |
| 909 | 
                - 'photo_thumbnail_url': img_url(row[9]),  | 
            |
| 910 | 
                - 'photo_thumbnail_w': row[10],  | 
            |
| 911 | 
                - 'photo_thumbnail_h': row[11],  | 
            |
| 912 | 
                - 'photo_thumbnail2_url': img_url(row[12]),  | 
            |
| 913 | 
                - 'photo_thumbnail2_w': row[13],  | 
            |
| 914 | 
                - 'photo_thumbnail2_h': row[14],  | 
            |
| 915 | 
                - 'photo_share_url': share_url(row[5]), # Warning: Index of This Line is 5  | 
            |
| 916 | 
                - 'user_id': row[15],  | 
            |
| 917 | 
                - 'nickname': row[16],  | 
            |
| 918 | 
                - 'avatar': row[17],  | 
            |
| 919 | 
                - 'comment_num': row[18],  | 
            |
| 920 | 
                - 'thumbup_num': row[19],  | 
            |
| 921 | 
                - 'photo_from': row[20],  | 
            |
| 922 | 
                - 'created_at': row[21],  | 
            |
| 923 | 
                - } for row in rows]  | 
            |
| 924 | 
                -  | 
            |
| 908 | 
                +    # rows = [{
               | 
            |
| 909 | 
                + # 'group_id': row[0],  | 
            |
| 910 | 
                + # 'group_name': row[1],  | 
            |
| 911 | 
                + # 'group_default_avatar': row[2],  | 
            |
| 912 | 
                + # 'group_avatar': row[3],  | 
            |
| 913 | 
                + # 'group_from': row[4],  | 
            |
| 914 | 
                + # 'photo_id': row[5],  | 
            |
| 915 | 
                + # 'photo_url': img_url(row[6]),  | 
            |
| 916 | 
                + # 'photo_w': row[7],  | 
            |
| 917 | 
                + # 'photo_h': row[8],  | 
            |
| 918 | 
                + # 'photo_thumbnail_url': img_url(row[9]),  | 
            |
| 919 | 
                + # 'photo_thumbnail_w': row[10],  | 
            |
| 920 | 
                + # 'photo_thumbnail_h': row[11],  | 
            |
| 921 | 
                + # 'photo_thumbnail2_url': img_url(row[12]),  | 
            |
| 922 | 
                + # 'photo_thumbnail2_w': row[13],  | 
            |
| 923 | 
                + # 'photo_thumbnail2_h': row[14],  | 
            |
| 924 | 
                + # 'photo_share_url': share_url(row[5]), # Warning: Index of This Line is 5  | 
            |
| 925 | 
                + # 'user_id': row[15],  | 
            |
| 926 | 
                + # 'nickname': row[16],  | 
            |
| 927 | 
                + # 'avatar': row[17],  | 
            |
| 928 | 
                + # 'comment_num': row[18],  | 
            |
| 929 | 
                + # 'thumbup_num': row[19],  | 
            |
| 930 | 
                + # 'photo_from': row[20],  | 
            |
| 931 | 
                + # 'created_at': row[21],  | 
            |
| 932 | 
                + # } for row in rows]  | 
            |
| 933 | 
                +  | 
            |
| 934 | 
                +    # [row.update({
               | 
            |
| 935 | 
                + # 'thumbup': get_group_photo_thumbup_flag(row['photo_id'], user_id),  | 
            |
| 936 | 
                +    #     'porder': get_lensman_order_record(row['photo_id'], user_id) if row['photo_from'] == GroupPhotoInfo.SESSION_GROUP else {}
               | 
            |
| 937 | 
                + # }) for row in rows]  | 
            |
| 938 | 
                +  | 
            |
| 939 | 
                + rows = [dict(row) for row in rows]  | 
            |
| 925 | 940 | 
                     [row.update({
               | 
            
| 941 | 
                + 'photo_url': img_url(row['photo_path']),  | 
            |
| 942 | 
                + 'photo_thumbnail_url': img_url(row['photo_thumbnail_path']),  | 
            |
| 943 | 
                + 'photo_thumbnail2_url': img_url(row['photo_thumbnail2_path']),  | 
            |
| 944 | 
                + 'photo_share_url': share_url(row['photo_id']),  | 
            |
| 926 | 945 | 
                'thumbup': get_group_photo_thumbup_flag(row['photo_id'], user_id),  | 
            
| 927 | 946 | 
                         'porder': get_lensman_order_record(row['photo_id'], user_id) if row['photo_from'] == GroupPhotoInfo.SESSION_GROUP else {}
               | 
            
| 928 | 947 | 
                }) for row in rows]  | 
            
                @@ -961,7 +980,7 @@ def lensman_photo_price(request):  | 
            ||
| 961 | 980 | 
                else:  | 
            
| 962 | 981 | 
                # 获取摄影师定价  | 
            
| 963 | 982 | 
                # TODO, 此处需要完整的摄影师定价  | 
            
| 964 | 
                - price = 999 if photo_type == 'origin' else 666  | 
            |
| 983 | 
                + price = 999 if photo_type == 'origin' else 299  | 
            |
| 965 | 984 | 
                 | 
            
| 966 | 985 | 
                r.set(lensman_photo_price_key, price)  | 
            
| 967 | 986 | 
                 | 
            
                @@ -130,6 +130,31 @@ DATABASES = {
               | 
            ||
| 130 | 130 | 
                }  | 
            
| 131 | 131 | 
                }  | 
            
| 132 | 132 | 
                 | 
            
| 133 | 
                +SCHEMES = {
               | 
            |
| 134 | 
                + 'django.db.backends.postgresql_psycopg2': 'postgres',  | 
            |
| 135 | 
                + 'django.db.backends.postgresql_psycopg2': 'postgresql',  | 
            |
| 136 | 
                + 'django.db.backends.postgresql_psycopg2': 'pgsql',  | 
            |
| 137 | 
                + 'django.contrib.gis.db.backends.postgis': 'postgis',  | 
            |
| 138 | 
                + 'django.db.backends.mysql': 'mysql',  | 
            |
| 139 | 
                + # 'django.db.backends.mysql': 'mysql2',  | 
            |
| 140 | 
                + 'django.contrib.gis.db.backends.mysql': 'mysqlgis',  | 
            |
| 141 | 
                + 'mysql.connector.django': 'mysql-connector',  | 
            |
| 142 | 
                + 'django.contrib.gis.db.backends.spatialite': 'spatialite',  | 
            |
| 143 | 
                + 'django.db.backends.sqlite3': 'sqlite',  | 
            |
| 144 | 
                + 'django.db.backends.oracle': 'oracle',  | 
            |
| 145 | 
                + 'django.contrib.gis.db.backends.oracle': 'oraclegis',  | 
            |
| 146 | 
                +}  | 
            |
| 147 | 
                +  | 
            |
| 148 | 
                +DATABASE_URL = {
               | 
            |
| 149 | 
                +    k: '{scheme}://{user}:{password}@{host}:{port}/{name}'.format(
               | 
            |
| 150 | 
                +        scheme=SCHEMES[v.get('ENGINE', '')],
               | 
            |
| 151 | 
                +        user=v.get('USER', 'root'),
               | 
            |
| 152 | 
                +        password=v.get('PASSWORD', ''),
               | 
            |
| 153 | 
                +        host=v.get('HOST', 'localhost'),
               | 
            |
| 154 | 
                +        port=v.get('PORT', 6039),
               | 
            |
| 155 | 
                +        name=v.get('NAME', '')
               | 
            |
| 156 | 
                + ) for k, v in DATABASES.iteritems()  | 
            |
| 157 | 
                +}  | 
            |
| 133 | 158 | 
                 | 
            
| 134 | 159 | 
                # Internationalization  | 
            
| 135 | 160 | 
                # https://docs.djangoproject.com/en/1.8/topics/i18n/  | 
            
                @@ -15,6 +15,7 @@ kkconst==1.1.2  | 
            ||
| 15 | 15 | 
                pep8==1.6.2  | 
            
| 16 | 16 | 
                pillow==2.9.0  | 
            
| 17 | 17 | 
                pytz==2015.7  | 
            
| 18 | 
                +records==0.4.3  | 
            |
| 18 | 19 | 
                redis==2.10.5  | 
            
| 19 | 20 | 
                shortuuid==0.4.2  | 
            
| 20 | 21 | 
                uWSGI==2.0.11.1  | 
            
                @@ -2,8 +2,8 @@  | 
            ||
| 2 | 2 | 
                 | 
            
| 3 | 3 | 
                PAI2_HOME_API = (  | 
            
| 4 | 4 | 
                r"select "  | 
            
| 5 | 
                - r"T1.group_id, T2.group_name, T2.group_default_avatar, T2.group_avatar, T2.group_from, T3.id, T3.photo_path, "  | 
            |
| 6 | 
                - r"T3.photo_w, T3.photo_h, T3.photo_thumbnail_path, T3.photo_thumbnail_w, T3.photo_thumbnail_h, "  | 
            |
| 5 | 
                + r"T1.group_id, T2.group_name, T2.group_default_avatar, T2.group_avatar, T2.group_from, T3.id as photo_id, "  | 
            |
| 6 | 
                + r"T3.photo_path, T3.photo_w, T3.photo_h, T3.photo_thumbnail_path, T3.photo_thumbnail_w, T3.photo_thumbnail_h, "  | 
            |
| 7 | 7 | 
                r"T3.photo_thumbnail2_path, T3.photo_thumbnail2_w, T3.photo_thumbnail2_h, T3.user_id, T3.nickname, T3.avatar, "  | 
            
| 8 | 8 | 
                r"T3.comment_num, T3.thumbup_num, T3.photo_from, T3.created_at "  | 
            
| 9 | 9 | 
                     r"from (select * from group_groupuserinfo where user_id='{user_id}' and user_status=1) as T1 "
               |