Exemplo n.º 1
0
	def on_update(self):
		clear_unit_views(self.doc.unit)

		if self.doc.assigned_to and self.doc.assigned_to != self.assigned_to \
			and webnotes.session.user != self.doc.assigned_to:
			
			# send assignment email
			sendmail(recipients=[self.doc.assigned_to], 
				subject="You have been assigned this Task by {}".format(get_fullname(self.doc.modified_by)),
				msg=self.get_reply_email_message(get_fullname(self.doc.owner)))
Exemplo n.º 2
0
	def on_update(self):
		clear_cache(website_group=self.doc.website_group)
		clear_post_cache(self.doc.parent_post or self.doc.name)

		if self.doc.assigned_to and self.doc.assigned_to != self.assigned_to \
			and webnotes.session.user != self.doc.assigned_to:
			
			# send assignment email
			sendmail(recipients=[self.doc.assigned_to], 
				subject="You have been assigned this Task by {}".format(get_fullname(self.doc.modified_by)),
				msg=self.get_reply_email_message(self.doc.name, get_fullname(self.doc.owner)))
Exemplo n.º 3
0
def notify(arg=None):
	from webnotes.utils import cstr, get_fullname, get_url
	
	webnotes.sendmail(\
		recipients=[webnotes.conn.get_value("Profile", arg["contact"], "email") or arg["contact"]],
		sender= webnotes.conn.get_value("Profile", webnotes.session.user, "email"),
		subject="New Message from " + get_fullname(webnotes.user.name),
		message=webnotes.get_template("templates/emails/new_message.html").render({
			"from": get_fullname(webnotes.user.name),
			"message": arg['txt'],
			"link": get_url()
		})
	)	
Exemplo n.º 4
0
    def get_context(self):
        import webnotes.utils
        import markdown2

        # this is for double precaution. usually it wont reach this code if not published
        if not webnotes.utils.cint(self.doc.published):
            raise Exception, "This blog has not been published yet!"

        # temp fields
        from webnotes.utils import global_date_format, get_fullname
        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.published_on)

        if self.doc.blogger:
            self.doc.blogger_info = webnotes.doc("Blogger",
                                                 self.doc.blogger).fields

        self.doc.description = self.doc.blog_intro or self.doc.content[:140]
        self.doc.meta_description = self.doc.description

        self.doc.categories = webnotes.conn.sql_list(
            "select name from `tabBlog Category` order by name")

        self.doc.comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog Post"
			and comment_docname=%s order by creation""",
                                                  self.doc.name,
                                                  as_dict=1) or []
Exemplo n.º 5
0
    def prepare_template_args(self):
        import webnotes.utils

        # this is for double precaution. usually it wont reach this code if not published
        if not webnotes.utils.cint(self.doc.published):
            raise Exception, "This blog has not been published yet!"

            # temp fields
        from webnotes.utils import global_date_format, get_fullname

        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.creation)

        self.markdown_to_html(["content"])

        comment_list = webnotes.conn.sql(
            """\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog"
			and comment_docname=%s order by creation""",
            self.doc.name,
            as_dict=1,
        )

        self.doc.comment_list = comment_list or []
        for comment in self.doc.comment_list:
            comment["comment_date"] = webnotes.utils.global_date_format(comment["creation"])
Exemplo n.º 6
0
def get_blog_list(args=None):
	"""
		args = {
			'start': 0,
		}
	"""
	import webnotes
	
	if not args: args = webnotes.form_dict
	
	query = """\
		select
			name, page_name, content, owner, creation as creation,
			title, (select count(name) from `tabComment` where
				comment_doctype='Blog' and comment_docname=`tabBlog`.name) as comments
		from `tabBlog`
		where ifnull(published,0)=1
		order by creation desc, name asc
		limit %s, 5""" % args.start
		
	result = webnotes.conn.sql(query, args, as_dict=1)

	# strip html tags from content
	import webnotes.utils
	
	for res in result:
		from webnotes.utils import global_date_format, get_fullname
		res['full_name'] = get_fullname(res['owner'])
		res['published'] = global_date_format(res['creation'])
		if not res['content']:
			res['content'] = website.utils.get_html(res['page_name'])
		res['content'] = split_blog_content(res['content'])

	return result
Exemplo n.º 7
0
	def prepare_template_args(self):
		import webnotes.utils
		
		# this is for double precaution. usually it wont reach this code if not published
		if not webnotes.utils.cint(self.doc.published):
			raise Exception, "This blog has not been published yet!"
		
		# temp fields
		from webnotes.utils import global_date_format, get_fullname
		self.doc.full_name = get_fullname(self.doc.owner)
		self.doc.updated = global_date_format(self.doc.published_on)
		self.doc.content_html = self.doc.content
		if self.doc.blogger:
			self.doc.blogger_info = webnotes.doc("Blogger", self.doc.blogger).fields
		
		self.doc.description = self.doc.blog_intro or self.doc.content[:140]
		
		self.doc.categories = webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
		
		self.doc.texts = {
			"comments": _("Comments"),
			"first_comment": _("Be the first one to comment"),
			"add_comment": _("Add Comment"),
			"submit": _("Submit"),
			"all_posts_by": _("All posts by"),
		}

		comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog Post"
			and comment_docname=%s order by creation""", self.doc.name, as_dict=1)
		
		self.doc.comment_list = comment_list or []
		for comment in self.doc.comment_list:
			comment['comment_date'] = webnotes.utils.global_date_format(comment['creation'])
