Commits

Guido Draheim committed d9237cf

fix channels.conf edit

Comments (0)

Files changed (3)

src/dvbcronrecording/channelsconf.py

     # Public methods
     #
 
-    implements(IPermissionRequestor, ITemplateProvider,  IRequestHandler)
+    implements(IPermissionRequestor, ITemplateProvider, IRequestHandler)
 
     # IPermissionRequestor methods
 
             data['adapterlist'] = self._adapter_list(req)
             data['text'] = self.loadtext(req)
             data['_'] = translate
-            add_stylesheet(req, PACKAGE+'/css/recordingchannelsconf.css')
-            add_stylesheet(req, PACKAGE+'/css/dvbcronrecording.css')
+            add_stylesheet(req, PACKAGE + '/css/recordingchannelsconf.css')
+            add_stylesheet(req, PACKAGE + '/css/dvbcronrecording.css')
             add_script(req, 'common/js/trac.js')
             return ('channelsconf_editor.html', data, None)
         if page in [ "edit" ]:
             data['adapterlist'] = self._adapter_list(req)
             data['text'] = self.loadtext(req)
             data['_'] = translate
-            add_stylesheet(req, PACKAGE+'/css/recordingchannelsconf.css')
-            add_stylesheet(req, PACKAGE+'/css/dvbcronrecording.css')
+            add_stylesheet(req, PACKAGE + '/css/recordingchannelsconf.css')
+            add_stylesheet(req, PACKAGE + '/css/dvbcronrecording.css')
             add_script(req, 'common/js/trac.js')
             return ('channelsconf_editor.html', data, None)
         if page in [ "take", "takeover" ]:
             data['_'] = translate
             data['urlencode'] = urlencode
             data['q'] = q
-            add_stylesheet(req, PACKAGE+'/css/recordingchannelsconf.css')
-            add_stylesheet(req, PACKAGE+'/css/dvbcronrecording.css')
+            add_stylesheet(req, PACKAGE + '/css/recordingchannelsconf.css')
+            add_stylesheet(req, PACKAGE + '/css/dvbcronrecording.css')
             add_script(req, 'common/js/trac.js')
             return ('channelsconf_take.html', data, None)
         
         commit()
 
         add_stylesheet(req, 'common/css/wiki.css')
-        add_stylesheet(req, PACKAGE+'/css/recordingchannelsconf.css')
-        add_stylesheet(req, PACKAGE+'/css/dvbcronrecording.css')
+        add_stylesheet(req, PACKAGE + '/css/recordingchannelsconf.css')
+        add_stylesheet(req, PACKAGE + '/css/dvbcronrecording.css')
         add_script(req, 'common/js/trac.js')
         add_script(req, 'common/js/wikitoolbar.js')
         
         newchannels_list = self._newchannels_list(req)
         channels_list = self._channelsconf_list(req, channeltype)
         channeltypelist = ["all channel types",
-                           "data channels", 
-                           "radio channels", 
+                           "data channels",
+                           "radio channels",
                            "video channels"]
 
         # passing variables to template
         data["channeltype"] = channeltype
         data["channeltypelist"] = channeltypelist
         data['new_datalist'] = newchannels_list
-        data['_selection'] = "channeltype="+quote2(channeltype)
+        data['_selection'] = "channeltype=" + quote2(channeltype)
         data["_pagenum"] = req.args.get("_pagenum", "0")
         data["_pagesize"] = req.args.get("_pagesize", "10")
         data['datalist'] = Paginator(channels_list, int(data["_pagenum"]), int(data["_pagesize"]))
     """
       Returns list of the adapter settings
     """
-    def _adapter_list(self, req, defaults = [ 0 ]):
+    def _adapter_list(self, req, defaults=[ 0 ]):
         return tuning_adapter_list(self.env, defaults)
     
     """
       Returns list of the channels.conf
     """
-    def _channelsconf_selectby(self, req, selectby = ['adapter', 'title']):
+    def _channelsconf_selectby(self, req, selectby=['adapter', 'title']):
         session = db_cnx(self.env)
         q = session.query(RecordingChannelsConf)
         for col in selectby:
         return q.all()
     
     def _newchannels_list(self, req):
-        _ = ['adapter', 'title','frequency','polarity','source','symbolrate','vpid', 'apid', 'tpid']
+        _ = ['adapter', 'title', 'frequency', 'polarity', 'source', 'symbolrate', 'vpid', 'apid', 'tpid']
         translate = Translate(PACKAGE, req.locale)
         defs = {}
         defs["adapter"] = req.args.get("adapter", "0")
     """
       Returns list of the channels.conf
     """
-    def _channelsconf_list(self, req, channeltype = None):
+    def _channelsconf_list(self, req, channeltype=None):
         session = db_cnx(self.env)
         q = session.query(RecordingChannelsConf)
         q = q.order_by("title", "adapter", "source")
     """
       Appends a new entry into channels.conf list
     """
-    def _channelsconf_append(self, req):
+    def _channelsconf_append(self, req, session=None):
         item = RecordingChannelsConf()
