From dea608ca03981fa5ab6fc1a2a0862b6263e4258d Mon Sep 17 00:00:00 2001 From: Charles Connell Date: Thu, 19 Dec 2013 21:50:07 -0500 Subject: [PATCH] Accept uploaders' email addresses --- karmaworld/apps/document_upload/models.py | 3 +- karmaworld/apps/document_upload/views.py | 9 ++-- karmaworld/apps/notes/models.py | 8 ++-- karmaworld/apps/users/__init__.py | 0 karmaworld/apps/users/models.py | 11 +++++ karmaworld/settings/common.py | 3 +- karmaworld/templates/partial/filepicker.html | 43 ++++++++++++++------ 7 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 karmaworld/apps/users/__init__.py create mode 100644 karmaworld/apps/users/models.py diff --git a/karmaworld/apps/document_upload/models.py b/karmaworld/apps/document_upload/models.py index 876ee41..d44bdd2 100644 --- a/karmaworld/apps/document_upload/models.py +++ b/karmaworld/apps/document_upload/models.py @@ -32,7 +32,8 @@ class RawDocument(Document): slug=self.slug, ip=self.ip, uploaded_at=self.uploaded_at, - fp_file=self.fp_file) + fp_file=self.fp_file, + user=self.user) note.save() for tag in self.tags.all(): note.tags.add(tag) diff --git a/karmaworld/apps/document_upload/views.py b/karmaworld/apps/document_upload/views.py index a72d271..1b25643 100644 --- a/karmaworld/apps/document_upload/views.py +++ b/karmaworld/apps/document_upload/views.py @@ -5,12 +5,9 @@ import datetime from django.http import HttpResponse -from django.views.generic import CreateView -from django.views.generic.edit import ProcessFormView -from django.views.generic.edit import ModelFormMixin - -from karmaworld.apps.document_upload.models import RawDocument from karmaworld.apps.document_upload.forms import RawDocumentForm +from karmaworld.apps.users.models import KarmaUser + def save_fp_upload(request): """ ajax endpoint for saving a FilePicker uploaded file form @@ -27,6 +24,8 @@ def save_fp_upload(request): delta = time_b - time_a raw_document.ip = request.META['REMOTE_ADDR'] raw_document.uploaded_at = datetime.datetime.utcnow() + if request.POST['email'] != '': + raw_document.user = KarmaUser.objects.get_or_create(email=request.POST['email'])[0] time_c = datetime.datetime.now() # note that .save() has the side-effect of kicking of a celery processing task raw_document.save() diff --git a/karmaworld/apps/notes/models.py b/karmaworld/apps/notes/models.py index 47b95c8..db5b356 100644 --- a/karmaworld/apps/notes/models.py +++ b/karmaworld/apps/notes/models.py @@ -21,6 +21,7 @@ from oauth2client.client import Credentials from taggit.managers import TaggableManager from karmaworld.apps.courses.models import Course +from karmaworld.apps.users.models import KarmaUser try: from secrets.drive import GOOGLE_USER @@ -49,8 +50,9 @@ class Document(models.Model): slug = models.SlugField(max_length=255, null=True) # metadata relevant to the Upload process - ip = models.IPAddressField(blank=True, null=True, - help_text=u"IP address of the uploader") + user = models.ForeignKey('users.KarmaUser', null=True) + ip = models.IPAddressField(blank=True, null=True, + help_text=u"IP address of the uploader") uploaded_at = models.DateTimeField(null=True, default=datetime.datetime.utcnow) @@ -60,7 +62,7 @@ class Document(models.Model): fp_file = django_filepicker.models.FPFileField( upload_to=_choose_upload_to, - storage=fs, \ + storage=fs, null=True, blank=True, help_text=u"An uploaded file reference from Filepicker.io") mimetype = models.CharField(max_length=255, blank=True, null=True) diff --git a/karmaworld/apps/users/__init__.py b/karmaworld/apps/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/karmaworld/apps/users/models.py b/karmaworld/apps/users/models.py new file mode 100644 index 0000000..7fb50c3 --- /dev/null +++ b/karmaworld/apps/users/models.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +# -*- coding:utf8 -*- +# Copyright (C) 2013 FinalsClub Foundation + +from django.db import models + +class KarmaUser(models.Model): + email = models.EmailField(blank=False, null=False, unique=True) + + def __unicode__(self): + return u'{e}'.format(e=self.email) diff --git a/karmaworld/settings/common.py b/karmaworld/settings/common.py index e64d4e5..692e3be 100644 --- a/karmaworld/settings/common.py +++ b/karmaworld/settings/common.py @@ -211,8 +211,9 @@ THIRD_PARTY_APPS = ( LOCAL_APPS = ( # file handling app 'karmaworld.apps.notes', - 'karmaworld.apps.courses',\ + 'karmaworld.apps.courses', 'karmaworld.apps.document_upload', + 'karmaworld.apps.users' ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps diff --git a/karmaworld/templates/partial/filepicker.html b/karmaworld/templates/partial/filepicker.html index 615b95d..a09e607 100644 --- a/karmaworld/templates/partial/filepicker.html +++ b/karmaworld/templates/partial/filepicker.html @@ -25,12 +25,12 @@
- @@ -63,9 +63,24 @@
-
-