utils Package

utils Package

webnotes.utils.add_days(date, days)[source]

Adds days to the given string_date

webnotes.utils.add_months(string_date, months)[source]
webnotes.utils.add_years(string_date, years)[source]
webnotes.utils.cint(s)[source]

Convert to integer

webnotes.utils.clear_recycle_bin()[source]
webnotes.utils.cstr(s)[source]

Convert to string

webnotes.utils.date_diff(string_ed_date, string_st_date=None)[source]
webnotes.utils.db_exists(dt, dn)[source]
webnotes.utils.dict_to_str(args, sep='&')[source]

Converts a dictionary to URL

webnotes.utils.flt(s)[source]

Convert to float (ignore commas)

webnotes.utils.fmt_money(amount, fmt='%.2f')[source]

Convert to string with commas for thousands, millions etc

webnotes.utils.formatdate(string_date)[source]

Convers the given string date to user_format

webnotes.utils.generate_hash()[source]

Generates reandom hash for session id

webnotes.utils.getCSVelement(v)[source]

Returns the CSV value of v, For example:

  • apple becomes “apple”
  • hi”there becomes “hi”“there”
webnotes.utils.getTraceback()[source]

Returns the traceback of the Exception

webnotes.utils.get_defaults(key=None)[source]

Get dictionary of default values from the Control Panel, or a value if key is passed

webnotes.utils.get_first_day(dt, d_years=0, d_months=0)[source]

Returns the first day of the month for the date specified by date object Also adds d_years and d_months if specified

webnotes.utils.get_last_day(dt)[source]

Returns last day of the month using: get_first_day(dt, 0, 1) + datetime.timedelta(-1)

webnotes.utils.getdate(string_date)[source]

Coverts string date (yyyy-mm-dd) to datetime.date object

webnotes.utils.global_date_format(date)[source]
webnotes.utils.has_common(l1, l2)[source]

Returns true if there are common elements in lists l1 and l2

webnotes.utils.in_words(integer)[source]

Returns string in words for the given integer.

webnotes.utils.isNull(v)[source]

Returns true if v=’’ or v is None

webnotes.utils.load_json(arg)[source]
webnotes.utils.log(event, details)[source]
webnotes.utils.money_in_words(number, main_currency=None, fraction_currency=None)[source]

Returns string in words with currency and fraction currency.

webnotes.utils.now()[source]

Returns time.strftime(‘%Y-%m-%d %H:%M:%S’)

webnotes.utils.now_datetime()[source]
webnotes.utils.nowdate()[source]

Returns time.strftime(‘%Y-%m-%d’)

webnotes.utils.parse_val(v)[source]

Converts to simple datatypes from SQL query results

webnotes.utils.pprint_dict(d, level=1)[source]
webnotes.utils.replace_newlines(s)[source]

Replace newlines by ‘<br>’

webnotes.utils.send_error_report()[source]
webnotes.utils.sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc=[], attach=[])[source]

Send an email. For more details see email_lib.sendmail()

webnotes.utils.set_default(key, val)[source]

Set / add a default value to Control Panel

webnotes.utils.str_esc_quote(s)[source]

Escape quotes

webnotes.utils.timestamps_equal(t1, t2)[source]

Returns true if same the two string timestamps are same

webnotes.utils.user_format

User format specified in Control Panel

Examples:

  • dd-mm-yyyy
  • mm-dd-yyyy
  • dd/mm/yyyy
webnotes.utils.validate_email_add(email_str)[source]

Validates the email string

archive Module

backups Module

cache Module

Simple Caching:

Stores key-value pairs in database and enables simple caching

get_item(key).get() returns the cached value if not expired (else returns null) get_item(key).set(interval = 60000) sets a value to cache, expiring after x seconds get_item(key).clear() clears an old value setup() sets up cache

class webnotes.utils.cache.CacheItem(key)[source]
clear()[source]

clear the item

get()[source]

get value

set(value, interval=6000)[source]

set a new value, with interval

webnotes.utils.cache.get_item(key)[source]

returns get CacheItem object

webnotes.utils.cache.setup()[source]

encrypt Module

XTEA Block Encryption Algorithm Author: Paul Chakravarti (paul_dot_chakravarti_at_gmail_dot_com) License: Public Domain

webnotes.utils.encrypt.crypt(key, data, iv='\x00\x00\x00\x00\x00\x00\x00\x00', n=32)[source]
webnotes.utils.encrypt.decrypt(data, encryption_key=None)[source]
webnotes.utils.encrypt.encrypt(data, encryption_key=None)[source]
webnotes.utils.encrypt.get_key()[source]
webnotes.utils.encrypt.xtea_decrypt(key, block, n=32, endian='!')[source]
webnotes.utils.encrypt.xtea_encrypt(key, block, n=32, endian='!')[source]

file_manager Module

