def logic(self):
     form = self.form
     action = form['action']
     image = form['image']
     uri = form['uri']
     form['action'] = 'check'
     num = form['num']
     path = htdocs_dir + '/data/' + 'spec.xml'
     res = etree.fromstring(open(path, 'r').read())
     trackList = res.xpath('//trackList')[0]
     playlist = res.xpath('//playlist')[0]
     if action == 'check':
         if uri and image is not None and not num:
             filename = image.filename
             if re.match(r"^[a-zA-Z]+[0-9a-zA-Z]*(?:\.[0-9a-zA-Z]+)?$",
                         filename) is None:
                 self.errors.append(
                     u'Название файла должно содеражать латинские буквы и цифры.'
                 )
                 return
             f = image.file
             img = Image.open(f)
             img.save(htdocs_dir + '/data/' + filename)
             trackList.append(
                 E.track(E.location('http://peshca.ru/data/' + filename),
                         E.info(uri),
                         num=filename))
             self.results.append(u'Запись успешно добавлена')
         elif num:
             if image is not None:
                 filename = image.filename
                 if re.match(r"^[a-z]+[0-9a-z]*(?:\.[0-9a-z]+)?$",
                             filename) is None:
                     self.errors.append(
                         u'Название файла должно содеражать латинские буквы и цифры.'
                     )
                     return
                 f = image.file
                 img = Image.open(f)
                 img.save(htdocs_dir + '/data/' + filename)
             else:
                 filename = ''
             playlist.append(
                 E.action(act='1', info=uri, location=filename, num=num))
     elif action == 'delete':
         playlist.append(E.action(num=num))
         self.results.append(u'Запись успешно удалена')
     xslt = StringIO(_spec)
     parser = etree.parse(xslt)
     result = etree.XSLT(parser)
     res = result(res)
     tmp = htdocs_dir + '/data/' + '_tmp.xml'
     fn = open(tmp, 'w')
     fn.write(etree.tostring(res))
     fn.close()
     os.rename(tmp, path)
     return
 def data(self, dbconn):
     form = self.form
     ajax = [
         E.oper(E.group(group_info, id=str(r.group_id)),
                E.auth_name(r.auth_name),
                E.lastname(r.lastname),
                E.firstname(r.firstname),
                E.middlename(r.middlename),
                E.email(r.email),
                E.phones(r.phones),
                E.info(r.info),
                id=str(r.oper_id)) for r, group_info in dbconn.query(
                    Distrib_oper, Admin_group.group_info).filter(
                        Distrib_oper.group_id == Admin_group.group_id)
     ]
     return E.ajax(*ajax)
 def data(self, dbconn):
     form = self.form
     group_kwds = dict(((r.group_kw, '1')
                        for r in dbconn.query(Admin_groupkw).filter(
                            Admin_groupkw.group_id == form['group_id'])))
     oper_kwds = dict(((r.group_kw, r.group_include)
                       for r in dbconn.query(Admin_operkw).filter(
                           Admin_operkw.oper_id == form['oper_id'])))
     ajax = []
     for kw, kw_info, kw_help in dbconn.query(
             Urlmapkw_info.url_kw,
             Urlmapkw_info.kw_info,
             Urlmapkw_info.kw_help,
     ).order_by(Urlmapkw_info.url_kw):
         ajax.append(
             E.kw(E.info(kw_info),
                  E.comment(kw_help),
                  E.group(group_kwds.pop(kw, '0')),
                  E.oper(oper_kwds.pop(kw, 'default')),
                  name=kw))
     return E.ajax(*ajax)
 def E_data(self):
     dbconn = self.dbconn
     try:
         uri = dbconn.query(Info_page.uri).filter(
             Info_page.info_page_id == self.form['info_page_id']).one()[0]
         f = open(htdocs_dir + '/pages/' + uri + '.html', 'r')
         text = f.read().replace('\n', " ").replace("'", '"')
         f.close()
         if not text:
             text = 'Текст статьи'
     except sqlalchemy.orm.exc.NoResultFound:
         sys.exc_clear()
         text = 'Текст статьи'
     info = dbconn.query(Info_page)
     data = E.data(text=text.decode('utf-8'))
     data_tag = data.xpath('//data')[0]
     for p in info:
         data_tag.append(
             E.info(info_page_id=str(p.info_page_id),
                    name=p.name,
                    uri=p.uri,
                    category_id=str(p.category_id),
                    weight=str(p.weight)))
     return data