allura
修訂 | d7ab1166056dbb289fc12b857cd528cff4862dd1 (tree) |
---|---|
時間 | 2012-06-14 23:28:20 |
作者 | bolkimen <bolkimen@yaho...> |
Commiter | bolkimen |
[#4347] ticket:82 add validator, fix command
@@ -116,7 +116,7 @@ class MDHTMLParser(HTMLParser): | ||
116 | 116 | |
117 | 117 | class RssFeedsCommand(base.BlogCommand): |
118 | 118 | summary = 'Rss feed client' |
119 | - parser = base.Command.standard_parser(verbose=True) | |
119 | + parser = base.BlogCommand.standard_parser(verbose=True) | |
120 | 120 | parser.add_option('-a', '--appid', dest='appid', default='', |
121 | 121 | help='application id') |
122 | 122 | parser.add_option('-u', '--username', dest='username', default='root', |
@@ -160,7 +160,7 @@ class RssFeedsCommand(base.BlogCommand): | ||
160 | 160 | allura_base.log.info("Get feed: %s" % feed_url) |
161 | 161 | f = feedparser.parse(feed_url) |
162 | 162 | if f.bozo: |
163 | - base.log.exception("%s: %s" % (feed_url, f.bozo_exception)) | |
163 | + allura_base.log.exception("%s: %s" % (feed_url, f.bozo_exception)) | |
164 | 164 | return |
165 | 165 | for e in f.entries: |
166 | 166 | title = e.title |
@@ -9,6 +9,7 @@ import pymongo | ||
9 | 9 | from tg import expose, validate, redirect, flash |
10 | 10 | from tg.decorators import with_trailing_slash, without_trailing_slash |
11 | 11 | from pylons import g, c, request, response |
12 | +import formencode | |
12 | 13 | from formencode import validators |
13 | 14 | from webob import exc |
14 | 15 |
@@ -401,18 +402,30 @@ class BlogAdminController(DefaultAdminController): | ||
401 | 402 | @without_trailing_slash |
402 | 403 | @expose() |
403 | 404 | @require_post() |
404 | - def set_exfeed(self, **kw): | |
405 | - new_exfeed = kw.get('new_exfeed', None) | |
405 | + def set_exfeed(self, new_exfeed=None, **kw): | |
406 | 406 | exfeed_val = kw.get('exfeed', []) |
407 | 407 | if type(exfeed_val) == unicode: |
408 | - exfeed_list = [] | |
409 | - exfeed_list.append(exfeed_val) | |
408 | + tmp_exfeed_list = [] | |
409 | + tmp_exfeed_list.append(exfeed_val) | |
410 | 410 | else: |
411 | - exfeed_list = exfeed_val | |
411 | + tmp_exfeed_list = exfeed_val | |
412 | 412 | |
413 | 413 | if new_exfeed is not None and new_exfeed != '': |
414 | - exfeed_list.append(new_exfeed) | |
414 | + tmp_exfeed_list.append(new_exfeed) | |
415 | + | |
416 | + exfeed_list = [] | |
417 | + invalid_list = [] | |
418 | + v = validators.URL() | |
419 | + for link in tmp_exfeed_list: | |
420 | + try: | |
421 | + v.to_python(link) | |
422 | + exfeed_list.append(link) | |
423 | + except formencode.api.Invalid: | |
424 | + invalid_list.append(link) | |
415 | 425 | |
416 | 426 | self.app.external_feeds_list = exfeed_list |
417 | 427 | flash('External feeds updated') |
428 | + if len(invalid_list) > 0: | |
429 | + flash('Invalid link(s): %s' % ','.join(link for link in invalid_list)) | |
430 | + | |
418 | 431 | redirect(c.project.url()+'admin/tools') |
@@ -15,7 +15,7 @@ | ||
15 | 15 | {% if allow_config %} |
16 | 16 | <div class="grid-13"> </div> |
17 | 17 | <div class="grid-13"> |
18 | - <input type="text" name="new_exfeed" id="new_exfeed" value=""/> | |
18 | + <label>Add RSS/Atom feed URL:</label> <input type="text" name="new_exfeed" id="new_exfeed" value=""/> | |
19 | 19 | </div> |
20 | 20 | <div class="grid-13"> </div> |
21 | 21 | <hr> |