Exemplo n.º 8
0
def get_context():
	post_name = webnotes.request.path[1:].split("/")[1]
	post = webnotes.bean("Post", post_name).doc
	
	access = get_access(post.unit)
	if not access.get("read"):
		return {
			"name": "Not Permitted",
			"title": "Not Permitted",
			"post_list_html": "<div class='text-muted'>You are not permitted to view this page</div>",
			"not_permitted": True
		}
	
	fullname = get_fullname(post.owner)
	title = "{post} by {fullname}".format(unit=post.unit, post="Post", fullname=fullname)
	unit = webnotes.bean("Unit", post.unit).doc
	parents = webnotes.conn.sql("""select name, unit_title from tabUnit 
		where lft <= %s and rgt >= %s order by lft asc""", (unit.lft, unit.rgt), as_dict=1)
	
	return {
		"name": post.unit,
		"title": title,
		"parent_post_html": get_parent_post_html(post, access),
		"post_list_html": get_child_posts_html(post),
		"parents": parents,
		"parent_post": post.name
	}
Exemplo n.º 9
0
    def validate_leave_approver(self):
        employee = webnotes.bean("Employee", self.doc.employee)
        leave_approvers = [l.leave_approver for l in employee.doclist.get({"parentfield": "employee_leave_approvers"})]

        if len(leave_approvers) and self.doc.leave_approver not in leave_approvers:
            msgprint(
                (
                    "["
                    + _("For Employee")
                    + ' "'
                    + self.doc.employee
                    + '"] '
                    + _("Leave Approver can be one of")
                    + ": "
                    + comma_or(leave_approvers)
                ),
                raise_exception=InvalidLeaveApproverError,
            )

        elif self.doc.leave_approver and not webnotes.conn.sql(
            """select name from `tabUserRole` 
			where parent=%s and role='Leave Approver'""",
            self.doc.leave_approver,
        ):
            msgprint(
                get_fullname(self.doc.leave_approver) + ": " + _("does not have role 'Leave Approver'"),
                raise_exception=InvalidLeaveApproverError,
            )
