def feed_bulk_action(self, args): """The feed handler - as feed request come in, feeds are adjusted""" posted = args all_args = {} for i in posted: i = i[0].split(":") all_args.update(dict([i])) self.all_feeds_list = [] action = all_args['bulk'] for i in all_args: if "FEED" in i: self.all_feeds_list.append(all_args[i]) self.mod_status = ModifyFeed() self.mod_status.mod(self.list_of_feeds, self.all_feeds_list, action)
class Feeds(Resource): def __init__(self): Resource.__init__(self) self.list_of_feeds = [] self.connectDB = ConnectFeedDB() self.connectDB.return_all_feeds()#force reload of table information self.value = "test" self.html = self.create_html() self.feed_gen = [x for x in self.connectDB.return_all_feeds()] self.feeds = "" self.html_feeds() self.list_of_all_feeds = [] self.all_feed_objects() def create_html(self): self.html = """ <html> <body bgcolor="black" text="white"> <center> <form name="feeds" method=POST> <table border=2 cellpadding=5> <tr> <td>Select</td> <td>Feed ID</td> <td>Feed Type</td> <td>URL</td> <td>Active?</td> <td>Date Added</td> <td>Date Last Checked</td> </tr> {0} </table> Bulk Action: <select name="BulkAction"> <option value="bulk:None">No Bulk</option> <option value="bulk:delete_feeds">Delete</option> <option value="bulk:check_now">Check Now</option> <option value="bulk:activate">Activate</option> <option value="bulk:deactivate">Deactivate</option> </select> <input type="submit" value="Submit" /> </center> </form> </body> </html>""" return self.html def html_feeds(self): for feed in self.feed_gen: self.feeds += "<tr>\n\t<td><input type=\"checkbox\" name=\"index_{0}\" value=\"FEED{0}:{0}\"/>".format(feed['id']) keys_ordered = ('id', 'URIType', 'URL', 'Active', 'Added', 'Last_Checked') self.list_of_feeds.append(feed) for key in keys_ordered: if key == 'Active': if feed[key] == 1: feed[key] = 'Active' elif feed[key] == 0: feed[key] = 'Deactive' self.feeds += "<td>" + str(feed[key]) + "</td>" self.feeds += "</tr>" def inject_feeds(self): self.html = self.html.format(self.feeds) return self.html def feed_bulk_action(self, args): """The feed handler - as feed request come in, feeds are adjusted""" posted = args all_args = {} for i in posted: i = i[0].split(":") all_args.update(dict([i])) self.all_feeds_list = [] action = all_args['bulk'] for i in all_args: if "FEED" in i: self.all_feeds_list.append(all_args[i]) self.mod_status = ModifyFeed() self.mod_status.mod(self.list_of_feeds, self.all_feeds_list, action) def all_feed_objects(self): for feed in self.feed_gen: self.list_of_all_feeds.append(FeedInformation(feed)) print self.list_of_all_feeds def render_GET(self, request): if request.path == '/feeds': self.__init__() return self.inject_feeds() def render_POST(self, request): args = request.args.values() self.feed_bulk_action(args) return self.render_GET(request)
class Feeds(Resource): def __init__(self): Resource.__init__(self) self.list_of_feeds = [] self.connectDB = ConnectFeedDB() self.connectDB.return_all_feeds() #force reload of table information self.value = "test" self.html = self.create_html() self.feed_gen = [x for x in self.connectDB.return_all_feeds()] self.feeds = "" self.html_feeds() self.list_of_all_feeds = [] self.all_feed_objects() def create_html(self): self.html = """ <html> <body bgcolor="black" text="white"> <center> <form name="feeds" method=POST> <table border=2 cellpadding=5> <tr> <td>Select</td> <td>Feed ID</td> <td>Feed Type</td> <td>URL</td> <td>Active?</td> <td>Date Added</td> <td>Date Last Checked</td> </tr> {0} </table> Bulk Action: <select name="BulkAction"> <option value="bulk:None">No Bulk</option> <option value="bulk:delete_feeds">Delete</option> <option value="bulk:check_now">Check Now</option> <option value="bulk:activate">Activate</option> <option value="bulk:deactivate">Deactivate</option> </select> <input type="submit" value="Submit" /> </center> </form> </body> </html>""" return self.html def html_feeds(self): for feed in self.feed_gen: self.feeds += "<tr>\n\t<td><input type=\"checkbox\" name=\"index_{0}\" value=\"FEED{0}:{0}\"/>".format( feed['id']) keys_ordered = ('id', 'URIType', 'URL', 'Active', 'Added', 'Last_Checked') self.list_of_feeds.append(feed) for key in keys_ordered: if key == 'Active': if feed[key] == 1: feed[key] = 'Active' elif feed[key] == 0: feed[key] = 'Deactive' self.feeds += "<td>" + str(feed[key]) + "</td>" self.feeds += "</tr>" def inject_feeds(self): self.html = self.html.format(self.feeds) return self.html def feed_bulk_action(self, args): """The feed handler - as feed request come in, feeds are adjusted""" posted = args all_args = {} for i in posted: i = i[0].split(":") all_args.update(dict([i])) self.all_feeds_list = [] action = all_args['bulk'] for i in all_args: if "FEED" in i: self.all_feeds_list.append(all_args[i]) self.mod_status = ModifyFeed() self.mod_status.mod(self.list_of_feeds, self.all_feeds_list, action) def all_feed_objects(self): for feed in self.feed_gen: self.list_of_all_feeds.append(FeedInformation(feed)) print self.list_of_all_feeds def render_GET(self, request): if request.path == '/feeds': self.__init__() return self.inject_feeds() def render_POST(self, request): args = request.args.values() self.feed_bulk_action(args) return self.render_GET(request)