note.tags.add(tag)
return note
- def save(self, user=None, session_key=None, *args, **kwargs):
+ def save(self, user=None, session=None, *args, **kwargs):
super(RawDocument, self).save(*args, **kwargs)
if not self.is_processed:
- tasks.process_raw_document.delay(self, user, session_key)
+ tasks.process_raw_document.delay(self, user, session)
auto_add_check_unique_together(RawDocument)
logger = get_task_logger(__name__)
@task()
-def process_raw_document(raw_document, user, session_key):
+def process_raw_document(raw_document, user, session):
""" Process a RawDocument instance in to a Note instance """
try:
- convert_raw_document(raw_document, user=user, session_key=session_key)
+ convert_raw_document(raw_document, user=user, session=session)
except:
logger.error(traceback.format_exc())
self.course.save()
self.client = Client()
- def doConversionForPost(self, post, user=None, session_key=None):
+ def doConversionForPost(self, post, user=None, session=None):
self.assertEqual(Note.objects.count(), 0)
r_d_f = RawDocumentForm(post)
self.assertTrue(r_d_f.is_valid())
raw_document = r_d_f.save(commit=False)
raw_document.fp_file = post['fp_file']
- convert_raw_document(raw_document, user=user, session_key=session_key)
+ convert_raw_document(raw_document, user=user, session_key=session)
self.assertEqual(Note.objects.count(), 1)
def testPlaintextConversion(self):
'name': 'graph3.txt',
'tags': '',
'mimetype': 'text/plain'},
- session_key=s.session_key)
+ session=s)
note = Note.objects.all()[0]
self.assertEqual(note.user, user)
'name': 'graph3.txt',
'tags': '',
'mimetype': 'text/plain'},
- session_key=s.session_key)
+ session=s)
user = User(username=TEST_USERNAME)
user.save()
if request.user.is_authenticated():
raw_document.save(user=request.user)
else:
- raw_document.save(session_key=request.session.session_key)
+ # Generate session key if it doesn't exist
+ if not request.session.get('has_session'):
+ request.session['has_session'] = True
+ request.session.save()
+ raw_document.save(session=request.session)
# save the tags to the database, too. don't forget those guys.
r_d_f.save_m2m()
import re
import json
import time
+from django.contrib.auth import SESSION_KEY
import httplib2
from apiclient.discovery import build
UPLOADED_NOTES_SESSION_KEY = 'uploaded_notes'
+
def extract_file_details(fileobj):
details = None
year = None
return file_dict
-def convert_raw_document(raw_document, user=None, session_key=None):
+def convert_raw_document(raw_document, user=None, session=None):
""" Upload a raw document to google drive and get a Note back"""
fp_file = raw_document.get_file()
# Finally, save whatever data we got back from google
note.save()
- if session_key and not user:
- s = SessionStore(session_key=session_key)
+ if session and not user:
# If the person who uploaded this made an
# account or signed in while convert_raw_document
# was running, associate their account with this note
try:
- uid = s['_auth_user_id']
+ uid = session[SESSION_KEY]
user = User.objects.get(pk=uid)
note.user = user
note.save()
# so if the uploader later creates an account,
# we can find notes they uploaded
except (KeyError, ObjectDoesNotExist):
- uploaded_notes = s.get(UPLOADED_NOTES_SESSION_KEY, [])
+ uploaded_notes = session.get(UPLOADED_NOTES_SESSION_KEY, [])
uploaded_notes.append(note.id)
- s[UPLOADED_NOTES_SESSION_KEY] = uploaded_notes
- s.save()
+ session[UPLOADED_NOTES_SESSION_KEY] = uploaded_notes
+ session.modified = True
+ session.save()
########## SESSION CONFIGURATION
+SESSION_ENGINE = 'django.contrib.sessions.backends.db'
SESSION_COOKIE_AGE = 63072000 # 2 years in seconds
########## END SESSION CONFIGURATION