removed archive.py

This commit is contained in:
Rushabh Mehta 2012-09-25 17:07:14 +05:30
parent 0fdb4b29ab
commit 90384c4e6f
6 changed files with 6 additions and 387 deletions

View file

@ -414,7 +414,7 @@ def validate_column_name(n):
# sync table - called from form.py
# -------------------------------------------------
def updatedb(dt, archive=0):
def updatedb(dt):
"""
Syncs a `DocType` to the table
* creates if required
@ -427,7 +427,7 @@ def updatedb(dt, archive=0):
if not res[0][0]:
webnotes.conn.commit()
tab = DbTable(dt, archive and 'arc' or 'tab')
tab = DbTable(dt, 'tab')
tab.sync()
webnotes.conn.begin()

View file

@ -1,130 +0,0 @@
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
#
# MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
from __future__ import unicode_literals
import webnotes
sql = webnotes.conn.sql
# main function
# -------------------------
def archive_doc(doctype, name, restore=0):
archive_record(doctype, name, restore)
tables = sql("select options from tabDocField where parent=%s and fieldtype='Table'", doctype)
for t in tables:
try:
rec_list = sql("select name from `%s%s` where parent=%s" % ((restore and 'arc' or 'tab') ,t[0], '%s'), name)
except Exception,e:
if e.args[0]==1146: # no child table
rec_list = []
else:
raise e
for r in rec_list:
archive_record(t[0], r[0], restore)
# archive individual record
# -------------------------
def archive_record(doctype, name, restore = 0):
src_tab = (restore and 'arc' or 'tab') + doctype
tar_tab = (restore and 'tab' or 'arc') + doctype
# get the record
try:
rec = sql("select * from `%s` where name=%s for update" % (src_tab, '%s'), name, as_dict=1)[0]
except Exception, e:
if e.args[0]==1146:
return # source table does not exist
else:
raise e
# insert the record
insert_record(doctype, tar_tab, name)
# put it field by field (ignore missing columns)
for field in rec.keys():
if rec.get(field):
update_value(src_tab, tar_tab, name, rec, field)
# delete from main
try:
sql("delete from `%s` where name=%s limit 1" % (src_tab, '%s'), name)
except Exception, e:
if e.args[0]==1451:
webnotes.msgprint("Cannot archive %s '%s' as it is referenced in another record. You must delete the referred record first" % (doctype, name))
# delete from target, as it will create a double copy!
sql("delete from `%s` where name=%s limit 1" % (tar_tab, '%s'), name)
# insert the record
# -------------------------
def insert_record_name(tab, name):
sql("insert ignore into `%s` (name) values (%s)" % (tab, '%s'), name)
# insert record
# -------------------------
def insert_record(doctype, tar_tab, name):
try:
insert_record_name(tar_tab, name)
except Exception, e:
if e.args[0]==1146:
# missing table - create it
from webnotes.model.db_schema import updatedb
updatedb(doctype, 1)
# again
insert_record_name(tar_tab, name)
else:
raise e
# update single value
# -------------------------
def update_single_value(tab, field, value, name):
sql("update `%s` set `%s`=%s where name=%s" % (tab, field, '%s', '%s'), (value, name))
# update value
# -------------------------
def update_value(src_tab, tar_tab, name, rec, field):
try:
update_single_value(tar_tab, field, rec[field], name)
except Exception, e:
if e.args[0]==1054:
# column missing.... add it?
ftype = sql("show columns from `%s` like '%s'" % (src_tab, field))[0][1]
webnotes.conn.commit() # causes implict commit
sql("alter table `%s` add column `%s` %s" % (tar_tab, field, ftype))
webnotes.conn.begin()
# again
update_single_value(tar_tab, field, rec[field], name)
else:
raise e

View file

@ -1,77 +0,0 @@
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
#
# MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
from __future__ import unicode_literals
"""
XTEA Block Encryption Algorithm
Author: Paul Chakravarti (paul_dot_chakravarti_at_gmail_dot_com)
License: Public Domain
"""
def get_key():
# Encryption key is datetime of creation of DocType, DocType"
import webnotes
return webnotes.conn.sql("select creation from tabDocType where name='DocType'")[0][0].strftime('%Y%m%d%H%M%s')[:16]
def encrypt(data, encryption_key = None):
if not encryption_key:
encryption_key = get_key()
return crypt(encryption_key, data).encode('hex')
def decrypt(data, encryption_key = None):
if not encryption_key:
encryption_key = get_key()
return crypt(encryption_key, data.decode('hex'))
def crypt(key,data,iv='\00\00\00\00\00\00\00\00',n=32):
def keygen(key,iv,n):
while True:
iv = xtea_encrypt(key,iv,n)
for k in iv:
yield ord(k)
xor = [ chr(x^y) for (x,y) in zip(map(ord,data),keygen(key,iv,n)) ]
return "".join(xor)
def xtea_encrypt(key,block,n=32,endian="!"):
import struct
v0,v1 = struct.unpack(endian+"2L",block)
k = struct.unpack(endian+"4L",key)
sum,delta,mask = 0L,0x9e3779b9L,0xffffffffL
for round in range(n):
v0 = (v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask
sum = (sum + delta) & mask
v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask
return struct.pack(endian+"2L",v0,v1)
def xtea_decrypt(key,block,n=32,endian="!"):
import struct
v0,v1 = struct.unpack(endian+"2L",block)
k = struct.unpack(endian+"4L",key)
delta,mask = 0x9e3779b9L,0xffffffffL
sum = (delta * n) & mask
for round in range(n):
v1 = (v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask
sum = (sum - delta) & mask
v0 = (v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask
return struct.pack(endian+"2L",v0,v1)

View file

@ -37,24 +37,19 @@ def getdoc():
form = webnotes.form_dict
doctype, docname = form.get('doctype'), form.get('name')
prefix = cint(form.get('from_archive')) and 'arc' or 'tab'
if not (doctype and docname):
raise Exception, 'doctype and name required!'
doclist = []
# single
doclist = load_single_doc(doctype, docname, (form.get('user') or webnotes.session['user']), prefix)
doclist = load_single_doc(doctype, docname, (form.get('user') or webnotes.session['user']))
# load doctype along with the doc
if form.get('getdoctype'):
import webnotes.model.doctype
doclist += webnotes.model.doctype.get(doctype)
# tag as archived
if prefix == 'arc':
doclist[0].__archived=1
webnotes.response['docs'] = doclist
@webnotes.whitelist()
@ -87,16 +82,12 @@ def getdoctype():
webnotes.response['docs'] = doclist
def load_single_doc(dt, dn, user, prefix):
def load_single_doc(dt, dn, user):
"""load doc and call onload methods"""
import webnotes.model.code
if not dn: dn = dt
dl = webnotes.model.doc.get(dt, dn, prefix=prefix)
# archive, done
if prefix=='arc':
return dl
dl = webnotes.model.doc.get(dt, dn)
try:
so, r = webnotes.model.code.get_server_obj(dl[0], dl), None

View file

@ -1,165 +0,0 @@
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
#
# MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
from __future__ import unicode_literals
"""
Server side methods called from DocBrowser
Needs to be refactored
"""
import webnotes
from webnotes.utils import cint, cstr
sql = webnotes.conn.sql
@webnotes.whitelist()
def has_result():
"""return Yes if the given dt has any records"""
return sql("select name from `tab%s` limit 1" % \
webnotes.form_dict.get('dt')) and 'Yes' or 'No'
def is_submittable(dt):
return sql("select name from tabDocPerm where parent=%s and ifnull(submit,0)=1 and docstatus<1 limit 1", dt)
def can_cancel(dt):
return sql('select name from tabDocPerm where parent="%s" and ifnull(cancel,0)=1 and docstatus<1 and role in ("%s") limit 1' % (dt, '", "'.join(webnotes.user.get_roles())))
def get_dt_trend(dt):
ret = {}
for r in sql("select datediff(now(),modified), count(*) from `tab%s` where datediff(now(),modified) between 0 and 30 group by date(modified)" % dt):
ret[cint(r[0])] = cint(r[1])
return ret
def get_columns(out, sf, fl, dt, tag_fields):
if not fl:
fl = sf
# subject
subject = webnotes.conn.get_value('DocType', dt, 'subject')
if subject:
out['subject'] = subject
# get fields from subject
import re
fl = re.findall('\%\( (?P<name> [^)]*) \)s', subject, re.VERBOSE)
if tag_fields:
fl += [t.strip() for t in tag_fields.split(',')]
res = []
for f in tuple(set(fl)):
if f:
res += [[c or '' for c in r] for r in sql("select fieldname, label, fieldtype, options from tabDocField where parent='%s' and fieldname='%s'" % (dt, f))]
return res
# --------------------------------------------------------------
# NOTE: THIS SHOULD BE CACHED IN DOCTYPE CACHE
# --------------------------------------------------------------
@webnotes.whitelist()
def get_dt_details():
"""
Returns details called by DocBrowser this includes:
the filters, columns, subject and tag_fields
also if the doctype is of type "submittable"
"""
fl = eval(webnotes.form_dict.get('fl'))
dt = webnotes.form_dict.get('dt')
tag_fields, description = webnotes.conn.get_value('DocType', dt, ['tag_fields', 'description'])
submittable = is_submittable(dt) and 1 or 0
out = {
'submittable':(is_submittable(dt) and 1 or 0),
'can_cancel':(can_cancel(dt) and 1 or 0)
}
# filters
# -------
sf = sql("select search_fields from tabDocType where name=%s", dt)[0][0] or ''
# get fields from in_filter (if not in search_fields)
if not sf.strip():
res = sql("select fieldname, label, fieldtype, options from tabDocField where parent=%s and `in_filter` = 1 and ifnull(fieldname,'') != ''", dt)
sf = [s[0] for s in res]
else:
sf = [s.strip() for s in sf.split(',')]
res = sql("select fieldname, label, fieldtype, options from tabDocField where parent='%s' and fieldname in (%s)" % (dt, '"'+'","'.join(sf)+'"'))
# select "link" options
res = [[c or '' for c in r] for r in res]
for r in res:
if r[2]=='Select' and r[3] and r[3].startswith('link:'):
tdt = r[3][5:]
ol = sql("select name from `tab%s` where docstatus!=2 order by name asc" % tdt)
r[3] = "\n".join([''] + [o[0] for o in ol])
if not res:
out['filters'] = [['name', 'ID', 'Data', '']]
else:
out['filters'] = [['name', 'ID', 'Data', '']] + res
# columns
# -------
res = get_columns(out, sf, fl, dt, tag_fields)
from webnotes.widgets.tags import check_user_tags
check_user_tags(dt)
out['columns'] = [['name', 'ID', 'Link', dt], ['modified', 'Modified', 'Data', ''], ['_user_tags', 'Tags', 'Data', '']] + res
out['tag_fields'] = tag_fields
out['description'] = description
return out
@webnotes.whitelist()
def get_trend():
return {'trend': get_dt_trend(webnotes.form_dict.get('dt'))}
@webnotes.whitelist()
def delete_items():
"""delete selected items"""
il = eval(webnotes.form_dict.get('items'))
from webnotes.model import delete_doc
from webnotes.model.code import get_obj
for d in il:
dt_obj = get_obj(d[0], d[1])
if hasattr(dt_obj, 'on_trash'):
dt_obj.on_trash()
delete_doc(d[0], d[1])
@webnotes.whitelist()
def archive_items():
"""archinve selected items"""
il = eval(webnotes.form_dict.get('items'))
from webnotes.utils.archive import archive_doc
for d in il:
archive_doc(d[0], d[1], webnotes.form_dict.get('action')=='Restore' and 1 or 0)

2
wnf.py
View file

@ -75,8 +75,8 @@ def search_replace_with_prompt(fpath, txt1, txt2, force=False):
print colored('Updated', 'green')
def pull(remote, branch):
os.system('git pull %s %s' % (remote, branch))
os.system('cd lib && git pull %s %s' % (remote, branch))
os.system('cd ../app && git pull %s %s' % (remote, branch))
def apply_latest_patches():
import webnotes.modules.patch_handler