Exemplo n.º 10
0
    def prepare_template_args(self):
        import webnotes.utils

        # this is for double precaution. usually it wont reach this code if not published
        if not webnotes.utils.cint(self.doc.published):
            raise Exception, "This blog has not been published yet!"

        # temp fields
        from webnotes.utils import global_date_format, get_fullname
        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.creation)

        self.markdown_to_html(['content'])

        comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog"
			and comment_docname=%s order by creation""",
                                         self.doc.name,
                                         as_dict=1)

        self.doc.comment_list = comment_list or []
        for comment in self.doc.comment_list:
            comment['comment_date'] = webnotes.utils.global_date_format(
                comment['creation'])
Exemplo n.º 11
0
def make_feed(feedtype, doctype, name, owner, subject, color):
	"makes a new Feed record"
	#msgprint(subject)
	from webnotes.model.doc import Document
	from webnotes.utils import get_fullname

	if feedtype in ('Login', 'Comment', 'Assignment'):
		# delete old login, comment feed
		webnotes.conn.sql("""delete from tabFeed where 
			datediff(curdate(), creation) > 7 and doc_type in ('Comment', 'Login', 'Assignment')""")
	else:
		# one feed per item
		webnotes.conn.sql("""delete from tabFeed
			where doc_type=%s and doc_name=%s 
			and ifnull(feed_type,'') != 'Comment'""", (doctype, name))

	f = Document('Feed')
	f.owner = owner
	f.feed_type = feedtype
	f.doc_type = doctype
	f.doc_name = name
	f.subject = subject
	f.color = color
	f.full_name = get_fullname(owner)
	f.save()
Exemplo n.º 12
0
def get_lead_or_customer():
    customer = webnotes.conn.get_value("Contact",
                                       {"email_id": webnotes.session.user},
                                       "customer")
    if customer:
        return webnotes.doc("Customer", customer)

    lead = webnotes.conn.get_value("Lead", {"email_id": webnotes.session.user})
    if lead:
        return webnotes.doc("Lead", lead)
    else:
        lead_bean = webnotes.bean({
            "doctype":
            "Lead",
            "email_id":
            webnotes.session.user,
            "lead_name":
            get_fullname(webnotes.session.user),
            "territory":
            guess_territory(),
            "status":
            "Open"  # TODO: set something better???
        })

        if webnotes.session.user != "Guest":
            lead_bean.ignore_permissions = True
            lead_bean.insert()

        return lead_bean.doc
Exemplo n.º 13
0
	def validate(self):
		"""write/update 'Page' with the blog"""		
		p = website.utils.add_page(self.doc.title)
		self.doc.name = p.name
		
		from jinja2 import Template
		import markdown2
		import os
		from webnotes.utils import global_date_format, get_fullname
		
		self.doc.content_html = markdown2.markdown(self.doc.content or '')
		self.doc.full_name = get_fullname(self.doc.owner)
		self.doc.updated = global_date_format(self.doc.modified)
		
		with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
			p.content = Template(f.read()).render(doc=self.doc)
		
		with open(os.path.join(os.path.dirname(__file__), 'blog_page.js'), 'r') as f:
			p.script = Template(f.read()).render(doc=self.doc)
				
		p.save()
		
		website.utils.add_guest_access_to_page(p.name)
		
		# cleanup
		for f in ['content_html', 'full_name', 'updated']:
			if f in self.doc.fields:
				del self.doc.fields[f]
Exemplo n.º 14
0
def get_blog_list(args=None):
    """
		args = {
			'start': 0,
		}
	"""
    import webnotes

    if not args: args = webnotes.form_dict

    query = """\
		select
			name, page_name, content, owner, creation as creation,
			title, (select count(name) from `tabComment` where
				comment_doctype='Blog' and comment_docname=`tabBlog`.name) as comments
		from `tabBlog`
		where ifnull(published,0)=1
		order by creation desc, name asc
		limit %s, 5""" % args.start

    result = webnotes.conn.sql(query, args, as_dict=1)

    # strip html tags from content
    import webnotes.utils

    for res in result:
        from webnotes.utils import global_date_format, get_fullname
        res['full_name'] = get_fullname(res['owner'])
        res['published'] = global_date_format(res['creation'])
        if not res['content']:
            res['content'] = website.utils.get_html(res['page_name'])
        res['content'] = split_blog_content(res['content'])

    return result
Exemplo n.º 15
0
def make_feed(feedtype, doctype, name, owner, subject, color):
    "makes a new Feed record"
    #msgprint(subject)
    from webnotes.model.doc import Document
    from webnotes.utils import get_fullname

    if feedtype in ('Login', 'Comment', 'Assignment'):
        # delete old login, comment feed
        webnotes.conn.sql("""delete from tabFeed where 
			datediff(curdate(), creation) > 7 and doc_type in ('Comment', 'Login', 'Assignment')"""
                          )
    else:
        # one feed per item
        webnotes.conn.sql(
            """delete from tabFeed
			where doc_type=%s and doc_name=%s 
			and ifnull(feed_type,'') != 'Comment'""", (doctype, name))

    f = Document('Feed')
    f.owner = owner
    f.feed_type = feedtype
    f.doc_type = doctype
    f.doc_name = name
    f.subject = subject
    f.color = color
    f.full_name = get_fullname(owner)
    f.save()
Exemplo n.º 16
0
	def get_context(self):
		import webnotes.utils
		import markdown2
		
		# this is for double precaution. usually it wont reach this code if not published
		if not webnotes.utils.cint(self.doc.published):
			raise Exception, "This blog has not been published yet!"
		
		# temp fields
		from webnotes.utils import global_date_format, get_fullname
		self.doc.full_name = get_fullname(self.doc.owner)
		self.doc.updated = global_date_format(self.doc.published_on)
		
		if self.doc.blogger:
			self.doc.blogger_info = webnotes.doc("Blogger", self.doc.blogger).fields
		
		self.doc.description = self.doc.blog_intro or self.doc.content[:140]
		self.doc.meta_description = self.doc.description
		
		self.doc.categories = webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
		
		self.doc.comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog Post"
			and comment_docname=%s order by creation""", self.doc.name, as_dict=1) or []
Exemplo n.º 17
0
def assign_post(post, profile=None):
	post = webnotes.bean("Post", post)

	if not get_access(post.doc.unit).get("write"):
		raise webnotes.PermissionError("You are not allowed edit this post")
	
	if profile and not get_access(post.doc.unit, profile).get("write"):
		raise webnotes.PermissionError("Selected user does not have 'write' access to this post")
		
	if profile and post.doc.assigned_to:
		webnotes.throw("Someone is already assigned to this post. Please refresh.")
		
	if not profile and post.doc.status == "Completed":
		webnotes.throw("You cannot revoke assignment of a completed task.")
		
	post.doc.status = "Assigned" if profile else None
	
	post.doc.assigned_to = profile
	post.doc.assigned_to_fullname = get_fullname(profile) if profile else None
	
	post.ignore_permissions = True
	post.save()
	
	return {
		"post_settings_html": get_post_settings(post.doc.unit, post.doc.name),
		"assigned_to_fullname": post.doc.assigned_to_fullname,
		"status": post.doc.status
	}
Exemplo n.º 18
0
def add():
	"""add in someone's to do list"""
	if webnotes.conn.sql("""select owner from `tabToDo Item`
		where reference_type=%(doctype)s and reference_name=%(name)s
		and owner=%(assign_to)s""", webnotes.form_dict):
		webnotes.msgprint("Already in todo")
		return
	else:
		from webnotes.model.doc import Document
		from webnotes.utils import nowdate
		
		d = Document("ToDo Item")
		d.owner = webnotes.form_dict['assign_to']
		d.reference_type = webnotes.form_dict['doctype']
		d.reference_name = webnotes.form_dict['name']
		d.description = webnotes.form_dict['description']
		d.priority = webnotes.form_dict.get('priority', 'Medium')
		d.date = webnotes.form_dict.get('date', nowdate())
		d.assigned_by = webnotes.user.name
		d.save(1)

	# notify
	notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', notify=webnotes.form_dict.get('notify'))
		
	# update feeed
	try:
		import home
		from webnotes.utils import get_fullname
		home.make_feed('Assignment', d.reference_type, d.reference_name, webnotes.session['user'],
			'[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)), '#C78F58')
	except ImportError, e:
		pass
Exemplo n.º 19
0
	def _get_post_context():
		fullname = get_fullname(post.owner)
		return {
			"title": "{} by {}".format(post.title, fullname),
			# "group_title": group_context.get("unit_title") + " by {}".format(fullname),
			"parent_post_html": get_parent_post_html(post, group_context.get("view")),
			"post_list_html": get_child_posts_html(post, group_context.get("view")),
			"parent_post": post.name
		}
Exemplo n.º 20
0
def add(args=None):
	"""add in someone's to do list"""
	if not args:
		args = webnotes.local.form_dict
		
	if webnotes.conn.sql("""select owner from `tabToDo`
		where reference_type=%(doctype)s and reference_name=%(name)s and status="Open"
		and owner=%(assign_to)s""", args):
		webnotes.msgprint("Already in todo", raise_exception=True)
		return
	else:
		from webnotes.utils import nowdate
		
		d = webnotes.bean({
			"doctype":"ToDo",
			"owner": args['assign_to'],
			"reference_type": args['doctype'],
			"reference_name": args['name'],
			"description": args.get('description'),
			"priority": args.get("priority", "Medium"),
			"status": "Open",
			"date": args.get('date', nowdate()),
			"assigned_by": args.get('assigned_by', webnotes.user.name),
		}).insert(ignore_permissions=True).doc
		
		# set assigned_to if field exists
		from webnotes.model.meta import has_field
		if has_field(args['doctype'], "assigned_to"):
			webnotes.conn.set_value(args['doctype'], args['name'], "assigned_to", args['assign_to'])
			
	try:
		if cint(args.get("restrict")):
			from webnotes.core.page.user_properties import user_properties
			user_properties.add(args['assign_to'], args['doctype'], args['name'])
			webnotes.msgprint(_("Restriction added"))
	except webnotes.PermissionError:
		webnotes.throw("{cannot}: {user}, {_for}: {doctype} {_and}: {name}".format(cannot=_("You cannot restrict User"), 
			user=args['assign_to'], _for=_("for DocType"), doctype=_(args['doctype']), _and=_("and Name"),
			name=args['name']))

	# notify
	if not args.get("no_notification"):
		notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', description=args.get("description"), notify=args.get('notify'))
		
	# update feeed
	try:
		from erpnext.home import make_feed
		from webnotes.utils import get_fullname
		make_feed('Assignment', d.reference_type, d.reference_name, webnotes.session['user'],
			'[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)), '#C78F58')
	except ImportError, e:
		pass
Exemplo n.º 21
0
def add(args=None):
    """add in someone's to do list"""
    if not args:
        args = webnotes.form_dict

    if webnotes.conn.sql(
            """select owner from `tabToDo`
		where reference_type=%(doctype)s and reference_name=%(name)s
		and owner=%(assign_to)s""", args):
        webnotes.msgprint("Already in todo", raise_exception=True)
        return
    else:
        from webnotes.model.doc import Document
        from webnotes.utils import nowdate

        d = Document("ToDo")
        d.owner = args['assign_to']
        d.reference_type = args['doctype']
        d.reference_name = args['name']
        d.description = args.get('description')
        d.priority = args.get('priority', 'Medium')
        d.date = args.get('date', nowdate())
        d.assigned_by = args.get('assigned_by', webnotes.user.name)
        d.save(1)

        # set assigned_to if field exists
        from webnotes.model.meta import has_field
        if has_field(args['doctype'], "assigned_to"):
            webnotes.conn.set_value(args['doctype'], args['name'],
                                    "assigned_to", args['assign_to'])

    # notify
    if not args.get("no_notification"):
        notify_assignment(d.assigned_by,
                          d.owner,
                          d.reference_type,
                          d.reference_name,
                          action='ASSIGN',
                          description=args.get("description"),
                          notify=args.get('notify'))

    # update feeed
    try:
        import home
        from webnotes.utils import get_fullname
        home.make_feed(
            'Assignment', d.reference_type, d.reference_name,
            webnotes.session['user'],
            '[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)),
            '#C78F58')
    except ImportError, e:
        pass
Exemplo n.º 22
0
	def validate_leave_approver(self):
		employee = webnotes.bean("Employee", self.doc.employee)
		leave_approvers = [l.leave_approver for l in 
			employee.doclist.get({"parentfield": "employee_leave_approvers"})]

		if len(leave_approvers) and self.doc.leave_approver not in leave_approvers:
			msgprint(("[" + _("For Employee") + ' "' + self.doc.employee + '"] ' 
				+ _("Leave Approver can be one of") + ": "
				+ comma_or(leave_approvers)), raise_exception=InvalidLeaveApproverError)
		
		elif self.doc.leave_approver and not webnotes.conn.sql("""select name from `tabUserRole` 
			where parent=%s and role='Leave Approver'""", self.doc.leave_approver):
				msgprint(get_fullname(self.doc.leave_approver) + ": " \
					+ _("does not have role 'Leave Approver'"), raise_exception=InvalidLeaveApproverError)
def move_remarks_to_comments():
	from webnotes.utils import get_fullname
	result = webnotes.conn.sql("""select name, remark, modified_by from `tabStock Reconciliation`
		where ifnull(remark, '')!=''""")
	fullname_map = {}
	for reco, remark, modified_by in result:
		webnotes.bean([{
			"doctype": "Comment",
			"comment": remark,
			"comment_by": modified_by,
			"comment_by_fullname": fullname_map.setdefault(modified_by, get_fullname(modified_by)),
			"comment_doctype": "Stock Reconciliation",
			"comment_docname": reco
		}]).insert()
Exemplo n.º 24
0
	def send_email_on_reply(self):
		owner_fullname = get_fullname(self.doc.owner)
		
		parent_post = webnotes.bean("Post", self.doc.parent_post).doc
		
		message = self.get_reply_email_message(owner_fullname)
		
		# send email to the owner of the post, if he/she is different
		if parent_post.owner != self.doc.owner:
			send(recipients=[parent_post.owner], 
				subject="{someone} replied to your post".format(someone=owner_fullname), 
				message=message,
			
				# to allow unsubscribe
				doctype='Profile', 
				email_field='name', 
				
				# for tracking sent status
				ref_doctype=self.doc.doctype, ref_docname=self.doc.name)
		
		# send email to members who part of the conversation
		recipients = webnotes.conn.sql_list("""select owner from `tabPost`
			where parent_post=%s and owner not in (%s, %s)""", 
			(self.doc.parent_post, parent_post.owner, self.doc.owner))
		
		send(recipients=recipients, 
			subject="{someone} replied to a post by {other}".format(someone=owner_fullname, 
				other=get_fullname(parent_post.owner)), 
			message=message,
		
			# to allow unsubscribe
			doctype='Profile', 
			email_field='name', 
			
			# for tracking sent status
			ref_doctype=self.doc.doctype, ref_docname=self.doc.name)
Exemplo n.º 25
0
    def prepare_template_args(self):
        import webnotes.utils
        import markdown2

        # this is for double precaution. usually it wont reach this code if not published
        if not webnotes.utils.cint(self.doc.published):
            raise Exception, "This blog has not been published yet!"

        # temp fields
        from webnotes.utils import global_date_format, get_fullname
        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.published_on)
        self.doc.content_html = self.doc.content

        if self.doc.blogger:
            self.doc.blogger_info = webnotes.doc("Blogger",
                                                 self.doc.blogger).fields

        self.doc.description = self.doc.blog_intro or self.doc.content[:140]
        self.doc.meta_description = self.doc.description

        self.doc.categories = webnotes.conn.sql_list(
            "select name from `tabBlog Category` order by name")

        self.doc.texts = {
            "comments": _("Comments"),
            "first_comment": _("Be the first one to comment"),
            "add_comment": _("Add Comment"),
            "submit": _("Submit"),
            "all_posts_by": _("All posts by"),
        }

        comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog Post"
			and comment_docname=%s order by creation""",
                                         self.doc.name,
                                         as_dict=1)

        self.doc.comment_list = comment_list or []
        for comment in self.doc.comment_list:
            comment['comment_date'] = webnotes.utils.global_date_format(
                comment['creation'])
            comment['comment'] = markdown2.markdown(comment['comment'])
Exemplo n.º 26
0
def add(args=None):
	"""add in someone's to do list"""
	if not args:
		args = webnotes.local.form_dict
		
	if webnotes.conn.sql("""select owner from `tabToDo`
		where reference_type=%(doctype)s and reference_name=%(name)s
		and owner=%(assign_to)s""", args):
		webnotes.msgprint("Already in todo", raise_exception=True)
		return
	else:
		from webnotes.model.doc import Document
		from webnotes.utils import nowdate
		
		d = Document("ToDo")
		d.owner = args['assign_to']
		d.reference_type = args['doctype']
		d.reference_name = args['name']
		d.description = args.get('description')
		d.priority = args.get('priority', 'Medium')
		d.date = args.get('date', nowdate())
		d.assigned_by = args.get('assigned_by', webnotes.user.name)
		d.save(1)
		
		if args['doctype']=='Opportunity':
			update_assign_to(args)
		
		# set assigned_to if field exists
		from webnotes.model.meta import has_field
		if has_field(args['doctype'], "assigned_to"):
			webnotes.conn.set_value(args['doctype'], args['name'], "assigned_to", args['assign_to'])

	# notify
	if not args.get("no_notification"):
		notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', description=args.get("description"), notify=args.get('notify'))
		
	# update feeed
	try:
		import home
		from webnotes.utils import get_fullname
		home.make_feed('Assignment', d.reference_type, d.reference_name, webnotes.session['user'],
			'[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)), '#C78F58')
	except ImportError, e:
		pass
Exemplo n.º 27
0
    def validate(self):
        """write/update 'Page' with the blog"""
        # we need the name for the templates
        if not self.doc.name:
            self.autoname()

        if self.doc.page_name:
            webnotes.conn.sql("""delete from tabPage where name=%s""",
                              self.doc.page_name)

        p = website.utils.add_page(self.doc.title)

        from jinja2 import Template
        import markdown2
        import os
        from webnotes.utils import global_date_format, get_fullname
        from webnotes.model.code import get_obj

        self.doc.content_html = unicode(
            markdown2.markdown(self.doc.content or ''))
        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.modified)

        with open(os.path.join(os.path.dirname(__file__), 'template.html'),
                  'r') as f:
            p.content = Template(f.read()).render(doc=self.doc)

        with open(os.path.join(os.path.dirname(__file__), 'blog_page.js'),
                  'r') as f:
            p.script = Template(f.read()).render(doc=self.doc)

        p.web_page = 'Yes'
        p.save()
        get_obj(doc=p).write_cms_page()

        website.utils.add_guest_access_to_page(p.name)
        self.doc.page_name = p.name

        # cleanup
        for f in ['full_name', 'updated', 'content_html']:
            if f in self.doc.fields:
                del self.doc.fields[f]
Exemplo n.º 28
0
	def get_todo_list(self, user_id):
		from core.page.todo.todo import get
		todo_list = get()
		
		html = ""
		if todo_list:
			for i, todo in enumerate([todo for todo in todo_list if not todo.checked]):
				if i>= 10:
					break
				if not todo.description and todo.reference_type:
					todo.description = "%s: %s - %s %s" % \
					(todo.reference_type, get_url_to_form(todo.reference_type, todo.reference_name),
					_("assigned by"), get_fullname(todo.assigned_by))
					
				html += "<li style='line-height: 200%%'>%s [%s]</li>" % (todo.description, todo.priority)
				
		if html:
			return 1, "<h4>To Do (max 10):</h4><ul>" + html + "</ul><hr>"
		else:
			return 0, "<p>To Do</p>"
Exemplo n.º 29
0
	def validate(self):
		if not self.doc.parent_post and not self.doc.title:
			webnotes.throw("Please enter title!")
		
		self.assigned_to = webnotes.conn.get_value(self.doc.doctype, self.doc.name, "assigned_to")
		if self.doc.is_task:
			if not self.doc.status:
				self.doc.status = "Open"
			if self.doc.assigned_to:
				if not self.doc.assigned_to_fullname:
					self.doc.assigned_to_fullname = get_fullname(self.doc.assigned_to)
			else:
				self.doc.assigned_to_fullname = None
		else:
			self.doc.assigned_to = self.doc.assigned_to_fullname = self.doc.status = None
			
		if self.doc.is_event:
			if not self.doc.event_datetime:
				webnotes.throw("Please specify Event's Date and Time")
		else:
			self.doc.event_datetime = None
Exemplo n.º 30
0
def move_remarks_to_comments():
    from webnotes.utils import get_fullname
    result = webnotes.conn.sql(
        """select name, remark, modified_by from `tabStock Reconciliation`
		where ifnull(remark, '')!=''""")
    fullname_map = {}
    for reco, remark, modified_by in result:
        webnotes.model_wrapper([{
            "doctype":
            "Comment",
            "comment":
            remark,
            "comment_by":
            modified_by,
            "comment_by_fullname":
            fullname_map.setdefault(modified_by, get_fullname(modified_by)),
            "comment_doctype":
            "Stock Reconciliation",
            "comment_docname":
            reco
        }]).insert()
Exemplo n.º 31
0
def get_blog_list(args=None):
    """
		args = {
			'limit_start': 0,
			'limit_page_length': 10,
		}
	"""
    import webnotes

    if not args: args = webnotes.form_dict

    query = """\
		select
			cache.name as name, cache.html as content,
			blog.owner as owner, blog.creation as published,
			blog.title as title, (select count(name) from `tabComment` where
				comment_doctype='Blog' and comment_docname=blog.name) as comments
		from `tabWeb Cache` cache, `tabBlog` blog
		where cache.doc_type = 'Blog' and blog.page_name = cache.name
		order by published desc, name asc"""

    from webnotes.widgets.query_builder import add_limit_to_query
    query, args = add_limit_to_query(query, args)

    result = webnotes.conn.sql(query, args, as_dict=1)

    # strip html tags from content
    import webnotes.utils
    import website.web_cache

    for res in result:
        from webnotes.utils import global_date_format, get_fullname
        res['full_name'] = get_fullname(res['owner'])
        res['published'] = global_date_format(res['published'])
        if not res['content']:
            res['content'] = website.web_cache.get_html(res['name'])
        res['content'] = split_blog_content(res['content'])
        res['content'] = res['content'][:1000]

    return result
Exemplo n.º 32
0
def get_blog_list(args=None):
	"""
		args = {
			'limit_start': 0,
			'limit_page_length': 10,
		}
	"""
	import webnotes
	
	if not args: args = webnotes.form_dict
	
	query = """\
		select
			cache.name as name, cache.html as content,
			blog.owner as owner, blog.creation as published,
			blog.title as title, (select count(name) from `tabComment` where
				comment_doctype='Blog' and comment_docname=blog.name) as comments
		from `tabWeb Cache` cache, `tabBlog` blog
		where cache.doc_type = 'Blog' and blog.page_name = cache.name
		order by published desc, name asc"""
	
	from webnotes.widgets.query_builder import add_limit_to_query
	query, args = add_limit_to_query(query, args)
	
	result = webnotes.conn.sql(query, args, as_dict=1)

	# strip html tags from content
	import webnotes.utils
	import website.web_cache
	
	for res in result:
		from webnotes.utils import global_date_format, get_fullname
		res['full_name'] = get_fullname(res['owner'])
		res['published'] = global_date_format(res['published'])
		if not res['content']:
			res['content'] = website.web_cache.get_html(res['name'])
		res['content'] = split_blog_content(res['content'])
		res['content'] = res['content'][:1000]

	return result
Exemplo n.º 33
0
def get_lead_or_customer():
	customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user}, "customer")
	if customer:
		return webnotes.doc("Customer", customer)
	
	lead = webnotes.conn.get_value("Lead", {"email_id": webnotes.session.user})
	if lead:
		return webnotes.doc("Lead", lead)
	else:
		lead_bean = webnotes.bean({
			"doctype": "Lead",
			"email_id": webnotes.session.user,
			"lead_name": get_fullname(webnotes.session.user),
			"territory": guess_territory(),
			"status": "Open" # TODO: set something better???
		})
		
		if webnotes.session.user != "Guest":
			lead_bean.ignore_permissions = True
			lead_bean.insert()
			
		return lead_bean.doc
