def save(self, *args, **kwargs): if self.id is not None: self.title = clean_html(self.title) old_version = RSSFeed.objects.get(id=self.id) if (self.link != old_version.link) and (not validate_feed( self.link)): raise Exception("RSS Feed is not valid") super(RSSFeed, self).save(*args, **kwargs) # Call the "real" save() method.
def create(self, *args, **kwargs): if 'title' in kwargs and (isinstance(kwargs['title'], str) or isinstance(kwargs['title'], str)): kwargs['title'] = clean_html(kwargs['title']) else: raise Exception("Title is missing - RSSFeed_Sub Manager") if RSSFeed_Sub.objects.filter(user=kwargs['user'], feed=kwargs['feed']).exists(): raise Exception("User (" + kwargs['user'].username + ") is already subscribed to the RSSFeed (id = " + str(kwargs['feed'].id) + ")") return super(RSSFeed_SubManager, self).create(*args, **kwargs)
def post(self, request): payload = dict() try: rssfeed = request.POST.get('rssfeed') if rssfeed == None: raise Exception("Link for the RSS Feed not provided") else: payload["rssfeed"] = rssfeed rssfeed_queryset = RSSFeed.objects.filter(link=rssfeed) if rssfeed_queryset.exists(): if RSSFeed.objects.filter( link=rssfeed, rel_sub_feed_assoc__user=request.user): payload["valid"] = False payload[ "error"] = "You already subscribed to this RSS Feed" else: payload["valid"] = True payload["title"] = rssfeed_queryset[0].title else: rss_data = feedparser.parse(rssfeed) if validate_feed(rss_data): payload["valid"] = True payload["title"] = clean_html(rss_data.feed.title) else: payload["valid"] = False payload[ "error"] = "The RSS Feed is not valid. Please check your link" payload["success"] = True except Exception as e: payload["success"] = False payload["error"] = "An error occured in the process: " + str(e) payload["operation"] = "RSS Feed Validation" payload["timestamp"] = get_timestamp() return Response(payload)
def create(self, *args, **kwargs): if 'title' in kwargs and (isinstance(kwargs['title'], str) or isinstance(kwargs['title'], str)): kwargs['title'] = clean_html(kwargs['title']) else: raise Exception("Title is missing - RSSArticle Manager") if 'link' in kwargs and (isinstance(kwargs['link'], str) or isinstance(kwargs['link'], str)): if RSSArticle.objects.filter(rssfeed=kwargs['rssfeed'], link=kwargs['link']).exists(): raise Exception( "RSS Article already exists in database - RSSArticle Manager" ) else: raise Exception("Link is missing - RSSFeed Manager") return super(RSSArticleManager, self).create(*args, **kwargs)
def create(self, *args, **kwargs): if 'title' in kwargs and (isinstance(kwargs['title'], str) or isinstance(kwargs['title'], str)): kwargs['title'] = clean_html(kwargs['title']) else: raise Exception("Title is missing - RSSFeed Manager") if 'link' in kwargs and (isinstance(kwargs['link'], str) or isinstance(kwargs['link'], str)): if RSSFeed.objects.filter(link=kwargs['link']).exists(): raise Exception("RSSFeed already exists in the database.") elif not validate_feed(kwargs['link']): raise Exception("RSS Feed is not valid") else: raise Exception("Link is missing - RSSFeed Manager") return super(RSSFeedManager, self).create(*args, **kwargs)
def save(self, *args, **kwargs): if self.id is not None: self.title = clean_html(self.title) super(RSSFeed_Sub, self).save(*args, **kwargs) # Call the "real" save() method.