def res_list(self):
     allres = self.resource_set.all()
     dic = []
     for r in allres:
         if r.file:
             rel_url = r.file.url
             abs_url = os.path.join(settings.MEDIA_ROOT, rel_url)
             f_type = re.sub('\.', '', os.path.splitext(abs_url)[1])
             f_size = format_bytes(os.path.getsize(abs_url))
             dic.append(
                 dict(name=r.title,
                      short_name=r.list_title,
                      file=rel_url,
                      type=f_type,
                      size=f_size,
                      url=None,
                      pos=r.pos))
         elif r.url:
             dic.append(
                 dict(name=r.title,
                      short_name=r.list_title,
                      file=None,
                      type=None,
                      size=None,
                      url=r.url,
                      pos=r.pos))
     return sorted(dic, key=lambda a: a['pos'])
 def file_list(self):
     allfiles =  self.resource_set.all()
     dic = []
     for f in allfiles:
         ffile = f.file
         if ffile:
             rel_url = ffile.url
             abs_url = os.path.join(settings.MEDIA_ROOT, rel_url)
             f_type = re.sub('\.','',os.path.splitext(abs_url)[1])
             f_size = format_bytes(os.path.getsize(abs_url))
             dic.append(dict(name=f.title, file=rel_url, type=f_type, size=f_size))
     return dic
 def res_list(self):
     allres = self.resource_set.all()
     dic = []
     for r in allres:
         if r.file:
             rel_url = r.file.url
             abs_url = os.path.join(settings.MEDIA_ROOT, rel_url)
             f_type = re.sub('\.','',os.path.splitext(abs_url)[1])
             f_size = format_bytes(os.path.getsize(abs_url))
             dic.append(dict(name=r.title, short_name=r.list_title, file=rel_url, type=f_type, size=f_size, url=None, pos=r.pos))
         elif r.url:
             dic.append(dict(name=r.title, short_name=r.list_title, file=None, type=None, size=None, url=r.url, pos=r.pos))
     return sorted(dic, key=lambda a: a['pos'])
 def file_list(self):
     allfiles = self.resource_set.all()
     dic = []
     for f in allfiles:
         ffile = f.file
         if ffile:
             rel_url = ffile.url
             abs_url = os.path.join(settings.MEDIA_ROOT, rel_url)
             f_type = re.sub('\.', '', os.path.splitext(abs_url)[1])
             f_size = format_bytes(os.path.getsize(abs_url))
             dic.append(
                 dict(name=f.title, file=rel_url, type=f_type, size=f_size))
     return dic