示例#1
0
 def create_new_initiative(self, initiative):
     try:
         db_initiative = ORMInitiative.objects.create(acronym = initiative.acronym, full_name = initiative.full_name)
         return self._decode_db_initiative (db_initiative)
     
     except Exception as e:
         stdlogger.error(" %s" % (e))
         raise InternalServerException()
示例#2
0
 def delete_existing_initiative(self, id):
     try:
         orm_initiative = ORMInitiative.objects.get(id = id)
         orm_initiative.delete()
     except ORMInitiative.DoesNotExist as e:
         stdlogger.error("%s" % (e))
         raise EntityDoesNotExistException(source='initiative', code='not found', message='Initiative not found')
     
     except Exception as e:
         stdlogger.error(" %s" % (e))
         raise InternalServerException()
示例#3
0
    def get_initiative(self, id):
        try:
            db_initiative = ORMInitiative.objects.get(id = id)
            return self._decode_db_initiative(db_initiative)

        except ORMInitiative.DoesNotExist as e:
            stdlogger.error("%s" % (e))
            raise EntityDoesNotExistException(source='initiative', code='not found', message='Initiative not found')
        
        except Exception as e:
            stdlogger.error(" %s" % (e))
            raise InternalServerException()
示例#4
0
    def get_all_news_by_tag(self, tag):
        stdlogger.info("Call to get_news method")
        try:
            all_db_news = ORMNews.objects.filter(tags__icontains = tag)

            news =[]
            for db_news in all_db_news:
                news.append(self._decode_db_news(db_news))
            return news

        except Exception as e:
            stdlogger.error("%s" % (e))
            raise InternalServerException()
示例#5
0
    def delete_existing_news(self, id):
        stdlogger.info("Call to delete_existing_news method")
        try:
            db_news = ORMNews.objects.get(id = id)
            db_news.delete()

        except ORMNews.DoesNotExist as e:
            stdlogger.error("%s" % (e))
            raise EntityDoesNotExistException(source='news', code='not found', message='This news does not exist. It may already be deleted')
        
        except Exception as e:
            stdlogger.error("%s" % (e))
            raise InternalServerException()
示例#6
0
    def create_new_news(self, news):
        stdlogger.info("Call to create_news method")
        try:
            stdlogger.debug("Creating a news")
            
            orm_aud,created = ORMAudience.objects.get_or_create(audience_type = news.audience_type)
           
            db_news = ORMNews.objects.create(news_title = news.news_title, news_content = news.news_content, visible = (news.visible == "true"), tags = news.tags, audience=orm_aud)
           
            return self._decode_db_news (db_news)    

        except Exception as e:
            stdlogger.error("%s" % (e))
            raise InternalServerException()
示例#7
0
    def get_news(self, id):
        stdlogger.info("Call to get_news method")
        try:
            stdlogger.debug("Getting the news from id")
            db_news = ORMNews.objects.get(id = id)
            return self._decode_db_news(db_news)

        except ORMNews.DoesNotExist as e:
            stdlogger.error("%s" % (e))
            raise EntityDoesNotExistException(source='news', code='not found', message='News not found')
        
        except Exception as e:
            stdlogger.error(" %s" % (e))
            raise InternalServerException()
示例#8
0
    def update_existing_initiative(self, initiative):
        try:
            orm_initiative = ORMInitiative.objects.get(id = initiative.id)

            orm_initiative.acronym = initiative.acronym
            orm_initiative.full_name = initiative.full_name

            orm_initiative.save()

            return self._decode_db_initiative (orm_initiative)
            
        except ORMInitiative.DoesNotExist as e:
            stdlogger.error("%s" % (e))
            raise EntityDoesNotExistException(source='initiative', code='not found', message='Initiative not found')
        
        except Exception as e:
            stdlogger.error(" %s" % (e))
            raise InternalServerException()
示例#9
0
    def update_existing_news(self,news):
        stdlogger.info("Call to update_existing_news method")
        try:
            stdlogger.debug("Creating a news")
            db_news = ORMNews.objects.get(id = news.id)
            db_aud, created = ORMAudience.objects.get_or_create(audience_type = news.audience_type)
            db_news.audience.clear()

            db_news.news_title = news.news_title
            db_news.news_content = news.news_content
            db_news.visible = (news.visible == "true")
            db_news.tags = news.tags
            db_news.audience = db_aud
            db_news.save()

            return self._decode_db_news (db_news)

        except ORMNews.DoesNotExist as e:
            stdlogger.error("%s" % (e))
            raise EntityDoesNotExistException(source='news', code='not found', message='News not found')

        except Exception as e:
            stdlogger.error("%s" % (e))
            raise InternalServerException()