| 1 | <?xml version="1.0" encoding="UTF-8"?>
|
|---|
| 2 | <dictionary>
|
|---|
| 3 | <item key="custom"/>
|
|---|
| 4 | <item key="data"><![CDATA[# Import a standard function, and get the HTML request and response objects.
|
|---|
| 5 | from Products.PythonScripts.standard import html_quote
|
|---|
| 6 | request = container.REQUEST
|
|---|
| 7 | RESPONSE = request.RESPONSE
|
|---|
| 8 |
|
|---|
| 9 | def absattr(v):
|
|---|
| 10 | try:
|
|---|
| 11 | return v()
|
|---|
| 12 | except:
|
|---|
| 13 | return v
|
|---|
| 14 |
|
|---|
| 15 | print context.manage_page_header(context,request)
|
|---|
| 16 | print context.manage_tabs(context,request)
|
|---|
| 17 | print context.f_headline(context,headline='<big><img src="%swand.png" align="absmiddle" border="0"/> Import Template-Set...</big>'%context.MISC_ZMS)
|
|---|
| 18 | print '<form method="post" enctype="multipart/form-data">'
|
|---|
| 19 | print '<input type="hidden" name="form_id" value="manage_addMultiUpload"/>'
|
|---|
| 20 | print '<input type="hidden" name="lang" value="%s"/>'%request['lang']
|
|---|
| 21 | print context.zmi_form_section_begin(context,request)
|
|---|
| 22 |
|
|---|
| 23 | # --- Display contents of zip-file.
|
|---|
| 24 | # ---------------------------------
|
|---|
| 25 | if request.form.get('btn')==context.getZMILangStr('BTN_IMPORT') and request.form.get('file'):
|
|---|
| 26 | file = request['file']
|
|---|
| 27 | temp_id = request.SESSION.getId()+'_'+request['form_id']
|
|---|
| 28 | temp_folder = context.temp_folder
|
|---|
| 29 | files = context.getZipArchive(file)
|
|---|
| 30 | containers = []
|
|---|
| 31 | print '<input type="hidden" name="temp_id" value="%s"/>'%temp_id
|
|---|
| 32 | print '<input type="hidden" name="temp_filename" value="%s"/>'%file.filename
|
|---|
| 33 | if temp_id in context.temp_folder.objectIds():
|
|---|
| 34 | getattr(temp_folder,temp_id).manage_upload(file)
|
|---|
| 35 | else:
|
|---|
| 36 | temp_folder.manage_addFile(id=temp_id,title=file.filename,file=file)
|
|---|
| 37 | print '<tr valign="top">'
|
|---|
| 38 | print '<td class="form-label"><strong><img src="%smime_type.application_zip.gif" alt="" border="0" align="absmiddle"/> %s</strong><br/>(%s, %i %s)</td>'%(context.MISC_ZMS,file.filename,context.getDataSizeStr(getattr(temp_folder,temp_id).size),len(files),context.getZMILangStr('ATTR_OBJECTS'))
|
|---|
| 39 | print '<td class="form-small neutralColorWhite">'
|
|---|
| 40 | root = None
|
|---|
| 41 | standard_html = None
|
|---|
| 42 | for file in context.sort_list(files,'local_filename'):
|
|---|
| 43 | base = file['local_filename'][:-len(file['filename'])-1]
|
|---|
| 44 | if root is None:
|
|---|
| 45 | root = file['local_filename'][:max(file['local_filename'].rfind('/'),file['local_filename'].rfind('\\'))]
|
|---|
| 46 | file_id = file['local_filename'][len(root):]
|
|---|
| 47 | if file['isdir']:
|
|---|
| 48 | containers.append(file['local_filename'])
|
|---|
| 49 | icon = '/misc_/OFSP/Folder_icon.gif'
|
|---|
| 50 | print '<div><input type="checkbox" name="ids:list" value="%s" checked="checked"/><img src="%s" alt="" border="0" align="absmiddle"/> %s</div>'%(file_id,icon,file['filename'])
|
|---|
| 51 | print '<div style="margin-left:20px;">'
|
|---|
| 52 | else:
|
|---|
| 53 | if containers:
|
|---|
| 54 | if base != containers[-1]:
|
|---|
| 55 | containers.remove(containers[-1])
|
|---|
| 56 | print '</div>'
|
|---|
| 57 | icon = '/misc_/OFSP/File_icon.gif'
|
|---|
| 58 | if file['content_type'] == 'text/html':
|
|---|
| 59 | icon = '/misc_/PageTemplates/zpt.gif'
|
|---|
| 60 | elif file['content_type'].startswith('image/'):
|
|---|
| 61 | icon = '/misc_/OFSP/Image_icon.gif'
|
|---|
| 62 | print '<div>'
|
|---|
| 63 | print '<input type="checkbox" name="ids:list" value="%s" checked="checked"/><img src="%s" alt="" border="0" align="absmiddle"/> %s (%s)'%(file_id,icon,file['filename'],context.getDataSizeStr(file['size']))
|
|---|
| 64 | if len(containers) == 0 and file['content_type'] == 'text/html':
|
|---|
| 65 | print '<input type="radio" name="standard_html" value="%s"'%file_id
|
|---|
| 66 | if standard_html is None:
|
|---|
| 67 | print ' checked="checked"'
|
|---|
| 68 | standard_html = 1
|
|---|
| 69 | print '> <em>standard_html</em>'
|
|---|
| 70 | print '</div>'
|
|---|
| 71 | for base in containers:
|
|---|
| 72 | print '</div>'
|
|---|
| 73 | print '</tr>'
|
|---|
| 74 | print '<tr valign="middle">'
|
|---|
| 75 | print '<td> </td>'
|
|---|
| 76 | print '<td>'
|
|---|
| 77 | print '<input class="ui-button ui-state-default ui-corner-all" name="btn" type="submit" value="%s">'%context.getZMILangStr('BTN_IMPORT')
|
|---|
| 78 | print '<input class="ui-button ui-state-default ui-corner-all" name="btn" type="submit" value="%s">'%context.getZMILangStr('BTN_CANCEL')
|
|---|
| 79 | print '</td>'
|
|---|
| 80 | print '</tr>'
|
|---|
| 81 |
|
|---|
| 82 | # --- Import contents of zip-file.
|
|---|
| 83 | # ---------------------------------
|
|---|
| 84 | elif request.form.get('btn')==context.getZMILangStr('BTN_IMPORT') and request.form.get('temp_id'):
|
|---|
| 85 | temp_id = request['temp_id']
|
|---|
| 86 | temp_filename = request['temp_filename']
|
|---|
| 87 | temp_folder = context.temp_folder
|
|---|
| 88 | message = []
|
|---|
| 89 | files = context.getZipArchive(str(getattr(temp_folder,temp_id).data))
|
|---|
| 90 | containers = {}
|
|---|
| 91 | root = None
|
|---|
| 92 | c = 0
|
|---|
| 93 | for file in context.sort_list(files,'local_filename'):
|
|---|
| 94 | base = file['local_filename'][:-len(file['filename'])-1]
|
|---|
| 95 | if root is None:
|
|---|
| 96 | root = file['local_filename'][:max(file['local_filename'].rfind('/'),file['local_filename'].rfind('\\'))]
|
|---|
| 97 | file_id = file['local_filename'][len(root):]
|
|---|
| 98 | if file_id in request.form.get('ids',[]):
|
|---|
| 99 | container = containers.get(base,context.getHome())
|
|---|
| 100 | id = file['filename']
|
|---|
| 101 | title = ''
|
|---|
| 102 | if file['isdir']:
|
|---|
| 103 | container.manage_addFolder(id=id,title=title)
|
|---|
| 104 | containers[file['local_filename']] = getattr(container,id)
|
|---|
| 105 | elif file_id == request.get('standard_html') and file['content_type'] == 'text/html':
|
|---|
| 106 | id = 'standard_html'
|
|---|
| 107 | text = str(file['data'])
|
|---|
| 108 | container.manage_addProduct['PageTemplates'].manage_addPageTemplate(id=id,title=title,text=text)
|
|---|
| 109 | elif file['content_type'].startswith('image/'):
|
|---|
| 110 | container.manage_addImage(id=id,title=title,file=file['data'])
|
|---|
| 111 | else:
|
|---|
| 112 | container.manage_addFile(id=id,title=title,file=file['data'])
|
|---|
| 113 | c += 1
|
|---|
| 114 | message.append(context.getZMILangStr('MSG_IMPORTED')%temp_filename+' [%i/%i]'%(c,len(files)))
|
|---|
| 115 | request.response.redirect(context.url_append_params('%s/manage_main'%context.absolute_url(),{'lang':request['lang'],'manage_tabs_message':'<br/>'.join(message)}))
|
|---|
| 116 |
|
|---|
| 117 | # --- Display initial import form.
|
|---|
| 118 | # ---------------------------------
|
|---|
| 119 | else:
|
|---|
| 120 |
|
|---|
| 121 | if request.form.get('btn')==context.getZMILangStr('BTN_DELETE') and request.get('ids'):
|
|---|
| 122 | context.getHome().manage_delObjects(ids=request['ids'])
|
|---|
| 123 |
|
|---|
| 124 | # Init exclude-ids.
|
|---|
| 125 | excl_ids = [context.getDocumentElement().id, 'acl_users', 'bodyContent_PagePre', 'bodyContent_PagePost', 'index_html', ]
|
|---|
| 126 | # Add content-object artefacts to exclude-ids.
|
|---|
| 127 | for metaObjId in context.getMetaobjIds():
|
|---|
| 128 | for metaObjAttrId in context.getMetaobjAttrIds( metaObjId):
|
|---|
| 129 | metaObjAttr = context.getMetaobjAttr(metaObjId,metaObjAttrId)
|
|---|
| 130 | if metaObjAttr['type'] in context.metaobj_manager.valid_zopetypes:
|
|---|
| 131 | excl_ids.append( metaObjAttrId)
|
|---|
| 132 | c = 0
|
|---|
| 133 | for ob in context.getHome().objectValues():
|
|---|
| 134 | ob_id = absattr(ob.id)
|
|---|
| 135 | ob_icon = absattr(ob.icon)
|
|---|
| 136 | if ob_id not in excl_ids:
|
|---|
| 137 | if c == 0:
|
|---|
| 138 | print '<tr valign="top">'
|
|---|
| 139 | print '<td class="form-label"><img src="%s" alt="" border="0" align="absmiddle"/> %s</td>'%(context.getHome().icon,context.getHome().id)
|
|---|
| 140 | print '<td class="form-small neutralColorWhite">'
|
|---|
| 141 | print '<div><input type="checkbox" name="ids:list" value="%s" checked="checked"/><img src="%s" alt="" border="0" align="absmiddle"/> %s</div>'%(ob_id,ob_icon,ob_id)
|
|---|
| 142 | c += 1
|
|---|
| 143 | if c > 0:
|
|---|
| 144 | print '</td>'
|
|---|
| 145 | print '</tr>'
|
|---|
| 146 | print '<tr valign="middle">'
|
|---|
| 147 | print '<td> </td>'
|
|---|
| 148 | print '<td>'
|
|---|
| 149 | print '<input class="ui-button ui-state-default ui-corner-all" name="btn" type="submit" value="%s">'%context.getZMILangStr('BTN_DELETE')
|
|---|
| 150 | print '</td>'
|
|---|
| 151 | print '</tr>'
|
|---|
| 152 | print '<tr valign="middle">'
|
|---|
| 153 | print '<td colspan="2"> </td>'
|
|---|
| 154 | print '</tr>'
|
|---|
| 155 |
|
|---|
| 156 | print '<tr valign="top">'
|
|---|
| 157 | print '<td class="form-label"><img src="%smime_type.application_zip.gif" alt="" border="0" align="absmiddle"/> Template-Set</td>'%(context.MISC_ZMS)
|
|---|
| 158 | print '<td class="form-element">'
|
|---|
| 159 | print '<input class="form-element" name="file" type="file" size="25">'
|
|---|
| 160 | print '<div class="form-small zmiNeutralColorWhite">'
|
|---|
| 161 | print 'You may download a template-set e.g. from <a href="http://www.freecsstemplates.org/css-templates/" target="_blank" class="zmi">http://www.freecsstemplates.org/css-templates/</a>'
|
|---|
| 162 | print '</div>'
|
|---|
| 163 | print '</td>'
|
|---|
| 164 | print '</tr>'
|
|---|
| 165 | print '<tr valign="middle">'
|
|---|
| 166 | print '<td> </td>'
|
|---|
| 167 | print '<td>'
|
|---|
| 168 | print '<input class="ui-button ui-state-default ui-corner-all" name="btn" type="submit" value="%s">'%context.getZMILangStr('BTN_IMPORT')
|
|---|
| 169 | print '<input class="ui-button ui-state-default ui-corner-all" name="btn" type="submit" value="%s">'%context.getZMILangStr('BTN_CANCEL')
|
|---|
| 170 | print '</td>'
|
|---|
| 171 | print '</tr>'
|
|---|
| 172 |
|
|---|
| 173 | # ---------------------------------
|
|---|
| 174 |
|
|---|
| 175 | print context.zmi_form_section_end(context,request)
|
|---|
| 176 | print '</form>'
|
|---|
| 177 | print context.manage_page_footer(context,request)
|
|---|
| 178 |
|
|---|
| 179 | return printed
|
|---|
| 180 | ]]>
|
|---|
| 181 | </item>
|
|---|
| 182 | <item key="description"/>
|
|---|
| 183 | <item key="exec" type="int">0</item>
|
|---|
| 184 | <item key="id"><![CDATA[manage_importTemplateSet]]></item>
|
|---|
| 185 | <item key="meta_type"><![CDATA[Script (Python)]]></item>
|
|---|
| 186 | <item key="meta_types" type="list">
|
|---|
| 187 | <list>
|
|---|
| 188 | <item><![CDATA[ZMS]]></item>
|
|---|
| 189 | </list>
|
|---|
| 190 | </item>
|
|---|
| 191 | <item key="name"><![CDATA[Import Template-Set...]]></item>
|
|---|
| 192 | <item key="roles" type="list">
|
|---|
| 193 | <list>
|
|---|
| 194 | <item><![CDATA[ZMSAdministrator]]></item>
|
|---|
| 195 | </list>
|
|---|
| 196 | </item>
|
|---|
| 197 | </dictionary> |
|---|