Kaynağa Gözat

added sync_all in module

version-14
Rushabh Mehta 14 yıl önce
ebeveyn
işleme
f55ffc988a
16 değiştirilmiş dosya ile 75 ekleme ve 49 silme
  1. +3
    -4
      cgi-bin/core/doctype/custom_field/custom_field.txt
  2. +3
    -3
      cgi-bin/core/doctype/custom_script/custom_script.txt
  3. +1
    -1
      cgi-bin/core/doctype/doctype/doctype.py
  4. +2
    -2
      cgi-bin/core/doctype/doctype_label/doctype_label.txt
  5. +3
    -3
      cgi-bin/core/doctype/doctype_mapper/doctype_mapper.txt
  6. +3
    -3
      cgi-bin/core/doctype/field_mapper_detail/field_mapper_detail.txt
  7. +2
    -2
      cgi-bin/core/doctype/letter_head/letter_head.txt
  8. +3
    -3
      cgi-bin/core/doctype/module_def/module_def.py
  9. +2
    -2
      cgi-bin/core/doctype/module_def_item/module_def_item.txt
  10. +2
    -2
      cgi-bin/core/doctype/module_def_role/module_def_role.txt
  11. +3
    -3
      cgi-bin/core/doctype/property_setter/property_setter.txt
  12. +3
    -3
      cgi-bin/core/doctype/table_mapper_detail/table_mapper_detail.txt
  13. +2
    -2
      cgi-bin/core/doctype/tag/tag.txt
  14. +3
    -2
      cgi-bin/webnotes/model/__init__.py
  15. +11
    -1
      cgi-bin/webnotes/tests/modules.py
  16. +29
    -13
      cgi-bin/webnotes/utils/transfer.py

+ 3
- 4
cgi-bin/core/doctype/custom_field/custom_field.txt Dosyayı Görüntüle

@@ -3,17 +3,16 @@

# These values are common in all dictionaries
{
'creation': '2010-10-13 16:33:29',
'creation': '2011-07-22 15:56:01',
'docstatus': 0,
'modified': '2011-01-04 14:39:15',
'modified_by': 'umair@iwebnotes.com',
'modified': '2011-07-22 15:56:01',
'modified_by': 'Administrator',
'owner': 'Administrator'
},

