예제 #1
0
	def import_att_data(self):
		filename = self.doc.file_list.split(',')

		if not filename:
			msgprint("Please attach a .CSV File.")
			raise Exception
		
		if filename[0].find('.csv') < 0:
			raise Exception
		
		if not filename and filename[0] and file[1]:
			msgprint("Please Attach File. ")
			raise Exception
			
		from webnotes.utils import file_manager
		fn, content = file_manager.get_file(filename[1])
 
	# NOTE: Don't know why this condition exists
		if not isinstance(content, basestring) and hasattr(content, 'tostring'):
			content = content.tostring()

		import webnotes.model.import_docs
		im = webnotes.model.import_docs.CSVImport()
		out = im.import_csv(content,self.doc.import_date_format, cint(self.doc.overwrite))
		return out
예제 #2
0
    def attach_file(self, n):
        """attach a file from the `FileData` table"""
        from webnotes.utils.file_manager import get_file
        res = get_file(n)
        if not res:
            return

        self.add_attachment(res[0], res[1])
예제 #3
0
파일: smtp.py 프로젝트: appost/wnframework
	def attach_file(self, n):
		"""attach a file from the `FileData` table"""
		from webnotes.utils.file_manager import get_file		
		res = get_file(n)
		if not res:
			return
	
		self.add_attachment(res[0], res[1])
예제 #4
0
	def get_csv_file_data(self):
		filename = self.doc.file_list.split(',')
		if not filename:
			msgprint("Please Attach File. ", raise_exception=1)
			
		from webnotes.utils import file_manager
		fn, content = file_manager.get_file(filename[1])
		
		if not type(content) == str:
			content = content.tostring()
		return content
예제 #5
0
 def get_csv_file_data(self):
   self.admin_msgprint("get_csv_file_data")
   filename = self.doc.file_list.split(',')
   if not filename and filename[0] and file[1]:
     msgprint("Please Attach File. ")
     raise Exception
     
   from webnotes.utils import file_manager
   fn, content = file_manager.get_file(filename[1])
   
   if not type(content) == str:
     content = content.tostring()
   return content
예제 #6
0
    def get_csv_file_data(self, submit=1):
        """Get csv data"""
        if submit:
            filename = self.doc.file_list.split(',')
            if not filename:
                msgprint("Please Attach File. ", raise_exception=1)

            from webnotes.utils import file_manager
            fn, content = file_manager.get_file(filename[1])
        else:
            content = self.doc.diff_info

        return content
예제 #7
0
def read_csv_content_from_attached_file(doc):
	if not doc.file_list:
		msgprint("File not attached!")
		raise Exception

	try:
		from webnotes.utils.file_manager import get_file
		fid = doc.file_list.split(",")[1]
		fname, fcontent = get_file(fid)
		return read_csv_content(fcontent)
	except Exception, e:
		webnotes.msgprint("""Unable to open attached file. Please try again.""")
		raise Exception
예제 #8
0
	def get_csv_data(self):
		if not self.doc.file_list:
		  msgprint("File not attached!")
		  raise Exception

		fid = self.doc.file_list.split(',')[1]
		  
		try:
			from webnotes.utils import file_manager
			fn, content = file_manager.get_file(fid)
		except Exception, e:
			webnotes.msgprint("Unable to open attached file. Please try again.")
			raise e
예제 #9
0
	def get_csv_file_data(self, submit = 1):
		"""Get csv data"""
		if submit:
			filename = self.doc.file_list.split(',')
			if not filename:
				msgprint("Please Attach File. ", raise_exception=1)
			
			from webnotes.utils import file_manager
			fn, content = file_manager.get_file(filename[1])
		else:
			content = self.doc.diff_info

		return content
