mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Fixing OPML upload when the opml file is missing crucial information. Thanks to richardb20!
This commit is contained in:
parent
328b1cd4cf
commit
d4d53f5969
2 changed files with 8 additions and 9 deletions
|
@ -44,28 +44,27 @@ class OPMLImporter(Importer):
|
||||||
|
|
||||||
def process_outline(self, outline):
|
def process_outline(self, outline):
|
||||||
folders = []
|
folders = []
|
||||||
|
|
||||||
for item in outline:
|
for item in outline:
|
||||||
if not hasattr(item, 'xmlUrl'):
|
if not hasattr(item, 'xmlUrl'):
|
||||||
folder = item
|
folder = item
|
||||||
if hasattr(folder, 'text'):
|
# if hasattr(folder, 'text'):
|
||||||
logging.info(' ---> [%s] ~FRNew Folder: %s' % (self.user, folder.text))
|
# logging.info(' ---> [%s] ~FRNew Folder: %s' % (self.user, folder.text))
|
||||||
folders.append({folder.text: self.process_outline(folder)})
|
folders.append({folder.text: self.process_outline(folder)})
|
||||||
elif hasattr(item, 'xmlUrl'):
|
elif hasattr(item, 'xmlUrl'):
|
||||||
feed = item
|
feed = item
|
||||||
if not hasattr(feed, 'htmlUrl'):
|
if not hasattr(feed, 'htmlUrl'):
|
||||||
setattr(feed, 'htmlUrl', None)
|
setattr(feed, 'htmlUrl', None)
|
||||||
if not hasattr(feed, 'title'):
|
if not hasattr(feed, 'title') or not feed.title:
|
||||||
setattr(feed, 'title', feed.htmlUrl)
|
setattr(feed, 'title', feed.htmlUrl or feed.xmlUrl)
|
||||||
feed_address = urlnorm.normalize(feed.xmlUrl)
|
feed_address = urlnorm.normalize(feed.xmlUrl)
|
||||||
feed_link = urlnorm.normalize(feed.htmlUrl)
|
feed_link = urlnorm.normalize(feed.htmlUrl)
|
||||||
if len(feed_address) > Feed._meta.get_field('feed_address').max_length:
|
if len(feed_address) > Feed._meta.get_field('feed_address').max_length:
|
||||||
continue
|
continue
|
||||||
if feed_link and len(feed_link) > Feed._meta.get_field('feed_link').max_length:
|
if feed_link and len(feed_link) > Feed._meta.get_field('feed_link').max_length:
|
||||||
continue
|
continue
|
||||||
if feed.title and len(feed.title) > Feed._meta.get_field('feed_title').max_length:
|
if len(feed.title) > Feed._meta.get_field('feed_title').max_length:
|
||||||
feed.title = feed.title[:255]
|
feed.title = feed.title[:255]
|
||||||
logging.info(' ---> \t~FR%s - %s - %s' % (feed.title, feed_link, feed_address,))
|
# logging.info(' ---> \t~FR%s - %s - %s' % (feed.title, feed_link, feed_address,))
|
||||||
feed_data = dict(feed_address=feed_address, feed_link=feed_link, feed_title=feed.title)
|
feed_data = dict(feed_address=feed_address, feed_link=feed_link, feed_title=feed.title)
|
||||||
# feeds.append(feed_data)
|
# feeds.append(feed_data)
|
||||||
|
|
||||||
|
|
|
@ -25,15 +25,15 @@ def opml_upload(request):
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if 'file' in request.FILES:
|
if 'file' in request.FILES:
|
||||||
logging.info(" ---> [%s] OPML Upload" % request.user)
|
logging.info(" ---> [%s] ~FR~SBOPML upload starting..." % request.user)
|
||||||
file = request.FILES['file']
|
file = request.FILES['file']
|
||||||
xml_opml = file.read()
|
xml_opml = file.read()
|
||||||
|
|
||||||
opml_importer = OPMLImporter(xml_opml, request.user)
|
opml_importer = OPMLImporter(xml_opml, request.user)
|
||||||
folders = opml_importer.process()
|
folders = opml_importer.process()
|
||||||
|
|
||||||
feeds = UserSubscription.objects.filter(user=request.user).values()
|
feeds = UserSubscription.objects.filter(user=request.user).values()
|
||||||
payload = dict(folders=folders, feeds=feeds)
|
payload = dict(folders=folders, feeds=feeds)
|
||||||
|
logging.info(" ---> [%s] ~FR~SBOPML Upload: ~SK%s~SN~SB~FR feeds" % (request.user, len(feeds)))
|
||||||
|
|
||||||
request.session['import_from_google_reader'] = False
|
request.session['import_from_google_reader'] = False
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Reference in a new issue