Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session_data in django3.2 #17

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN rm -f /usr/bin/python && \
ln -s /usr/local/bin/pip3.6 /usr/bin/pip && \
ln -s /usr/local/bin/pip3.6 /usr/bin/pip3

RUN pip3 install uvicorn pillow sqlalchemy==1.4.6 pymysql future requests redis \
RUN pip3 install uvicorn pillow sqlalchemy==1.4.6 pymysql future requests redis django==3.2.* \
-i https://mirrors.aliyun.com/pypi/simple && rm -r /root/.cache/pip


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pymysql
future # seaf-server
requests
redis
django==3.2.*

# psd_tools
# moviepy
11 changes: 7 additions & 4 deletions seatable_thumbnail/serializers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import uuid
import json
import base64
import mimetypes
from datetime import datetime
from email.utils import formatdate
from django.contrib.sessions.backends.db import SessionStore
from django.conf import settings as dj_settings

import seatable_thumbnail.settings as settings
from seatable_thumbnail.constants import TEXT_CONTENT_TYPE, FILE_EXT_TYPE_MAP, \
Expand All @@ -13,6 +14,10 @@
from seatable_thumbnail.utils import get_file_id, get_file_obj


dj_settings.configure(SECRET_KEY=settings.DTABLE_WEB_SECRET_KEY)
session_store = SessionStore()


class ThumbnailSerializer(object):
def __init__(self, db_session, request):
self.db_session = db_session
Expand All @@ -34,9 +39,7 @@ def gen_thumbnail_info(self):

def parse_django_session(self, session_data):
# django/contrib/sessions/backends/base.py
encoded_data = base64.b64decode(session_data.encode('ascii'))
hash_key, serialized = encoded_data.split(b':', 1)
return json.loads(serialized.decode('latin-1'))
return session_store.decode(session_data)

def session_check(self):
session_key = self.request.cookies[settings.SESSION_KEY]
Expand Down
2 changes: 2 additions & 0 deletions seatable_thumbnail/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# session key
SESSION_KEY = 'sessionid'

DTABLE_WEB_SECRET_KEY = ''


# url
URL_PREFIX = '/'
Expand Down