]> git.0d.be Git - panikweb-esperanzah.git/commitdiff
python3 bits
authorFrédéric Péters <fpeters@0d.be>
Thu, 26 Sep 2019 12:50:02 +0000 (14:50 +0200)
committerFrédéric Péters <fpeters@0d.be>
Fri, 3 Jan 2020 13:10:47 +0000 (14:10 +0100)
panikweb/paniktags/templatetags/paniktags.py
panikweb/settings.py
panikweb/urls.py
panikweb/views.py

index 61e357a5feab8e4a470657768cd6f70fb58fef57..c7134b588a52e992c2a22bd0301a5495e4a44837 100644 (file)
@@ -3,14 +3,16 @@ import datetime
 import json
 import re
 import time
-import urlparse
-import urllib2
 import uuid
 
 from django import template
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.db.models.query import QuerySet
+from django.utils.encoding import force_text
+from django.utils.http import quote
+from django.utils.six.moves.urllib import parse as urlparse
+
 from datetime import datetime, timedelta
 
 from emissions.models import Emission, Episode, NewsItem, SoundFile, Focus
@@ -243,7 +245,7 @@ def remove_facet(facet_id, url, facet):
         x[0] == 'selected_facets' and x[1] == facet)]
     query = '&'.join(['%s=%s' % x for x in query_string])
     url = urlparse.urlunsplit([scheme, netloc, path, query, None])
-    return unicode(re.sub(r'&page=\d+', '', url), 'utf-8')
+    return force_text(re.sub(r'&page=\d+', '', url), 'utf-8')
 
 @register.filter
 def remove_tag_facet(url, facet):
@@ -264,7 +266,7 @@ def remove_format_facet(url, facet):
 
 
 def append_facet(facet_id, url, facet):
-    facet = urllib2.quote(facet.encode('utf-8'), safe='')
+    facet = quote(facet.encode('utf-8'), safe='')
     if not '?' in url:
         url = url + '?'
     return re.sub(r'&page=\d+', '', url + '&selected_facets=%s_exact:%s' % (facet_id, facet))
index f6cb7bad2e774e03fb963fe0527d8491b854060a..2b542760eb9d918e88fa1bcc92cba00ecc890593 100644 (file)
@@ -239,8 +239,8 @@ JSON_CELL_TYPES = {}
 WEBSITE_BASE_URL = 'http://www.radiopanik.org/'
 
 try:
-    from local_settings import *
-except ImportError, e:
+    from .local_settings import *
+except ImportError as e:
     pass
 
 if DEBUG and DEBUG_TOOLBAR:
index 1444c2f7a60e474d01b12748164f6bab693e2530..5cee0b5b1e228412a3de0e9790bb8d5281f5f20e 100644 (file)
@@ -64,5 +64,5 @@ urlpatterns.append(url(r'', include('combo.public.urls')))
 
 try:
     from local_urls import *
-except ImportError, e:
+except ImportError as e:
     pass
index 5a3110e1e22134775754c83a115d95511207e285..b22d9f531f8e47f24429182b59a433b7ef8b5aba 100644 (file)
@@ -6,11 +6,13 @@ import random
 import os
 import stat
 import time
-import urlparse
 
 from django.core.urlresolvers import reverse
 from django.conf import settings
 from django.http import Http404, JsonResponse
+from django.utils.encoding import force_text
+from django.utils.encoding import python_2_unicode_compatible
+from django.utils.six.moves.urllib import parse as urlparse
 from django.views.decorators.cache import cache_control
 from django.views.generic.base import TemplateView
 from django.views.generic.detail import DetailView
@@ -262,6 +264,7 @@ class ProgramView(TemplateView):
 
 program = ProgramView.as_view()
 
+@python_2_unicode_compatible
 class TimeCell:
     nonstop = None
     w = 1
@@ -283,14 +286,14 @@ class TimeCell:
                 end_time.minute)
         self.schedules.append(schedule)
 
-    def __unicode__(self):
+    def __str__(self):
         if self.schedules:
             return ', '.join([x.emission.title for x in self.schedules])
         else:
             return self.nonstop
 
     def __eq__(self, other):
-        return (unicode(self) == unicode(other) and self.time_label == other.time_label)
+        return (force_text(self) == force_text(other) and self.time_label == other.time_label)
 
 
 class Grid(TemplateView):
@@ -377,7 +380,7 @@ class Grid(TemplateView):
                             continue
                         # here it is, same cell, same emission, several
                         # schedules
-                        schedule_list.sort(lambda x,y: cmp(x.get_duration(), y.get_duration()))
+                        schedule_list.sort(key=lambda x: x.get_duration())
 
                         schedule = schedule_list[0]
                         end_time = schedule.datetime + timedelta(
@@ -483,8 +486,7 @@ class Grid(TemplateView):
                                     grid[i][j].time_label = same_cell_below.time_label
                                     # then we sort emissions so the longest are
                                     # put first
-                                    grid[i][j].schedules.sort(
-                                            lambda x, y: -cmp(x.get_duration(), y.get_duration()))
+                                    grid[i][j].schedules.sort(key=lambda x: -x.get_duration())
                                     # then we add individual time labels to the
                                     # other schedules
                                     for schedule in current_cell_schedules: