def setUp(self): # create base values to test db representations self.now = datetime.datetime.utcnow() # create a school to satisfy course requirements self.school = School() self.school.name = 'Marshall College' self.school.save() # create a course to test relationships self.course = Course() self.course.school = self.school self.course.name = u'Archaeology 101' self.course.save() # override Course.save() appending an ID to the slug self.course.slug = u'archaeology-101' self.course.save() # create a note to test against self.note = Note() self.note.course = self.course self.note.name = u"Lecture notes concerning the use of therefore ∴" self.note.category = Note.LECTURE_NOTES self.note.uploaded_at = self.now self.note.text = "This is the plaintext version of a note. It's pretty cool. Alpaca." self.note.save()
def setup(self): # create base values to test db representations self.now = datetime.datetime.utcnow() # create a school to satisfy course requirements self.school = School() self.school.name = 'Marshall College' self.school.save() # create a course to test relationships self.course = Course() self.course.school = self.school self.course.name = u'Archaeology 101' self.course.save() # override Course.save() appending an ID to the slug self.course.slug = u'archaeology-101' self.course.save() # create a note to test against self.note = Note() self.note.course = self.course self.note.name = u"Lecture notes concerning the use of therefore ∴" #self.note.slug := do not set for test_remake_slug() behavior self.note.file_type = 'doc' self.note.uploaded_at = self.now self.note.save()
def upload_complete(self, request, filename, upload): path = settings.MEDIA_URL + "/" + filename self._dest.close() self._dir = settings.MEDIA_ROOT # Avoid File.objects.create, as this will try to make # Another file copy at FileField's 'upload_to' dir print "creating note" note = Note() note.name = filename note.note_file = os.path.join(self._dir, filename) note.course_id = request.GET['course_id'] note.draft = True # Pending approval from user print "saving note" note.save() # FIXME: Make get or create print "setting up session vars" #import ipdb; ipdb.set_trace() if 'uploaded_files' in request.session: request.session['uploaded_files'].append(note.pk) else: request.session['uploaded_files'] = [note.pk] # Asynchronously process document with Google Documents API print "upload_complete, firing task" tasks.process_document.delay(note) return {'note_url': note.get_absolute_url()}
def setUp(self): # create base values to test db representations self.now = datetime.datetime.utcnow() # create a school to satisfy course requirements self.school = School() self.school.name = 'Marshall College' self.school.save() # create a course to test relationships self.course = Course() self.course.school = self.school self.course.name = u'Archaeology 101' self.course.save() # override Course.save() appending an ID to the slug self.course.slug = u'archaeology-101' self.course.save() self.user1 = User(username='******') self.user1.save() self.user2 = User(username='******') self.user2.save() # create a note to test against self.note = Note() self.note.course = self.course self.note.name = u"Lecture notes concerning the use of therefore ∴" self.note.text = "This is the plaintext version of a note. It's pretty cool." self.note.user = self.user1 self.note.save() self.request1 = HttpRequest() self.request1.user = self.user1 self.request1.method = 'POST' self.request1.META = {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'} self.request1.session = SessionStore() self.request2 = HttpRequest() self.request2.user = self.user2 self.request2.method = 'POST' self.request2.META = {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'} self.request2.session = SessionStore()
def convert_to_note(self): """ polymorph this object into a note.models.Note object """ # TODO move this to Note. superclasses should not care about subclasses, # but subclasses should care about parents. # Note inherits all fields of Document as does RawDocument. # Dynamically refer to all fields of RawDocument found within Document # and also Note. initdict = {} for field in Document._meta.get_all_field_names(): if field in ('tags', ): # TaggableManager does not play well with init() continue initdict[field] = getattr(self, field) # Create a new Note using all fields from the Document note = Note(**initdict) note.save() for tag in self.tags.all(): note.tags.add(tag) return note