webnotes.utils.file_manager.convert_to_files(verbose=0)[source]
webnotes.utils.file_manager.delete_file(fname, verbose=0)[source]
webnotes.utils.file_manager.get_file(fname)[source]
webnotes.utils.file_manager.get_file_system_name(fname)[source]
webnotes.utils.file_manager.make_thumbnail(blob, size)[source]
webnotes.utils.file_manager.save_file(fname, content, module=None)[source]
webnotes.utils.file_manager.save_uploaded(js_okay='window.parent.msgprint("File Upload Successful")', js_fail='')[source]
webnotes.utils.file_manager.upload()[source]
webnotes.utils.file_manager.write_file(fid, content)[source]

jsmin Module

class webnotes.utils.jsmin.JavascriptMinify[source]

Bases: object

minify(instream, outstream)[source]
exception webnotes.utils.jsmin.UnterminatedComment[source]

Bases: exceptions.Exception

exception webnotes.utils.jsmin.UnterminatedRegularExpression[source]

Bases: exceptions.Exception

exception webnotes.utils.jsmin.UnterminatedStringLiteral[source]

Bases: exceptions.Exception

webnotes.utils.jsmin.isAlphanum(c)[source]

return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.

webnotes.utils.jsmin.jsmin(js)[source]

nestedset Module

webnotes.utils.nestedset.rebuild_node(doctype, parent, left, parent_field)[source]
webnotes.utils.nestedset.rebuild_tree(doctype, parent_field)[source]
webnotes.utils.nestedset.update_add_node(doctype, name, parent, parent_field)[source]
webnotes.utils.nestedset.update_nsm(doc_obj)[source]
webnotes.utils.nestedset.update_remove_node(doctype, name)[source]

scheduler Module

Simple Scheduler

This scheduler is used to fire events across multiple databases. A database master_scheduler is maintained with one event and one log table

Events are added by different databases in the master scheduler using the set_event method and they are executed by the cron.

__main__ will call run

To install:

python install_lib.py [root] [password] master_scheduler

In cron:

python [path]webnotes/utils/scheduler.py

class webnotes.utils.scheduler.Scheduler[source]
clear(db_name, event)[source]

Clears the event

connect()[source]
execute(db_name, event)[source]

Executes event in the specifed db

get_events(db_name=None)[source]

Returns list of upcoming events

get_log(db_name=None)[source]

Returns log of events

log(db_name, event, traceback)[source]

Log an event error

run()[source]

Run scheduled (due) events and reset time for recurring events

set(event, interval, recurring, db_name=None)[source]

Add an event to the Event table in the master scheduler

webnotes.utils.scheduler.cancel_event(event)[source]

Cancels an event

webnotes.utils.scheduler.set_event(event, interval=86400, recurring=1)[source]

Adds an event to the master scheduler

sitemap Module

webnotes.utils.sitemap.generate_xml(conn, site_prefix)[source]

transfer Module

class webnotes.utils.transfer.UpdateDocType(in_doclist)[source]

Bases: webnotes.utils.transfer.UpdateDocumentMerge

add_section_breaks_and_renum()[source]
child_exists(d)[source]
clear_section_breaks()[source]
fix_extra_fields(extra)[source]
get_extra_fields()[source]
get_id(d)[source]
get_orignal_values(d)[source]
on_save()[source]
renum()[source]
to_udpate(d)[source]
class webnotes.utils.transfer.UpdateDocTypeMapper(in_doclist)[source]

Bases: webnotes.utils.transfer.UpdateDocumentMerge

get_id(d)[source]
get_orignal_values(d)[source]
class webnotes.utils.transfer.UpdateDocument(in_doclist=[])[source]
delete_existing()[source]
is_modified()[source]
run_on_update()[source]
save()[source]
save_children()[source]
save_one_doc(df, as_new=1)[source]
sync()[source]
update_modified()[source]
class webnotes.utils.transfer.UpdateDocumentMerge(in_doclist)[source]

Bases: webnotes.utils.transfer.UpdateDocument

child_exists(d)[source]
delete_existing()[source]
get_id(d)[source]
keep_values(d)[source]
on_save()[source]
save()[source]
save_children()[source]
to_update(d)[source]
class webnotes.utils.transfer.UpdateModuleDef(in_doclist)[source]

Bases: webnotes.utils.transfer.UpdateDocumentMerge

get_id(d)[source]
get_orignal_values(d)[source]
to_update(d)[source]
webnotes.utils.transfer.set_doc(doclist, ovr=0, ignore=1, onupdate=1)[source]

webservice Module

class webnotes.utils.webservice.FrameworkServer(remote_host, path, user='', password='', account='', cookies=None, opts=None, https=0)[source]

Connect to a remote server via HTTP (webservice).

  • remote_host is the the address of the remote server
  • path is the path of the Framework (excluding index.cgi)
http_get_response(method, args)[source]

Run a method on the remote server, with the given arguments

run_method(method, args)[source]
runserverobj(doctype, docname, method, arg='')[source]

Returns the response of a remote method called on a system object specified by doctype and docname