Exploring the opportunity with proteus script and have some problem:
from proteus import config, Model, Wizard, Report
logger.info('Connecting to DB...')
config = config.set_trytond('my_database', config_file='/etc/trytond.conf')
logger.info('Picking Images table')
TrytonImage = Model.get('mymodule.image') # Class with all images
def main():
try:
directory = r'./static'
logger.info('Searching for all images...')
for filename in os.listdir(directory):
if filename.endswith(".svg"):
search_domain = ['OR',[('filename', 'like', f'{filename[:-4]}.jpg')],[('filename', 'like', f'{filename[:-4]}.png')]]
image_ids = TrytonImage.find(search_domain) #
if len(image_ids)>0:
image_record = image_ids[0]
svg_filename_with_path = os.path.join(directory,filename)
image_record.svg_filename = filename
with open(svg_filename_with_path,'rb') as f:
image_record.svg_image = f.read()
logger.info('Copied svg data to the record...')
try:
image_record.save() # Finally save the record
logger.info(f'Record {image_record.id} saved to DB successfully.')
except Exception as e:
logger.warning(e)
logger.info('Image record was updated with SVG data successfully.')
While a couple of records are updated successfully, others throw the Error:
You are not allowed to access “Image in mymodule”. -
And I have no idea what is the problem. I tried to update/delete it manually — it works fine.
Also, I don’t understand if I need a config.set_context(??WHAT IS HERE??
).
And if so — how?