Example #1
0
	def write_to_database(self,m_group_id, m_group_id2, m_title, m_content, m_url, m_level):
		print 'write_to_database'
		'''doc = Documents.objects.filter(url = m_url)
		if (len(doc) == 0):
			doc = Documents(url=m_url, uid=self.uid, title=m_title, level = m_level)
			doc.save()
			print 'create\n'
		else:
			doc[0].uid = self.uid
			doc[0].title = m_title
			# doc.update()
			doc[0].save()
			doc = doc[0]
			print 'update\n'''
		# doc = Documents(title='title', url='url')
		# doc.save()
		# print 'docid is: %s' % str(doc)
		# Delete old records
		res = ResAddr()
		id = res.saveResaddr(m_url, m_level, '', m_title)
		doc = res.getById(id)
		oldContents = Contents.objects.filter(doc = doc)
		oldContents.delete()
		import types
		if type(m_content) is types.ListType:
			for para in m_content:
				# print 'm_content' + para
				con = Contents(group_id=doc.id, group_id2=m_group_id2, doc=doc, paragraph=para, tag='p')
				con.save()
		else:
			con = Contents(group_id=doc.id, group_id2=m_group_id2, doc=doc, paragraph=m_content, tag='p')
			con.save()
		return doc.id
Example #2
0
def searchURLList(request):
    if request.method == 'POST':
        print 'start search...'
        try:
            STOP_LEVEL = 2  # Search to which level
            # https://wiki.wdf.sap.corp/wiki/display/wikitrain/Getting+Started
            uid = request.POST.get('u_id', '')
            pwd = request.POST.get('u_pwd', '')
            tempDocList = []
            completedList = []  # Already searched url list

            for i in range(0, STOP_LEVEL):
                docList = [d.url for d in ResAddr().getObjsByLevel(i)
                           ]  #Documents.objects.filter(level = i)] #
                # docList.append(tempDocList)
                # Remove urls which already searched
                # Add new urls into completed and to do list
                for url in tempDocList:
                    if url in completedList or url in docList:
                        pass
                    else:
                        docList.append(url)
                        completedList.append(url)
                tempDocList = doSearchAction(uid, pwd, docList, i)
        except:
            print '\nsomething error!'
        print 'end search...'
        do_syscmd_reindexer()
        return getURLList(request)
    return ''
Example #3
0
 def addPath(self, request):
     if request.method == 'POST':
         # print request
         s_path = request.POST.get('s_path', '')
         if s_path in [None, '']:
             return self.getURLList(request)
         ResAddr(s_path).save()
     return self.getURLList(request)
Example #4
0
    def write_file_to_database(self, m_group_id, m_group_id2, m_title, m_path,
                               m_url, m_level):
        print 'write_to_database'
        '''doc = Documents.objects.filter(url = m_url)
		if (len(doc) == 0):
			doc = Documents(url=m_url, uid=self.uid, title=m_title, level = m_level)
			doc.save()
			print 'create\n'
		else:
			doc[0].uid = self.uid
			doc[0].title = m_title
			# doc.update()
			doc[0].save()
			doc = doc[0]
			print 'update\n'''
        # doc = Documents(title='title', url='url')
        # doc.save()
        # print 'docid is: %s' % str(doc)
        # Delete old records
        res = ResAddr()
        id = res.saveResaddr(m_url, m_level, '', m_title)
        doc = res.getById(id)
        oldContents = Contents.objects.filter(doc=doc)
        oldContents.delete()
        try:
            print '\n\n\nstart write url:', m_url
            reader = ReadBigFile(m_path, blockSize=1024 * 16)
            block = reader.getNextBlock()

            while (block != None):
                # print 'm_content' + para
                con = Contents(group_id=doc.id,
                               group_id2=m_group_id2,
                               doc=doc,
                               paragraph=unicode(block),
                               tag='p')
                con.save()
                block = reader.getNextBlock()
            os.remove(m_path)
            return doc.id
        except Exception as e:
            print e
            print str(e)
            exit()
            return None
Example #5
0
def deleteURLList(request):
    if request.method == 'POST':
        # print request
        documentId = request.POST.get('d_id', -1)
        print 'documentId=' + str(documentId)
        if documentId == -1:
            return getURLList(request)
        #ResAddr().getById(documentId).delete()
        ResAddr().delById(documentId)
    return getURLList(request)
Example #6
0
    def write_to_database(self, m_group_id, m_group_id2, m_title, m_content,
                          m_url, m_level):
        print 'write_to_database'
        '''doc = Documents.objects.filter(url = m_url)
		if (len(doc) == 0):
			doc = Documents(url=m_url, uid=self.uid, title=m_title, level = m_level)
			doc.save()
			print 'create\n'
		else:
			doc[0].uid = self.uid
			doc[0].title = m_title
			# doc.update()
			doc[0].save()
			doc = doc[0]
			print 'update\n'''
        # doc = Documents(title='title', url='url')
        # doc.save()
        # print 'docid is: %s' % str(doc)
        # Delete old records
        res = ResAddr()
        id = res.saveResaddr(m_url, m_level, '', m_title)
        doc = res.getById(id)
        oldContents = Contents.objects.filter(doc=doc)
        oldContents.delete()
        import types
        if type(m_content) is types.ListType:
            for para in m_content:
                # print 'm_content' + para
                con = Contents(group_id=doc.id,
                               group_id2=m_group_id2,
                               doc=doc,
                               paragraph=para,
                               tag='p')
                con.save()
        else:
            con = Contents(group_id=doc.id,
                           group_id2=m_group_id2,
                           doc=doc,
                           paragraph=m_content,
                           tag='p')
            con.save()
        return doc.id
Example #7
0
	def write_file_to_database(self,m_group_id, m_group_id2, m_title, m_path, m_url, m_level):
		print 'write_to_database'
		'''doc = Documents.objects.filter(url = m_url)
		if (len(doc) == 0):
			doc = Documents(url=m_url, uid=self.uid, title=m_title, level = m_level)
			doc.save()
			print 'create\n'
		else:
			doc[0].uid = self.uid
			doc[0].title = m_title
			# doc.update()
			doc[0].save()
			doc = doc[0]
			print 'update\n'''
		# doc = Documents(title='title', url='url')
		# doc.save()
		# print 'docid is: %s' % str(doc)
		# Delete old records
		res = ResAddr()
		id = res.saveResaddr(m_url, m_level, '', m_title)
		doc = res.getById(id)
		oldContents = Contents.objects.filter(doc = doc)
		oldContents.delete()
		try:
			print '\n\n\nstart write url:', m_url
			reader = ReadBigFile(m_path, blockSize=1024*16)
			block = reader.getNextBlock()

			while(block!=None):
				# print 'm_content' + para
				con = Contents(group_id=doc.id, group_id2=m_group_id2, doc=doc, paragraph=unicode(block), tag='p')
				con.save()
				block = reader.getNextBlock()
			os.remove(m_path)
			return  doc.id
		except Exception as e:
			print e
			print str(e)
			exit()
			return None
Example #8
0
def getURLList(request):
    searchList = ResAddr().getAll()
    return render_to_response('config.html', {'s_list': searchList},
                              context_instance=RequestContext(request))
Example #9
0
 def getPathList(self):
     return ResAddr().getAll()
Example #10
0
 def getURLList(self, request):
     searchList = ResAddr().getAll()
     return render_to_response(self.template_name, {'s_list': searchList},
                               context_instance=RequestContext(request))