# These values are common for all DocType
{
'_last_update': '1305789385',
'allow_trash': 1,
'autoname': 'CustomField.####',
'colour': 'White:FFF',
'description': 'Adds a custom field to a DocType',


+ 3
- 3
cgi-bin/core/doctype/custom_script/custom_script.txt Dosyayı Görüntüle

@@ -3,10 +3,10 @@

# These values are common in all dictionaries
{
'creation': '2010-08-08 17:08:56',
'creation': '2011-07-22 15:56:01',
'docstatus': 0,
'modified': '2010-09-20 14:06:57',
'modified_by': 'yogesh@webnotestech.com',
'modified': '2011-07-22 15:56:01',
'modified_by': 'Administrator',
'owner': 'Administrator'
},



+ 1
- 1
cgi-bin/core/doctype/doctype/doctype.py Dosyayı Görüntüle

@@ -81,7 +81,7 @@ class DocType:
self.change_modified_of_parent()
import webnotes.defs
if not from_import and hasattr(webnotes.defs, 'developer_mode') and webnotes.defs.developer_mode:
if (not from_import) and hasattr(webnotes.defs, 'developer_mode') and webnotes.defs.developer_mode:
self.export_doc()
sql("delete from __DocTypeCache")


+ 2
- 2
cgi-bin/core/doctype/doctype_label/doctype_label.txt Dosyayı Görüntüle

@@ -3,9 +3,9 @@

# These values are common in all dictionaries
{
'creation': '2010-08-08 17:08:59',
'creation': '2011-07-22 15:58:56',
'docstatus': 0,
'modified': '2010-09-20 14:06:57',
'modified': '2011-07-22 15:58:56',
'modified_by': 'Administrator',
'owner': 'Administrator'
},


+ 3
- 3
cgi-bin/core/doctype/doctype_mapper/doctype_mapper.txt Dosyayı Görüntüle

@@ -3,10 +3,10 @@

# These values are common in all dictionaries
{
'creation': '2010-08-08 17:08:59',
'creation': '2011-07-22 15:58:57',
'docstatus': 0,
'modified': '2010-12-21 12:37:08',
'modified_by': 'sneha@webnotestech.com',
'modified': '2011-07-22 15:58:57',
'modified_by': 'Administrator',
'owner': 'Administrator'
},



+ 3
- 3
cgi-bin/core/doctype/field_mapper_detail/field_mapper_detail.txt Dosyayı Görüntüle

@@ -3,10 +3,10 @@

# These values are common in all dictionaries
{
'creation': '2010-08-08 17:09:02',
'creation': '2011-07-22 15:58:57',
'docstatus': 0,
'modified': '2010-09-20 14:06:57',
'modified_by': 'sneha@webnotestech.com',
'modified': '2011-07-22 15:58:58',
'modified_by': 'Administrator',
'owner': 'Administrator'
},



+ 2
- 2
cgi-bin/core/doctype/letter_head/letter_head.txt Dosyayı Görüntüle

@@ -3,9 +3,9 @@

# These values are common in all dictionaries
{
'creation': '2010-12-14 10:23:15',
'creation': '2011-07-22 15:58:58',
'docstatus': 0,
'modified': '2011-03-21 11:06:41',
'modified': '2011-07-22 15:58:58',
'modified_by': 'Administrator',
'owner': 'Administrator'
},


+ 3
- 3
cgi-bin/core/doctype/module_def/module_def.py Dosyayı Görüntüle

@@ -21,7 +21,7 @@ class DocType:
def __init__(self,d,dl):
self.doc, self.doclist = d,dl
def on_update(self):
def generate_children(self):
if not getlist(self.doclist,'items') and not self.doc.widget_code:
obj = Document(self.doc.doctype, self.doc.name)
@@ -42,9 +42,9 @@ class DocType:
r.display_name = d[1]
r.save(1)

def on_update(self):
def on_update(self, from_update=0):
import webnotes.defs
if hasattr(webnotes.defs, 'developer_mode') and webnotes.defs.developer_mode:
if (not from_update) and hasattr(webnotes.defs, 'developer_mode') and webnotes.defs.developer_mode:
from webnotes.modules.export_module import export_to_files
export_to_files(record_list=[[self.doc.doctype, self.doc.name]])

+ 2
- 2
cgi-bin/core/doctype/module_def_item/module_def_item.txt Dosyayı Görüntüle

@@ -3,9 +3,9 @@

# These values are common in all dictionaries
{
'creation': '2010-08-08 17:09:10',
'creation': '2011-07-22 15:59:00',
'docstatus': 0,
'modified': '2010-10-04 11:58:48',
'modified': '2011-07-22 15:59:00',
'modified_by': 'Administrator',
'owner': 'Administrator'
},


+ 2
- 2
cgi-bin/core/doctype/module_def_role/module_def_role.txt Dosyayı Görüntüle

@@ -3,9 +3,9 @@

# These values are common in all dictionaries
{
'creation': '2010-08-08 17:09:10',
'creation': '2011-07-22 15:59:00',
'docstatus': 0,
'modified': '2010-09-20 14:06:57',
'modified': '2011-07-22 15:59:00',
'modified_by': 'Administrator',
'owner': 'Administrator'
},


+ 3
- 3
cgi-bin/core/doctype/property_setter/property_setter.txt Dosyayı Görüntüle

@@ -3,9 +3,9 @@

# These values are common in all dictionaries
{
'creation': '2011-05-18 17:29:36',
'creation': '2011-07-22 15:59:12',
'docstatus': 0,
'modified': '2011-07-06 09:45:10',
'modified': '2011-07-22 15:59:12',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
@@ -209,4 +209,4 @@
'label': 'Default Value',
'no_column': 0
}
]
]

+ 3
- 3
cgi-bin/core/doctype/table_mapper_detail/table_mapper_detail.txt Dosyayı Görüntüle

@@ -3,10 +3,10 @@

# These values are common in all dictionaries
{
'creation': '2010-08-08 17:09:26',
'creation': '2011-07-22 15:59:13',
'docstatus': 0,
'modified': '2010-09-20 14:06:57',
'modified_by': 'sneha@webnotestech.com',
'modified': '2011-07-22 15:59:13',
'modified_by': 'Administrator',
'owner': 'Administrator'
},



+ 2
- 2
cgi-bin/core/doctype/tag/tag.txt Dosyayı Görüntüle

@@ -3,9 +3,9 @@

# These values are common in all dictionaries
{
'creation': '2010-08-08 17:09:26',
'creation': '2011-07-22 15:59:13',
'docstatus': 0,
'modified': '2010-09-20 14:06:57',
'modified': '2011-07-22 15:59:13',
'modified_by': 'Administrator',
'owner': 'Administrator'
},


+ 3
- 2
cgi-bin/webnotes/model/__init__.py Dosyayı Görüntüle

@@ -36,7 +36,7 @@ def check_if_doc_is_linked(dt, dn):
webnotes.msgprint("Cannot delete %s <b>%s</b> because it is linked in %s <b>%s</b>" % (dt, dn, link_dt, item[0][0]), raise_exception=1)