예제 #10
0
def read_csv_content_from_attached_file(doc):
	fileid = webnotes.conn.get_value("File Data", {"attached_to_doctype": doc.doctype,
		"attached_to_name":doc.name}, "name")
	if not fileid:
		msgprint("File not attached!")
		raise Exception

	try:
		from webnotes.utils.file_manager import get_file
		fname, fcontent = get_file(fileid)
		return read_csv_content(fcontent, webnotes.form_dict.get('ignore_encoding_errors'))
	except Exception, e:
		webnotes.msgprint("""Unable to open attached file. Please try again.""")
		raise Exception
예제 #11
0
    def get_csv_data(self):
        if not self.doc.file_list:
            msgprint("File not attached!")
            raise Exception

        fid = self.doc.file_list.split(',')[1]

        try:
            from webnotes.utils import file_manager
            fn, content = file_manager.get_file(fid)
        except Exception, e:
            webnotes.msgprint(
                "Unable to open attached file. Please try again.")
            raise e
예제 #12
0
def read_csv_content_from_attached_file(doc):
	fileid = webnotes.conn.get_value("File Data", {"attached_to_doctype": doc.doctype,
		"attached_to_name":doc.name}, "name")
	if not fileid:
		msgprint("File not attached!")
		raise Exception

	try:
		from webnotes.utils.file_manager import get_file
		fname, fcontent = get_file(fileid)
		return read_csv_content(fcontent, webnotes.form_dict.get('ignore_encoding_errors'))
	except Exception, e:
		webnotes.msgprint("""Unable to open attached file. Please try again.""")
		raise Exception
예제 #13
0
	def get_csv_file_data(self):
		"""Get csv data"""
		filename = self.doc.file_list.split(',')
		if not filename:
			msgprint("Please Attach File. ", raise_exception=1)
			
		from webnotes.utils import file_manager
		fn, content = file_manager.get_file(filename[1])
		
		# NOTE: Don't know why this condition exists
		if not isinstance(content, basestring) and hasattr(content, 'tostring'):
		  content = content.tostring()

		return content
예제 #14
0
def read_csv_content_from_attached_file(doc):
    if not doc.file_list:
        msgprint("File not attached!")
        raise Exception

    try:
        from webnotes.utils.file_manager import get_file
        fid = doc.file_list.split(",")[1]
        fname, fcontent = get_file(fid)
        return read_csv_content(fcontent)
    except Exception, e:
        webnotes.msgprint(
            """Unable to open attached file. Please try again.""")
        raise Exception
예제 #15
0
	def get_csv_data(self):
		if not self.doc.file_list:
		  msgprint("File not attached!")
		  raise Exception

		fid = self.doc.file_list.split(',')[1]
		  
		from webnotes.utils import file_manager
		fn, content = file_manager.get_file(fid)
		
		if not type(content) == str:
		  content = content.tostring()

		return content	
예제 #16
0
	def get_csv_data(self):
		if not self.doc.file_list:
		  msgprint("File not attached!")
		  raise Exception

		fid = self.doc.file_list.split(',')[1]
		  
		from webnotes.utils import file_manager
		fn, content = file_manager.get_file(fid)
		
		# NOTE: Don't know why this condition exists
		if not isinstance(content, basestring) and hasattr(content, 'tostring'):
		  content = content.tostring()

		return content
예제 #17
0
	def get_csv_data(self):
		if not self.doc.file_list:
		  msgprint("File not attached!")
		  raise Exception

		fid = self.doc.file_list.split(',')[1]
		  
		from webnotes.utils import file_manager
		fn, content = file_manager.get_file(fid)
		
		# NOTE: Don't know why this condition exists
		if not isinstance(content, basestring) and hasattr(content, 'tostring'):
		  content = content.tostring()

		return content
예제 #18
0
def execute():
	import webnotes
	from webnotes.modules import reload_doc
	reload_doc('stock', 'doctype', 'stock_reconciliation')

	sr = webnotes.conn.sql("select name, file_list from `tabStock Reconciliation` where docstatus = 1")
	for d in sr:
		if d[1]:
			filename = d[1].split(',')[1]
		
			from webnotes.utils import file_manager
			fn, content = file_manager.get_file(filename)
		
			if not isinstance(content, basestring) and hasattr(content, 'tostring'):
				content = content.tostring()

			webnotes.conn.sql("update `tabStock Reconciliation` set diff_info = %s where name = %s and ifnull(diff_info, '') = ''", (content, d[0]))
