Example #1
0
    def on_update(self):
        if getattr(self, "tree_image", None):
            webnotes.conn.set_in_doc(
                self.doc, "tree_image",
                save_file(self.doc.name + "-tree.jpg", self.tree_image,
                          self.doc.doctype, self.doc.name).file_name)

        if getattr(self, "leaf_image", None):
            webnotes.conn.set_in_doc(
                self.doc, "leaf_image",
                save_file(self.doc.name + "-leaf.jpg", self.leaf_image,
                          self.doc.doctype, self.doc.name).file_name)
Example #2
0
def update_profile_name(args):
    if args.get("email"):
        args['name'] = args.get("email")
        webnotes.flags.mute_emails = True
        webnotes.bean({
            "doctype": "Profile",
            "email": args.get("email"),
            "first_name": args.get("first_name"),
            "last_name": args.get("last_name")
        }).insert()
        webnotes.flags.mute_emails = False
        from webnotes.auth import _update_password
        _update_password(args.get("email"), args.get("password"))

    else:
        args['name'] = webnotes.session.user

        # Update Profile
        if not args.get('last_name') or args.get('last_name') == 'None':
            args['last_name'] = None
        webnotes.conn.sql(
            """update `tabProfile` SET first_name=%(first_name)s,
			last_name=%(last_name)s WHERE name=%(name)s""", args)

    if args.get("attach_profile"):
        filename, filetype, content = args.get("attach_profile").split(",")
        fileurl = save_file(filename,
                            content,
                            "Profile",
                            args.get("name"),
                            decode=True).file_name
        webnotes.conn.set_value("Profile", args.get("name"), "user_image",
                                fileurl)

    add_all_roles_to(args.get("name"))
Example #3
0
	def save_attachments_in_doc(self, doc):
		from webnotes.utils.file_manager import save_file, add_file_list, MaxFileSizeReachedError
		for attachment in self.attachments:
			try:
				fid = save_file(attachment['filename'], attachment['content'])
				status = add_file_list(doc.doctype, doc.name, fid, fid)
			except MaxFileSizeReachedError:
				# bypass max file size exception
				pass
Example #4
0
def create_items(args):
	for i in xrange(1,6):
		item = args.get("item_" + str(i))
		if item:
			item_group = args.get("item_group_" + str(i))
			webnotes.bean({
				"doctype":"Item",
				"item_code": item,
				"item_name": item,
				"description": item,
				"is_sales_item": "Yes",
				"is_stock_item": item_group!="Services" and "Yes" or "No",
				"item_group": item_group,
				"stock_uom": args.get("item_uom_" + str(i)),
				"default_warehouse": item_group!="Service" and ("Finished Goods - " + args.get("company_abbr")) or ""
			}).insert()
			
			if args.get("item_img_" + str(i)):
				filename, filetype, content = args.get("item_img_" + str(i)).split(",")
				fileurl = save_file(filename, content, "Item", item, decode=True).file_name
				webnotes.conn.set_value("Item", item, "image", fileurl)
					
	for i in xrange(1,6):
		item = args.get("item_buy_" + str(i))
		if item:
			item_group = args.get("item_buy_group_" + str(i))
			webnotes.bean({
				"doctype":"Item",
				"item_code": item,
				"item_name": item,
				"description": item,
				"is_sales_item": "No",
				"is_stock_item": item_group!="Services" and "Yes" or "No",
				"item_group": item_group,
				"stock_uom": args.get("item_buy_uom_" + str(i)),
				"default_warehouse": item_group!="Service" and ("Stores - " + args.get("company_abbr")) or ""
			}).insert()
			
			if args.get("item_img_" + str(i)):
				filename, filetype, content = args.get("item_img_" + str(i)).split(",")
				fileurl = save_file(filename, content, "Item", item, decode=True).file_name
				webnotes.conn.set_value("Item", item, "image", fileurl)
Example #5
0
def create_letter_head(args):
	if args.get("attach_letterhead"):
		lh = webnotes.bean({
			"doctype":"Letter Head",
			"letter_head_name": "Standard",
			"is_default": 1
		}).insert()
		
		filename, filetype, content = args.get("attach_letterhead").split(",")
		fileurl = save_file(filename, content, "Letter Head", "Standard", decode=True).file_name
		webnotes.conn.set_value("Letter Head", "Standard", "content", "<img src='%s' style='max-width: 100%%;'>" % fileurl)
Example #6
0
 def save_attachments_in_doc(self, doc):
     from webnotes.utils.file_manager import save_file, MaxFileSizeReachedError
     for attachment in self.attachments:
         try:
             fid = save_file(attachment['filename'], attachment['content'],
                             doc.doctype, doc.name)
         except MaxFileSizeReachedError:
             # WARNING: bypass max file size exception
             pass
         except webnotes.DuplicateEntryError:
             # same file attached twice??
             pass
Example #7
0
	def save_attachments(self, doc, attachment_list=[]):
		"""
			Saves attachments from email

			attachment_list is a list of dict containing:
			'filename', 'content', 'content-type'
		"""
		from webnotes.utils.file_manager import save_file, add_file_list
		for attachment in attachment_list:
			fid = save_file(attachment['filename'], attachment['content'], 'Support')
			status = add_file_list('Support Ticket', doc.name, attachment['filename'], fid)
			if not status:
				doc.description = doc.description \
					+ "\nCould not attach: " + cstr(attachment['filename'])
				doc.save()