Exemplo n.º 34
0
	def validate(self):
		"""write/update 'Page' with the blog"""
		# we need the name for the templates
		if not self.doc.name:
			self.autoname()
		
		if self.doc.page_name:
			webnotes.conn.sql("""delete from tabPage where name=%s""", self.doc.page_name)
		
		p = website.utils.add_page(self.doc.title)
		
		from jinja2 import Template
		import markdown2
		import os
		from webnotes.utils import global_date_format, get_fullname
		from webnotes.model.code import get_obj
		
		self.doc.content_html = unicode(markdown2.markdown(self.doc.content or ''))
		self.doc.full_name = get_fullname(self.doc.owner)
		self.doc.updated = global_date_format(self.doc.modified)
		
		with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
			p.content = Template(f.read()).render(doc=self.doc)
		
		with open(os.path.join(os.path.dirname(__file__), 'blog_page.js'), 'r') as f:
			p.script = Template(f.read()).render(doc=self.doc)
			
		p.web_page = 'Yes'
		p.save()
		get_obj(doc=p).write_cms_page()
		
		website.utils.add_guest_access_to_page(p.name)
		self.doc.page_name = p.name
		
		# cleanup
		for f in ['full_name', 'updated', 'content_html']:
			if f in self.doc.fields:
				del self.doc.fields[f]				