-        item.adapter = req.args.get("adapter","0")
+        item.adapter = req.args.get("adapter", "0")
         item.frequency = req.args.get("frequency")
         item.polarity = req.args.get("polarity")
         item.source = req.args.get("source")
         item.vpid = req.args.get("vpid")
         item.apid = req.args.get("apid")
         item.tpid = req.args.get("tpid")
-        item.title = req.args.get("newtitle")
+        item.title = req.args.get("newtitle", req.args.get("title"))
         value = "%s:%s" % (item.adapter, item.title)
-        session = db_cnx(self.env)
-        session.add(item)
-        session.flush() 
-        return "OK(%s)"+value
+        if session:
+            session.add(item)
+        else:
+            session = db_cnx(self.env)
+            session.add(item)
+            session.flush() 
+        return "OK(%s)" % value
 
     """
       Updates an entry in the channels.conf list
 
     # ---------------------------------------------------------------
     def savetext(self, req, text):
-        if not req.args.has_key("adapter"):
+        if not req.args.get("adapter"):
             return "no adapter given in update"
         session = db_cnx(self.env)
         adapter = req.args["adapter"]
-        sql = "DELETE FROM recording_channelsconf WHERE adapter = %s"
-        session.execute(sql, adapter)
+        q = session.query(RecordingChannelsConf).filter_by(adapter=adapter)
+        q.delete()
+        session.flush()
         msg = []
         for line in text.split("\n"):
-            msg += [ self.savetextline(req, unicode(line)) ]
+            textline = unicode(line.strip())
+            if textline:
+                msg += [ self.savetextline(req, textline, session) ]
+        session.flush()
         return "(%s lines = %s)" % (len(msg), str(msg))
-    def savetextline(self, req, line):
-        cols = ["title", "frequency", "polarity", "source", "symbolrate", "vpid","apid","tpid"]
+    def savetextline(self, req, line, session=None):
+        cols = ["title", "frequency", "polarity", "source", "symbolrate", "vpid", "apid", "tpid"]
         # VIVA PLUS:12551:v:0:22000:171:172:12120
-        m = re.match(r"([^:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]+)", line)
+        m = re.match(r"([^:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]+)\s*", line)
         if m:
             vals = m.groups()
             for n in xrange(len(cols)):
                     val = vals[n]
                     if val: val = val.strip()
                     req.args[ cols[n] ] = val
-            return self._channelsconf_append(req)
+            return self._channelsconf_append(req, session)
         else:
-            return "NO."
+            return "NO('%s')" % line.strip()
     def loadtext(self, req):
         return "\n".join(list(self.loadtextlines(req)))
     def loadtextlines(self, req):
-        cols = ["title", "frequency", "polarity", "source", "symbolrate", "vpid","apid","tpid"]
         entries = self._channelsconf_list(req)
         for entry in entries:
-            vals = []
-            for col in cols:
-                vals += [ ustr(getattr(entry, col))]
-            yield (":".join(vals))
+            val = "%s:%s:%s:%s:%s:%s:%s:%s" % (
+                    entry.title or "",
+                    entry.frequency or "",
+                    entry.polarity or "",
+                    entry.source or "",
+                    entry.symbolrate or "",
+                    entry.vpid or "",
+                    entry.apid or "",
+                    entry.tpid  or "")
+            yield val

src/dvbcronrecording/templates/channelsconf_editor.html

   <div class="actionlist">
           <form method="get" action="${href.recording('channelsconf/list')}" class="actionform">
             <select name="adapter">
-                <option py:for="adapter in sorted(adapterlist)" 
-                        value="${adapter}">
-                        ${adapter}
+                <option py:for="adapter1 in sorted(adapterlist)" 
+                        selected="${adapter1 == adapter or None}" 
+                        value="${adapter1}">
+                        ${adapter1}
                 </option>
             </select>
             <input type="submit" value="${_('channel.conf list')}" class="actionbutton"></input>
           </form>
           <form method="get" action="${href.recording('channelsconf/edit')}" class="actionform">
             <select name="adapter">
-                <option py:for="adapter in sorted(adapterlist)" 
-                        value="${adapter}">
-                        ${adapter}
+                <option py:for="adapter1 in sorted(adapterlist)" 
+                        selected="${adapter1 == adapter or None}" 
+                        value="${adapter1}">
+                        ${adapter1}
                 </option>
             </select>
             <input type="submit" value="${_('channels.conf edit')}" class="actionbutton"></input>
   <input type="submit" value="SAVE"></input>
   <label for="adapter">${_("adapter")}:</label>
   <select name="adapter">
-      <option py:for="adapter in sorted(adapterlist)" 
-            value="${adapter}">
-             ${adapter}
+      <option py:for="adapter1 in sorted(adapterlist)"
+            selected="${adapter1 == adapter or None}" 
+            value="${adapter1}">
+             ${adapter1}
       </option>
   </select>
 

src/dvbcronrecording/templates/channelsconf_list.html

        </td>
       <td class="adapter"><select name="adapter">
                 <option py:for="adapter1 in sorted(adapterlist)" 
-                        selected="${adapter1 == adapter or None}" 
+                        selected="${adapter1 == item.adapter or None}" 
                         value="${adapter1}">
                         ${adapter1}
         </option></select>