def delete_doc(doctype=None, name=None, doclist = None):
def delete_doc(doctype=None, name=None, doclist = None, force=0):
"""
Deletes a doc(dt, dn) and validates if it is not submitted and not linked in a live record
"""
@@ -74,7 +74,8 @@ def delete_doc(doctype=None, name=None, doclist = None):
obj.on_trash()
# check if links exist
check_if_doc_is_linked(doctype, name)
if not force:
check_if_doc_is_linked(doctype, name)
try:
webnotes.conn.sql("delete from `tab%s` where name='%s' limit 1" % (doctype, name))


+ 11
- 1
cgi-bin/webnotes/tests/modules.py Dosyayı Görüntüle

@@ -64,9 +64,19 @@ class ModuleTest(unittest.TestCase):
webnotes.conn.rollback()
webnotes.conn.sql("drop trigger if exists sandbox_trigger")
self.update_timestamp('doctype/sandbox/my_trigger.sql')
data = Module('core').get_file('doctype','sandbox','my_trigger.sql').sync()
Module('core').get_file('doctype','sandbox','my_trigger.sql').sync()
self.assertTrue(webnotes.conn.sql("show triggers like 'tabSandbox'")[0][0]=='sandbox_trigger')
def test_sync_all(self):
"""
Test sync all (rerun the sql file test calling sync_all)
"""
webnotes.conn.rollback()
webnotes.conn.sql("drop trigger if exists sandbox_trigger")
self.update_timestamp('doctype/sandbox/my_trigger.sql')
Module('core').sync_all()
self.assertTrue(webnotes.conn.sql("show triggers like 'tabSandbox'")[0][0]=='sandbox_trigger')
def tearDown(self):
if webnotes.conn.in_transaction:
webnotes.conn.rollback()

+ 29
- 13
cgi-bin/webnotes/utils/transfer.py Dosyayı Görüntüle

@@ -1,7 +1,23 @@
"""
Merges (syncs) incoming doclist into the database
Called when:
importing .txt files
importing bulk records from .csv files
For regular types, deletes the record and recreates it
for special types: `DocType`, `Module Def`, `DocType Mapper` there are subclasses
To use::
set_doc(doclist, ovr=1, ingore=1, noupdate=1)
"""

import webnotes
from webnotes.model.doc import Document

def set_doc(doclist, ovr=0, ignore=1, onupdate=1):
"""
Wrapper function to sync a record
"""
dt = doclist[0]['doctype']
if webnotes.conn.exists(doclist[0]['doctype'], doclist[0]['name']):
@@ -69,9 +85,7 @@ class UpdateDocument:
# delete existing
def delete_existing(self):
from webnotes.model import delete_doc
webnotes.conn.sql("set foreign_key_checks=0")
delete_doc(self.doc.doctype, self.doc.name)
webnotes.conn.sql("set foreign_key_checks=1")
delete_doc(self.doc.doctype, self.doc.namem, force=1)

# update modified timestamp
def update_modified(self):
@@ -99,10 +113,6 @@ class UpdateDocument:
so.on_update()



#
# "Merge incoming doctype"
#
class UpdateDocumentMerge(UpdateDocument):
def __init__(self, in_doclist):
self.to_update_doctype = []
@@ -262,10 +272,10 @@ class UpdateDocType(UpdateDocumentMerge):
so.on_update(from_import=1)


#
# update module def
#
class UpdateModuleDef(UpdateDocumentMerge):
"""
Merge `Module Def`
"""
def __init__(self, in_doclist):
UpdateDocumentMerge.__init__(self, in_doclist)
self.to_update_doctype = ['Module Def', 'Module Def Item']
@@ -282,12 +292,18 @@ class UpdateModuleDef(UpdateDocumentMerge):
if d.doctype=='Module Def':
return webnotes.conn.sql("select module_seq, disabled, is_hidden from `tabModule Def` where name=%s", d.name, as_dict = 1)[0]

def run_on_update(self):
from webnotes.model.code import get_server_obj
so = get_server_obj(self.doc, self.doclist)
print str(dir(so))
if hasattr(so, 'on_update'):
so.on_update(from_update=1)


#
# update module def
#
class UpdateDocTypeMapper(UpdateDocumentMerge):
"""
Merge `DocType Mapper`
"""
def __init__(self, in_doclist):
UpdateDocumentMerge.__init__(self, in_doclist)
self.to_update_doctype = ['Field Mapper Detail', 'Table Mapper Detail']


Yükleniyor…
İptal
Kaydet