Exemplo n.º 1
0
def detail(page):
    # usertype = request.args.getlist('usertype')
    KEYWORD = request.args.get('keyword')
    ip = request.args.get('ip')
    searchtype = request.args.get('searchtype')
    searchtime = request.args.get('searchtime')

    starttime, endtime = search_time(searchtime)
    page, per_page, offset = get_page_args()

    print isinstance(ip, unicode)
    if searchtime is not None and isinstance(ip, unicode):
        starttime = starttime.split("'")[1]
        endtime = endtime.split("'")[1]
        total = db.session.query(IP_log).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.keyword.like('%' + KEYWORD + '%'))).count()
        users = db.session.query(IP_log).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.keyword.like('%' + KEYWORD + '%'))).limit(
                        per_page).offset(offset).all()

    elif searchtime is not None and searchtype != 'none':
        starttime = starttime.split("'")[1]
        endtime = endtime.split("'")[1]
        total = db.session.query(IP_log).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.keyword.like('%' + KEYWORD + '%'),
                    IP_log.click == searchtype)).count()
        users = db.session.query(IP_log).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.keyword.like('%' + KEYWORD + '%'), IP_log.click ==
                    searchtype)).limit(per_page).offset(offset).all()

    elif (not isinstance(ip, unicode) and ip != None):
        total = db.session.query(IP_log).filter(IP_log.ip == ip).count()
        users = db.session.query(IP_log).filter(
            IP_log.ip == ip).limit(per_page).offset(offset).all()

    else:
        total = db.session.query(IP_log).count()
        # users = db.session.query(IP_log).order_by(db.desc(IP_log.created_at)).limit(per_page).offset(offset).all()
        users = db.session.query(IP_log).order_by(db.desc(
            IP_log.created_at)).limit(per_page).offset(offset).all()

    pagination = get_pagination(
        page=page,
        per_page=per_page,
        total=total,
        record_name='iplog',
        format_total=True,
        format_number=True,
    )
    return render_template(
        '/main/detail.html',
        users=users,
        page=page,
        per_page=per_page,
        pagination=pagination,
    )
Exemplo n.º 2
0
Arquivo: user.py Projeto: gitzart/sns
 def get(cls, id_1, id_2):
     """Given the composite primary key, return the query which
     finds the relationship of two people.
     """
     return cls.query.filter(db.or_(
         db.and_(cls.left_user_id == id_1, cls.right_user_id == id_2),
         db.and_(cls.left_user_id == id_2, cls.right_user_id == id_1)
     ))
Exemplo n.º 3
0
def reports():

    searchtime = request.args.get('searchtime')
    starttime, endtime = search_time(searchtime)
    starttime = starttime.split("'")[1]
    endtime = endtime.split("'")[1]
    search_days = []
    click_days = []
    searchdict = {'name': 'serch'}
    clickdict = {'name': 'click'}
    days = []
    if searchtime is not None:
        sea = db.func.date_format(IP_log.created_at,
                                  "%Y-%m-%d").label('search')
        search = db.session.query(sea, db.func.count(IP_log.click)).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.click == 0)).group_by('search').all()
        cli = db.func.date_format(IP_log.created_at,
                                  "%Y-%m-%d").label('search')
        click = db.session.query(cli, db.func.count(IP_log.click)).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.click == 1)).group_by('search').all()
    else:
        sea = db.func.date_format(IP_log.created_at,
                                  "%Y-%m-%d").label('search')
        search = db.session.query(sea, db.func.count(IP_log.click)).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.click == 0)).group_by('search').all()
        cli = db.func.date_format(IP_log.created_at,
                                  "%Y-%m-%d").label('search')
        click = db.session.query(cli, db.func.count(IP_log.click)).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.click == 1)).group_by('search').all()
    if len(search) == 0 or len(click) == 0:
        starttime, endtime = create_time(starttime, endtime)
        for i in range((endtime - starttime).days + 1):
            day = starttime + datetime.timedelta(days=i)
            day = unicode(str(day), 'utf-8')
            if len(search) == 0:
                search.append([day, 0])
            else:
                click.append([day, 0])
    for search_day, click_day in zip(search, click):
        search_day = list(search_day)
        search_day[0] = search_day[0].encode("utf-8")
        search_day[1] = int(search_day[1])
        click_day = list(click_day)
        click_day[0] = click_day[0].encode("utf-8")
        click_day[1] = int(click_day[1])
        search_days.append(search_day)
        click_days.append(click_day)

    searchdict['data'] = search_days
    clickdict['data'] = click_days
    days.extend([searchdict, clickdict])
    return render_template('/main/auto.html', data=days)
 def post(self):
     status = False
     data = request.data
     data_dict = json.loads(data)
     print(data_dict)
     try:
         pro = project.query.get(
             data_dict['pid'])  # get project is exist or not
         if pro.pid:
             try:
                 status = project.query.get(data_dict['pid'])
                 status.share.clear()
             except Exception as e:
                 print(f'Error {e} ')
             status = project.query.filter(
                 db.and_(project.uid == data_dict['uid'],
                         project.pid == data_dict['pid'])).delete()
             status = task_of_project.query.filter(
                 task_of_project.pid == data_dict['pid']).delete()
             db.session.commit()
             status = True
         else:
             status = False
     except Exception as e:
         print(str(e))
     print({'status': status})
     return {'status': status}
