Guido Draheim avatar Guido Draheim committed 44e6cab

delete old singular recording times

Comments (0)

Files changed (4)

src/dvbcronrecording/core.py

         if page in [ 'delete' ]:
             req.perm.assert_permission(LIST_DELETE)
             message = self._recordings_delete(req)
+        if page in [ 'deleteold' ]:
+            req.perm.assert_permission(LIST_DELETE)
+            message = self._recordings_delete_old(req)
         
         # database commit and return page content
         commit()
         q = q.filter_by(id = req.args.get("id"))
         q.delete()
 
+    """
+      Deletes entry from recordings that have a single day for
+      recording in last weeks (older in this month or being in last month) 
+    """
+    def _recordings_delete_old(self, req):
+        deleted = []
+        make = re.compile("^(\d+)[.](\d+).*")
+        today = datetime.datetime.now()
+        this_month = today.month
+        last_month = this_month - 1
+        if last_month == 0: last_month = 12
+        prev_month = last_month - 1
+        if prev_month == 0: prev_month = 12
+        session = db_cnx(self.env) 
+        q = session.query(RecordingList).filter(RecordingList.onlydate.like("%.%"))
+        for item in q.all():
+            m = make.match(item.onlydate)
+            if m:
+                day = int(m.group(1))
+                month = int(m.group(2))
+                if month == this_month and day < today.day:
+                    deleted += [ item.id ]
+                    session.delete(item)
+                if month == last_month or month == prev_month:
+                    deleted += [ item.id ]
+                    session.delete(item)
+        # commit is done in parent
+        return "[%s]" % (",".join([ str(item) for item in deleted]))
 
     # ---------------------------------------------------------------
     # old-style format

src/dvbcronrecording/dvbcronrecording.de.po

 
 msgid " previous moved after next recording - swapped around,"
 msgstr " vorige verschoben hinter nächste Aufname - vertauscht,"
+
+msgid "delete old singular recording times"
+msgstr " [Lösche veraltete Einzelaufnahmezeiten] "

src/dvbcronrecording/htdocs/css/recordinglist.css

                 background-color: #DDD; padding: 1px 14px; }
 .actionform div { display: inline } /* Trac specific */
 
+.recordinglist .deleteold { padding : 2em; }
+
 .recordinglist .new { font-weight: bold; color: #040; }
 .recordinglist th { text-align: left; border-bottom: 1px dotted black; font-size: small; font-weight: bold; }
 .recordinglist .id { width: 2em; text-align: right; padding-right: 0.5em; font-size: small; }

src/dvbcronrecording/templates/recordinglist.html

     </form>
   </div>
   </table>
+  <div>
+    <div class="deleteold">
+      <a href="${href.recording('deleteold')}">${_('delete old singular recording times')}</a>
+     </div>
+  </div>
 </div>
 <script><!--
 function parentsUntil(node, selector) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.