Carl Meyer avatar Carl Meyer committed d2abffa

Support pulling multiple pages of videos from Vimeo.

Comments (0)

Files changed (1)

adminfiles/views.py

     def slug(self):
         """
         Return slug suitable for accessing this view in a URLconf.
-        
+
         """
         slug = self.__class__.__name__.lower()
         if slug.endswith('view'):
     def link_text(self):
         """
         Return link text for this view.
-        
+
         """
         link = self.__class__.__name__
         if link.endswith('View'):
         """
         Raise ``DisableView`` if the configuration necessary for this
         view is not active.
-        
+
         """
         pass
-    
+
     def context(self, request):
         return {'browsers': get_enabled_browsers(),
                 'field_id': request.GET['field'],
 
 class ImagesView(AllView):
     link_text = _('Images')
-    
+
     def files(self):
         return super(ImagesView, self).files().filter(content_type='image')
 
 
 class AudioView(AllView):
     link_text = _('Audio')
-    
+
     def files(self):
         return super(AudioView, self).files().filter(content_type='audio')
 
 
 class FilesView(AllView):
     link_text = _('Files')
-        
+
     def files(self):
         not_files = ['video', 'image', 'audio']
         return super(FilesView, self).files().exclude(content_type__in=not_files)
         except AttributeError:
             raise DisableView('YouTubeView requires '
                               'ADMINFILES_YOUTUBE_USER setting')
-            
-    
+
+
     def context(self, request):
         context = super(YouTubeView, self).context(request)
         context['videos'] = self.videos()
 
 class FlickrView(OEmbedView):
     template_name = 'adminfiles/uploader/flickr.html'
-    
+
     def check(self):
         super(FlickrView, self).check()
         try:
             raise DisableView('FlickrView requires '
                               'ADMINFILES_FLICKR_USER and '
                               'ADMINFILES_FLICKR_API_KEY settings')
-                              
+
     def context(self, request):
         context = super(FlickrView, self).context(request)
         page = int(request.GET.get('page', 1))
         except AttributeError:
             raise DisableView('VimeoView requires '
                               'ADMINFILES_VIMEO_USER setting')
-    
+        try:
+            self.pages = django_settings.ADMINFILES_VIMEO_PAGES
+        except AttributeError:
+            self.pages = 1
+        if self.pages > 3:
+            self.pages = 3
+
     def context(self, request):
         context = super(VimeoView, self).context(request)
         context['videos'] = self.videos()
         return context
 
-    def videos(self):
+    def _get_videos(self, url):
         import urllib2
         try:
             import xml.etree.ElementTree as ET
         except ImportError:
             import elementtree.ElementTree as ET
-        request = urllib2.Request('http://vimeo.com/api/v2/%s/videos.xml'
-                                  % django_settings.ADMINFILES_VIMEO_USER)
+        request = urllib2.Request(url)
         request.add_header('User-Agent', 'django-adminfiles/0.x')
         root = ET.parse(urllib2.build_opener().open(request)).getroot()
         videos = []
                     })
         return videos
 
+    def videos(self):
+        url = ('http://vimeo.com/api/v2/%s/videos.xml'
+               % django_settings.ADMINFILES_VIMEO_USER)
+        videos = self._get_videos(url)
+        for page in range(2, self.pages + 1):
+            page_url = "%s?page=%s" % (url, page)
+            page_videos = self._get_videos(page_url)
+            if not page_videos:
+                break
+            videos += page_videos
+        return videos
+
 
 def download(request):
     '''Saves image from URL and returns ID for use with AJAX script'''
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.