Merge branch 'develop' of https://github.com/frappe/frappe into custom_append_to

This commit is contained in:
Himanshu Warekar 2019-12-12 19:23:53 +05:30
commit 02e8e3380c
8 changed files with 101 additions and 33 deletions

View file

@ -13,6 +13,8 @@ from six import text_type
@click.argument('site')
@click.option('--db-name', help='Database name')
@click.option('--db-type', default='mariadb', type=click.Choice(['mariadb', 'postgres']), help='Optional "postgres" or "mariadb". Default is "mariadb"')
@click.option('--db-host', help='Database Host')
@click.option('--db-port', type=int, help='Database Port')
@click.option('--mariadb-root-username', default='root', help='Root username for MariaDB')
@click.option('--mariadb-root-password', help='Root password for MariaDB')
@click.option('--admin-password', help='Administrator password for new site', default=None)
@ -21,22 +23,22 @@ from six import text_type
@click.option('--source_sql', help='Initiate database with a SQL file')
@click.option('--install-app', multiple=True, help='Install app after installation')
def new_site(site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None,
verbose=False, install_apps=None, source_sql=None, force=None, install_app=None,
db_name=None, db_type=None):
verbose=False, install_apps=None, source_sql=None, force=None, install_app=None,
db_name=None, db_type=None, db_host=None, db_port=None):
"Create a new site"
frappe.init(site=site, new_site=True)
_new_site(db_name, site, mariadb_root_username=mariadb_root_username,
mariadb_root_password=mariadb_root_password, admin_password=admin_password,
verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force,
db_type=db_type)
mariadb_root_password=mariadb_root_password, admin_password=admin_password,
verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force,
db_type=db_type, db_host=db_host, db_port=db_port)
if len(frappe.utils.get_sites()) == 1:
use(site)
def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=None,
admin_password=None, verbose=False, install_apps=None, source_sql=None, force=False,
reinstall=False, db_type=None):
admin_password=None, verbose=False, install_apps=None, source_sql=None, force=False,
reinstall=False, db_type=None, db_host=None, db_port=None):
"""Install a new Frappe site"""
if not force and os.path.exists(site):
@ -65,8 +67,8 @@ def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=N
installing = touch_file(get_site_path('locks', 'installing.lock'))
install_db(root_login=mariadb_root_username, root_password=mariadb_root_password,
db_name=db_name, admin_password=admin_password, verbose=verbose,
source_sql=source_sql, force=force, reinstall=reinstall, db_type=db_type)
db_name=db_name, admin_password=admin_password, verbose=verbose,
source_sql=source_sql, force=force, reinstall=reinstall, db_type=db_type, db_host=db_host, db_port=db_port)
apps_to_install = ['frappe'] + (frappe.conf.get("install_apps") or []) + (list(install_apps) or [])
for app in apps_to_install:

View file

@ -80,12 +80,14 @@ class DbManager:
if pipe:
print('Creating Database...')
command = '{pipe} mysql -u {user} -p{password} -h{host} {target} {source}'.format(
command = '{pipe} mysql -u {user} -p{password} -h{host} ' + ('-P{port}' if frappe.db.port else '') + ' {target} {source}'
command = command.format(
pipe=pipe,
user=esc(user),
password=esc(password),
host=esc(frappe.db.host),
target=esc(target),
source=source
source=source,
port=frappe.db.port
)
os.system(command)

View file

@ -19,6 +19,14 @@
background: #f0f4f7;
}
.from-date-field .clearfix{
display: none;
}
.from-date-field {
margin-left: 10px;
}
.select-time:focus, .select-doctype:focus, .select-filter:focus, .select-sort:focus {
background: #f0f4f7;
}

View file

@ -41,7 +41,11 @@ class Leaderboard {
return field;
});
}
this.timespans = ["Week", "Month", "Quarter", "Year", "All Time"];
this.timespans = [
"This Week", "This Month", "This Quarter", "This Year",
"Last Week", "Last Month", "Last Quarter", "Last Year",
"All Time", "Select From Date"
];
// for saving current selected filters
const _initial_doctype = frappe.get_route()[1] || this.doctypes[0];
@ -103,7 +107,8 @@ class Leaderboard {
this.timespans.map(d => {
return {"label": __(d), value: d };
})
);
);
this.create_from_date_field();
this.type_select = this.page.add_select(__("Field"),
this.options.selected_filter.map(d => {
@ -113,7 +118,12 @@ class Leaderboard {
this.timespan_select.on("change", (e) => {
this.options.selected_timespan = e.currentTarget.value;
this.make_request();
if (this.options.selected_timespan === 'Select From Date') {
this.from_date_field.show();
} else {
this.from_date_field.hide();
this.make_request();
}
});
this.type_select.on("change", (e) => {
@ -122,6 +132,28 @@ class Leaderboard {
});
}
create_from_date_field() {
let timespan_field = $(this.parent).find(`.frappe-control[data-original-title='Timespan']`);
this.from_date_field = $(`<div class="from-date-field"></div>`).insertAfter(timespan_field).hide();
let date_field = frappe.ui.form.make_control({
df: {
fieldtype: 'Date',
fieldname: 'selected_from_date',
placeholder: frappe.datetime.month_start(),
default: frappe.datetime.month_start(),
input_class: 'input-sm',
reqd: 1,
change: () => {
this.selected_from_date = date_field.get_value();
if (this.selected_from_date) this.make_request();
}
},
parent: $(this.parent).find('.from-date-field'),
render_input: 1
});
}
render_selected_doctype() {
this.$sidebar_list.on("click", "li", (e)=> {
@ -207,7 +239,6 @@ class Leaderboard {
this.leaderboard_config[this.options.selected_doctype].method,
{
'from_date': this.get_from_date(),
'timespan': this.options.selected_timespan,
'company': this.options.selected_company,
'field': this.options.selected_filter_item,
'limit': this.leaderboard_limit,
@ -360,17 +391,20 @@ class Leaderboard {
get_from_date() {
let timespan = this.options.selected_timespan.toLowerCase();
let current_date = frappe.datetime.now_date();
let date = '';
if (timespan === "month") {
date = frappe.datetime.add_months(current_date, -1);
} else if (timespan === "quarter") {
date = frappe.datetime.add_months(current_date, -3);
} else if (timespan === "year") {
date = frappe.datetime.add_months(current_date, -12);
} else if (timespan === "week") {
date = frappe.datetime.add_days(current_date, -7);
let get_from_date = {
"this week": frappe.datetime.week_start(),
"this month": frappe.datetime.month_start(),
"this quarter": frappe.datetime.quarter_start(),
"this year": frappe.datetime.year_start(),
"last week": frappe.datetime.add_days(current_date, -7),
"last month": frappe.datetime.add_months(current_date, -1),
"last quarter": frappe.datetime.add_months(current_date, -3),
"last year": frappe.datetime.add_months(current_date, -12),
"all time": "",
"select from date": this.selected_from_date || frappe.datetime.month_start()
}
return date;
return get_from_date[timespan];
}
}

View file

@ -21,13 +21,13 @@ from frappe.database import setup_database
from frappe.core.doctype.scheduled_job_type.scheduled_job_type import sync_jobs
def install_db(root_login="root", root_password=None, db_name=None, source_sql=None,
admin_password=None, verbose=True, force=0, site_config=None, reinstall=False,
db_type=None):
admin_password=None, verbose=True, force=0, site_config=None, reinstall=False,
db_type=None, db_host=None, db_port=None):
if not db_type:
db_type = frappe.conf.db_type or 'mariadb'
make_conf(db_name, site_config=site_config, db_type=db_type)
make_conf(db_name, site_config=site_config, db_type=db_type, db_host=db_host, db_port=db_port)
frappe.flags.in_install_db = True
frappe.flags.root_login = root_login
@ -191,14 +191,14 @@ def init_singles():
doc.flags.ignore_validate=True
doc.save()
def make_conf(db_name=None, db_password=None, site_config=None, db_type=None):
def make_conf(db_name=None, db_password=None, site_config=None, db_type=None, db_host=None, db_port=None):
site = frappe.local.site
make_site_config(db_name, db_password, site_config, db_type=db_type)
make_site_config(db_name, db_password, site_config, db_type=db_type, db_host=db_host, db_port=db_port)
sites_path = frappe.local.sites_path
frappe.destroy()
frappe.init(site, sites_path=sites_path)
def make_site_config(db_name=None, db_password=None, site_config=None, db_type=None):
def make_site_config(db_name=None, db_password=None, site_config=None, db_type=None, db_host=None, db_port=None):
frappe.create_folder(os.path.join(frappe.local.site_path))
site_file = get_site_config_path()
@ -209,6 +209,12 @@ def make_site_config(db_name=None, db_password=None, site_config=None, db_type=N
if db_type:
site_config['db_type'] = db_type
if db_host:
site_config['db_host'] = db_host
if db_port:
site_config['db_port'] = db_port
with open(site_file, "w") as f:
f.write(json.dumps(site_config, indent=1, sort_keys=True))

View file

@ -3,6 +3,9 @@ import frappe
def execute():
if frappe.db.count("File", filters={"attached_to_doctype": "Prepared Report", "is_private": 0}) > 10000:
frappe.db.auto_commit_on_many_writes = True
files = frappe.get_all("File", fields=["name", "attached_to_name"], filters={"attached_to_doctype": "Prepared Report", "is_private": 0})
for file_dict in files:
# For some reason Prepared Report doc might not exist, check if it exists first
@ -17,3 +20,7 @@ def execute():
else:
# If Prepared Report doc doesn't exist then the file doc is useless. Delete it.
frappe.delete_doc("File", file_dict.name)
if frappe.db.auto_commit_on_many_writes:
frappe.db.auto_commit_on_many_writes = False

View file

@ -90,6 +90,14 @@ $.extend(frappe.datetime, {
return moment().endOf("month").format();
},
quarter_start: function() {
return moment().startOf("quarter").format();
},
quarter_end: function() {
return moment().endOf("quarter").format();
},
year_start: function(){
return moment().startOf("year").format();
},

View file

@ -10,7 +10,8 @@
// To compensate for percieved centering
.null-state {
height: 12em !important;
height: 15rem !important;
max-height: 150px;
width: auto;
}
@ -616,4 +617,4 @@ input.list-check-all, input.list-row-checkbox {
.file-title {
margin-top: 5px;
}
}