Exemplo n.º 35
0
def notify(arg=None):
	from webnotes.utils import cstr, get_fullname, get_url
	
	fn = get_fullname(webnotes.user.name) or webnotes.user.name
	
	url = get_url()
	
	message = '''You have a message from <b>%s</b>:
	
	%s
	
	To answer, please login to your erpnext account at \
	<a href=\"%s\" target='_blank'>%s</a>
	''' % (fn, arg['txt'], url, url)
	
	sender = webnotes.conn.get_value("Profile", webnotes.user.name, "email") \
		or webnotes.user.name
	recipient = [webnotes.conn.get_value("Profile", arg["contact"], "email") \
		or arg["contact"]]
	
	from webnotes.utils.email_lib import sendmail
	sendmail(recipient, sender, message, arg.get("subject") or "You have a message from %s" % (fn,))
	
Exemplo n.º 36
0
def notify(arg=None):
    from webnotes.utils import cstr, get_fullname, get_url

    fn = get_fullname(webnotes.user.name) or webnotes.user.name

    url = get_url()

    message = '''You have a message from <b>%s</b>:
	
	%s
	
	To answer, please login to your erpnext account at \
	<a href=\"%s\" target='_blank'>%s</a>
	''' % (fn, arg['txt'], url, url)

    sender = webnotes.conn.get_value("Profile", webnotes.user.name, "email") \
     or webnotes.user.name
    recipient = [webnotes.conn.get_value("Profile", arg["contact"], "email") \
     or arg["contact"]]

    from webnotes.utils.email_lib import sendmail
    sendmail(recipient, sender, message,
             arg.get("subject") or "You have a message from %s" % (fn, ))
Exemplo n.º 37
0
def get_context():
	post_name = webnotes.request.path[1:].split("/")[1]
	post = webnotes.bean("Post", post_name).doc
	
	access = get_access(post.unit)
	if not access.get("read"):
		raise webnotes.PermissionError
	
	fullname = get_fullname(post.owner)
	title = "{post} by {fullname}".format(unit=post.unit, post="Post", fullname=fullname)
	unit = webnotes.bean("Unit", post.unit).doc
	parents = webnotes.conn.sql("""select name, unit_title from tabUnit 
		where lft <= %s and rgt >= %s order by lft asc""", (unit.lft, unit.rgt), as_dict=1)
	
	return {
		"name": post.unit,
		"title": title,
		"parent_post_html": get_parent_post_html(post, access),
		"post_list_html": get_child_posts_html(post),
		"public": 1,
		"parents": parents,
		"parent_post": post.name
	}