Exemplo n.º 5
0
def count(page):
    # usertype = request.args.getlist('usertype')
    searchtype = request.args.get('searchtype')
    searchtime = request.args.get('searchtime')
    starttime, endtime = search_time(searchtime)

    page, per_page, offset = get_page_args()
    if searchtime is not None and searchtype != 'none':
        starttime = starttime.split("'")[1]
        endtime = endtime.split("'")[1]
        total = db.session.query(db.func.count('*'), IP_log.keyword).filter(
            db.and_(IP_log.created_at.between(starttime, endtime),
                    IP_log.click == searchtype)).group_by(
                        IP_log.keyword).count()
        users = db.session.query(
            db.func.count('*').label('count'), IP_log.keyword).filter(
                db.and_(IP_log.created_at.between(
                    starttime, endtime), IP_log.click == searchtype)).group_by(
                        IP_log.keyword).limit(per_page).offset(offset).all()
    elif searchtime is not None:
        starttime = starttime.split("'")[1]
        endtime = endtime.split("'")[1]
        total = db.session.query(
            db.func.count('*').label('count'), IP_log.keyword).filter(
                db.and_(IP_log.created_at.between(
                    starttime, endtime))).group_by(IP_log.keyword).count()
        users = db.session.query(
            db.func.count('*').label('count'), IP_log.keyword).filter(
                db.and_(IP_log.created_at.between(
                    starttime, endtime))).group_by(
                        IP_log.keyword).limit(per_page).offset(offset).all()
    else:
        starttime = starttime.split("'")[1]
        endtime = endtime.split("'")[1]
        total = db.session.query(
            db.func.count('*').label('count'), IP_log.keyword).filter(
                db.and_(IP_log.created_at.between(
                    starttime, endtime))).group_by(IP_log.keyword).count()
        users = db.session.query(
            db.func.count('*').label('count'), IP_log.keyword).filter(
                db.and_(IP_log.created_at.between(
                    starttime, endtime))).group_by(
                        IP_log.keyword).limit(per_page).offset(offset).all()

    pagination = get_pagination(
        page=page,
        per_page=per_page,
        total=total,
        record_name='iplog',
        format_total=True,
        format_number=True,
    )
    return render_template(
        '/main/count.html',
        users=users,
        page=page,
        per_page=per_page,
        pagination=pagination,
    )
 def post(self):
     data = request.data
     data_dict = json.loads(data)
     print(data_dict)
     data = list()
     us = Users.query.get(data_dict['uid'])
     for row in project.query.filter(
             db.and_(project.share.contains(us),
                     project.pid == data_dict['pid'])):
         d = row.__dict__
         d.pop('_sa_instance_state')
         for x in date_in_result:
             d[x] = str(d[x])
         data.append(d)
     print('\nSingle Project:')
     print({'all_projects': data})
     return {'all_projects': data}
 def post(self):
     status = False
     data = request.data
     dataDict = json.loads(data)
     print(dataDict)
     try:
         us = Users.query.get(dataDict['uid'])  # get user
         us = project.query.filter(
             db.and_(project.share.contains(us),
                     project.pid == dataDict['pid'])).first()
         users = list()
         for x in us.share:
             d = x.__dict__
             d.pop('_sa_instance_state')
             d.pop('password_text')
             users.append(d)  # create users list
         status = True
         data = {'status': status, 'users': json.loads(json.dumps(users))}
         print('\n\nusers {}:{}'.format(dataDict['uid'], data))
         return data
     except Exception as e:
         print({'status': status, 'error': str(e)})
         return {'status': status, 'error': str(e)}
Exemplo n.º 8
0
Arquivo: user.py Projeto: gitzart/sns
 def criteria(id):
     return db.and_(
         Friendship.left_user_id == id,
         Friendship.state == ACCEPTED
     )