2015-03-03 09:25:30 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2014-04-18 10:30:41 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
|
|
|
|
import frappe
|
|
|
|
from frappe import _
|
|
|
|
from frappe.utils import nowdate
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2014-04-18 10:30:41 +00:00
|
|
|
class website_maker(object):
|
2016-05-12 09:52:59 +00:00
|
|
|
def __init__(self, args):
|
|
|
|
self.args = args
|
|
|
|
self.company = args.company_name
|
|
|
|
self.tagline = args.company_tagline
|
2018-04-30 12:40:22 +00:00
|
|
|
self.user = args.get("email")
|
2014-04-18 10:30:41 +00:00
|
|
|
self.make_web_page()
|
|
|
|
self.make_website_settings()
|
|
|
|
self.make_blog()
|
|
|
|
|
|
|
|
def make_web_page(self):
|
2014-04-22 11:22:11 +00:00
|
|
|
# home page
|
2016-05-12 09:52:59 +00:00
|
|
|
homepage = frappe.get_doc("Homepage", "Homepage")
|
|
|
|
homepage.company = self.company
|
|
|
|
homepage.tag_line = self.tagline
|
|
|
|
homepage.setup_items()
|
|
|
|
homepage.save()
|
2014-04-22 11:22:11 +00:00
|
|
|
|
2014-04-18 10:30:41 +00:00
|
|
|
def make_website_settings(self):
|
|
|
|
# update in home page in settings
|
|
|
|
website_settings = frappe.get_doc("Website Settings", "Website Settings")
|
2016-05-12 09:52:59 +00:00
|
|
|
website_settings.home_page = "home"
|
2014-04-18 10:30:41 +00:00
|
|
|
website_settings.brand_html = self.company
|
|
|
|
website_settings.copyright = self.company
|
|
|
|
website_settings.top_bar_items = []
|
|
|
|
website_settings.append(
|
|
|
|
"top_bar_items", {"doctype": "Top Bar Item", "label": "Contact", "url": "/contact"}
|
|
|
|
)
|
|
|
|
website_settings.append(
|
|
|
|
"top_bar_items", {"doctype": "Top Bar Item", "label": "Blog", "url": "/blog"}
|
|
|
|
)
|
2014-04-21 16:40:15 +00:00
|
|
|
website_settings.append(
|
|
|
|
"top_bar_items", {"doctype": "Top Bar Item", "label": _("Products"), "url": "/all-products"}
|
|
|
|
)
|
2014-04-18 10:30:41 +00:00
|
|
|
website_settings.save()
|
|
|
|
|
|
|
|
def make_blog(self):
|
2018-04-30 12:40:22 +00:00
|
|
|
blog_category = frappe.get_doc(
|
|
|
|
{"doctype": "Blog Category", "category_name": "general", "published": 1, "title": _("General")}
|
|
|
|
).insert()
|
|
|
|
|
|
|
|
if not self.user:
|
|
|
|
# Admin setup
|
|
|
|
return
|
|
|
|
|
2014-04-18 10:30:41 +00:00
|
|
|
blogger = frappe.new_doc("Blogger")
|
|
|
|
user = frappe.get_doc("User", self.user)
|
|
|
|
blogger.user = self.user
|
|
|
|
blogger.full_name = user.first_name + (" " + user.last_name if user.last_name else "")
|
|
|
|
blogger.short_name = user.first_name.lower()
|
|
|
|
blogger.avatar = user.user_image
|
|
|
|
blogger.insert()
|
|
|
|
|
2014-04-21 08:13:11 +00:00
|
|
|
frappe.get_doc(
|
|
|
|
{
|
2014-04-18 10:30:41 +00:00
|
|
|
"doctype": "Blog Post",
|
|
|
|
"title": "Welcome",
|
|
|
|
"published": 1,
|
|
|
|
"published_on": nowdate(),
|
|
|
|
"blogger": blogger.name,
|
|
|
|
"blog_category": blog_category.name,
|
|
|
|
"blog_intro": "My First Blog",
|
2015-11-09 11:23:11 +00:00
|
|
|
"content": frappe.get_template("setup/setup_wizard/data/sample_blog_post.html").render(),
|
2014-04-18 10:30:41 +00:00
|
|
|
}
|
|
|
|
).insert()
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2014-04-18 10:30:41 +00:00
|
|
|
|
|
|
|
def test():
|
|
|
|
frappe.delete_doc("Web Page", "test-company")
|
|
|
|
frappe.delete_doc("Blog Post", "welcome")
|
|
|
|
frappe.delete_doc("Blogger", "administrator")
|
|
|
|
frappe.delete_doc("Blog Category", "general")
|
2016-05-12 09:52:59 +00:00
|
|
|
website_maker(
|
2022-03-28 13:22:46 +00:00
|
|
|
{
|
2016-05-12 09:52:59 +00:00
|
|
|
"company": "Test Company",
|
|
|
|
"company_tagline": "Better Tools for Everyone",
|
|
|
|
"name": "Administrator",
|
2022-03-28 13:22:46 +00:00
|
|
|
}
|
2016-05-12 09:52:59 +00:00
|
|
|
)
|
2014-04-18 10:30:41 +00:00
|
|
|
frappe.db.commit()
|