예제 #19
0
def execute():
	import webnotes
	from webnotes.modules import reload_doc
	reload_doc('stock', 'doctype', 'stock_reconciliation')

	sr = webnotes.conn.sql("select name, file_list from `tabStock Reconciliation` where docstatus = 1")
	for d in sr:
		if d[1]:
			filename = d[1].split(',')[1]
		
			from webnotes.utils import file_manager
			fn, content = file_manager.get_file(filename)
		
			if not isinstance(content, basestring) and hasattr(content, 'tostring'):
				content = content.tostring()

			webnotes.conn.sql("update `tabStock Reconciliation` set diff_info = %s where name = %s and ifnull(diff_info, '') = ''", (content, d[0]))
예제 #20
0
	def attach(self, n):
		"""
		attach a file from the `FileData` table
		"""
		from webnotes.utils.file_manager import get_file		
		res = get_file(n)
		if not res:
			self.msg.attach('Sender tried to attach an unknown file id: ' + n)
	
		from email.mime.audio import MIMEAudio
		from email.mime.base import MIMEBase
		from email.mime.image import MIMEImage
		from email.mime.text import MIMEText
			
		fname = res[0]
		fcontent = res[1]
		
		import mimetypes

		ctype, encoding = mimetypes.guess_type(fname)
		if ctype is None or encoding is not None:
			# No guess could be made, or the file is encoded (compressed), so
			# use a generic bag-of-bits type.
			ctype = 'application/octet-stream'
		
		maintype, subtype = ctype.split('/', 1)
		if maintype == 'text':
			# Note: we should handle calculating the charset
			msg = MIMEText(fcontent, _subtype=subtype)
		elif maintype == 'image':
			msg = MIMEImage(fcontent, _subtype=subtype)
		elif maintype == 'audio':
			msg = MIMEAudio(fcontent, _subtype=subtype)
		else:
			msg = MIMEBase(maintype, subtype)
			msg.set_payload(fcontent)
			# Encode the payload using Base64
			from email import encoders
			encoders.encode_base64(msg)
		# Set the filename parameter
		msg.add_header('Content-Disposition', 'attachment', filename=fname)
		self.msg.attach(msg)
  def import_att_data(self):
    filename = self.doc.file_list.split(',')

    if not filename:
      msgprint("Please attach a .CSV File.")
      raise Exception
    
    if filename[0].find('.csv') < 0:
      raise Exception
    
    if not filename and filename[0] and file[1]:
      msgprint("Please Attach File. ")
      raise Exception
      
    from webnotes.utils import file_manager
    fn, content = file_manager.get_file(filename[1])
    
    if not type(content) == str:
      content = content.tostring()

    import webnotes.model.import_docs
    im = webnotes.model.import_docs.CSVImport()
    out = im.import_csv(content,self.doc.import_date_format, cint(self.doc.overwrite))
    return out
예제 #22
0
	from webnotes.utils.file_manager import get_file

	try:
		fl = webnotes.conn.sql("select name from `tabFile Data` where module=%s", m)
	except Exception, e:
		if e.args[0]==1054: # no field called module
			return
		else:
			raise e
	
	# write the files	
	if fl:
		folder = os.path.join(webnotes.defs.modules_path, m, 'files')
		webnotes.create_folder(folder)
		for f in fl:
			file_det = get_file(f)
			file = open(os.path.join(folder, file_det[0]), 'w+')
			file.write(file_det[1])
			file.close()		
		
	
# ==============================================================================
# write module.info file with last updated timestamp
# ==============================================================================

def write_module_info(mod):
	import webnotes.utils, os

	file = open(os.path.join(get_module_path(mod), 'module.info'), 'w')
	file.write(str({'update_date': webnotes.utils.now()}))
	file.close()