def list_articles(request):
    try:
        articles = session.query(Article).filter(
            Article.user_id == request.params['user_id']).all()
    except KeyError:
        articles = session.query(Article).all()
    json = dumps([serialize(article) for article in articles])
    return Response(json)
예제 #2
0
 def log(self, sFile, sErrorType, sErrorMsg):
     with open(sFile, 'a') as file:
         aErrorLog = {
             'errorType': str(sErrorType),
             'errorMsg': str(sErrorMsg)
         }
         sErrorLog = str(serialize(aErrorLog))
         file.write(sErrorLog)
     return
def add_user(request):
    if not request.method != 'POST':
        raise HTTPMethodNotAllowed
    try:
        user = User(email=request.params['email'],
                    first_name=request.params['first_name'],
                    last_name=request.params['last_name'])
        session.add(user)
        session.commit()
        response = dumps(serialize(user))
    except KeyError:
        response = 'query parameters was not provided'

    return Response(response)
def add_article(request):
    if not request.method != 'POST':
        raise HTTPMethodNotAllowed
    try:
        article = Article(user_id=request.params['user_id'],
                          title=request.params['title'],
                          text=request.params['text'])
        session.add(article)
        session.commit()
        response = dumps(serialize(article))
    except KeyError:
        response = 'query parameters was not provided'

    return Response(response)
예제 #5
0
def display_charts(df, chart_type="default", render_to=None, **kwargs):
    """Display you DataFrame with Highcharts.

    df: DataFrame
    chart_type: str
        'default' or 'stock'
    render_to: str
        div id for plotting your data
    """
    if chart_type not in ("default", "stock"):
        raise ValueError("Wrong chart_type: accept 'default' or 'stock'.")
    chart_id = render_to if render_to is not None else _generate_div_id_chart()
    json_data = serialize(df, render_to=chart_id, chart_type=chart_type, **kwargs)
    content = """<div id="{chart_id}"</div>
    <script type="text/javascript">{data}</script>"""
    return display(HTML(content.format(chart_id=chart_id, data=json_data)))
예제 #6
0
def display_charts(df, chart_type="default", render_to=None, **kwargs):
    """Display you DataFrame with Highcharts.

    df: DataFrame
    chart_type: str
        'default' or 'stock'
    render_to: str
        div id for plotting your data
    """
    if chart_type not in ("default", "stock"):
        raise ValueError("Wrong chart_type: accept 'default' or 'stock'.")
    chart_id = render_to if render_to is not None else _generate_div_id_chart()
    json_data = serialize(df,
                          render_to=chart_id,
                          chart_type=chart_type,
                          **kwargs)
    content = """<div id="{chart_id}"</div>
    <script type="text/javascript">{data}</script>"""
    return display(HTML(content.format(chart_id=chart_id, data=json_data)))
예제 #7
0
    def getObject(self, sClass, aParams=[]):
        sHash = md5(sClass + serialize(aParams))
        if (sHash in self.aObject.keys()):
            return self.aObject[sHash]

        if (class_exist(sClass) == False):
            buff = Error('ErrorClassModuleExistence',
                         'Classe' + sClass + 'N\'existe pas')

        ClassMod = __import__('class' + sClass, fromlist=[sClass])

        if (aParams != []):
            cmd = sClass + '('
            for i in range(len(aParams)):
                cmd += "\"" + aParams[i] + "\""
                if (i != len(aParams) - 1):
                    cmd += ','
            cmd += ')'
            cmd = 'ClassMod.' + cmd
            self.aObject[sHash] = eval(cmd)
            return self.aObject[sHash]
        return
def list_users(request):
    users = session.query(User).all()
    json = dumps([serialize(user) for user in users])
    return Response(json)
def detail_user(request, id):
    user = session.query(User).filter(User.id == id.path).one()
    json = dumps(serialize(user))

    return Response(json)
def read(request, id):
    article = session.query(Article).filter(Article.id == id.path).one()
    json = dumps(serialize(article))
    return Response(json)