def create_topics(self,extuser=False,username='******'): if not extuser: extuser = self.create_user(username, groups = ('Program Manager',)) topic1 = Topic( user=extuser.user, name='Topic1', category='Outline', topic_slug='UNIQUEVL', ) topic2 = Topic( user=extuser.user, name='Topic2', category='Outline', topic_slug='OTHER', ) topic1.save() topic2.save() document1 = Document( location='fakepath', name='Document1 A Document Name XCVF', fileName='fakepath/doc.docx', size=200, topic=topic1, ) document1.save() document2 = Document( location='fakepath', name='Document2 A Document Name XCVF', fileName='fakepath/doc.docx', size=200, topic=topic1, ) document2.save() topic1.documents.add(document1,document2) document3 = Document( location='fakepath', name='Document3 A Document Name XCVF', fileName='fakepath/doc.docx', size=200, topic=topic2, ) document4 = Document( location='fakepath', name='Document4 A Document Name XCVF', fileName='fakepath/doc.docx', size=200, topic=topic2, ) document3.save() document4.save() topic2.documents.add(document3,document4)
def addtopic(request): context= { 'title':'Add Topic', } #Check for POST data. if request.method == 'POST': topicform = TopicForm(request.POST) if topicform.is_valid(): #Get the topic post data topic_name = request.POST['name'] topic_description = request.POST['description'] topic_category = request.POST['category'] topic_user = request.user topic_slug = generate_topic_slug() #Create a new topic and save it. topic = Topic( name=topic_name, description=topic_description, user=topic_user, category=topic_category, topic_slug = topic_slug ) topic.save() #Create a new directory for the topic. directory = create_directory(topic,settings.UPLOADED_TOPIC_DIR) #Get the files files = request.FILES #Thesea re the names of hte files. for name,f in files.iteritems(): #Single file upload #Get the file name = f.name fileName = "%s-%s" % (uuid4(),name) #The uploaded_topic_dir is in PDTtool.settings. location = '%s/%s' % (directory, fileName) #Handle the filesize. fileSize = f.size #Load a new uploaded file and save it. uploadedfile = Document(topic=topic, location = location, name=name, fileName=fileName, size=fileSize) uploadedfile.save() #Save the file on to the directory. handle_uploaded_file(f,location) topic.documents.add(uploadedfile) #Return the redirect. return redirect('/viewtopic/?publicid=%s#added' % topic.publicid) else: #Create an unbound post data. topicform = TopicForm #Make a context variable # for the topicform. context['topicform'] = topicform return render(request, 'topic_management/addtopic.html', context)