Beispiel #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,
    )
def index_images(page, per_page):
    paginate = Image.query.order_by(db.desc(Image.id)).paginate(
        page=page, per_page=per_page, error_out=False)
    map = {'has_next': paginate.has_next}
    images = []
    for image in paginate.items:
        fabulous = []
        for i in range(0, len(image.fabulous)):
            fab = image.fabulous[i]
            fabulous.append({'user_id': fab.user_id})
        comments = []
        for i in range(0, min(2, len(image.comments))):
            comment = image.comments[i]
            comments.append({
                'username': comment.user.username,
                'user_id': comment.user_id,
                'content': comment.content
            })
        imgvo = {
            'id': image.id,
            'url': image.url,
            'comment_count': len(image.comments),
            'fabulous_count': len(image.fabulous),
            'fabulous': fabulous,
            'user_id': image.user_id,
            'head_url': image.user.head_url,
            'user_username': image.user.username,
            'created_date': str(image.created_date),
            'comments': comments
        }
        images.append(imgvo)

    map['images'] = images
    return json.dumps(map)
Beispiel #3
0
def image(image_id):
    image = Image.query.get(image_id)
    if image == None:
        return redirect('/')
    comments = Comment.query.filter_by(image_id=image_id).order_by(
        db.desc(Comment.id)).limit(20).all()
    return render_template('pageDetail.html', image=image, comments=comments)
def index():
    paginate = Image.query.order_by(db.desc(Image.id)).paginate(page=1,
                                                                per_page=10)
    # images = Image.query.order_by(db.desc(Image.id)).limit(20).all()
    return render_template('index.html',
                           image=image,
                           has_next=paginate.has_next,
                           images=paginate.items)
Beispiel #5
0
    def insert(self, url):
        try:
            row = URI_Table.query.order_by(db.desc('index')).first()
            index = row.index
            if index is None:
                index = 0
            else:
                index += 1

            new_url = get_page_id(index=index)

            db.session.add(URI_Table(url=url, s_url=new_url, index=index))
            db.session.commit()
            return new_url
        except:
            return -1
def image(image_id):
    image = Image.query.get(image_id)
    if image == None:
        return redirect('/')
    fabulous = []
    fabs = Fabulous.query.filter_by(image_id=image_id).all()
    for i in fabs:
        ivo = {'user_id': i.user_id}
        fabulous.append(ivo)
    paginate = Comment.query.filter_by(image_id=image_id).order_by(
        db.desc(Comment.id)).paginate(page=1, per_page=10)
    return render_template('pageDetail.html',
                           image=image,
                           fabulous=fabulous,
                           has_next=paginate.has_next,
                           comments=paginate.items)
Beispiel #7
0
def user_images(user_id, page, per_page):
    # 参数检查
    paginate = Image.query.filter_by(user_id=user_id).order_by(
        db.desc(Image.id)).paginate(page=page,
                                    per_page=per_page,
                                    error_out=False)
    map = {'has_next': paginate.has_next}
    images = []
    for image in paginate.items:
        imgvo = {
            'id': image.id,
            'url': image.url,
            'comment_count': len(image.comments)
        }
        images.append(imgvo)
    map['images'] = images
    return json.dumps(map)
def image_images(image_id, page, per_page):
    # 参数检查
    paginate = Comment.query.filter_by(image_id=image_id).order_by(
        db.desc(Comment.id)).paginate(page=page,
                                      per_page=per_page,
                                      error_out=False)
    map = {'has_next': paginate.has_next}
    comments = []
    for comment in paginate.items:
        comgvo = {
            'head_url': comment.user.head_url,
            'content': comment.content,
            'user_id': comment.user_id,
            'username': comment.user.username
        }
        comments.append(comgvo)
    map['comments'] = comments
    return json.dumps(map)
def profile(user_id):
    user = User.query.get(user_id)
    if user == None:
        return redirect('/')
    paginate = Image.query.filter_by(user_id=user_id).order_by(
        db.desc(Image.id)).paginate(page=1, per_page=3)

    fabus = Fabulous.query.filter_by(user_id=user_id).all()
    fabus_images = []
    for image in fabus:
        fabus_images.append(Image.query.filter_by(id=image.image_id).all())

    f_images = []
    for f in fabus_images:
        for i in f:
            f_images.append(i)
    return render_template('profile.html',
                           user=user,
                           has_next=paginate.has_next,
                           images=paginate.items,
                           f_images=f_images)
Beispiel #10
0
 def most_recent_confirmation(self) -> "ConfirmationModel":
     return self.confirmation.order_by(db.desc(
         ConfirmationModel.expire_at)).first()
def images():
    images = Image.query.order_by(db.desc(Image.id)).all()
    return render_template('admin/image.html', images=images)
def fabulous():
    fabulous = Fabulous.query.order_by(db.desc(Fabulous.id)).all()
    return render_template('admin/fabulous.html', fabulous=fabulous)
def comment():
    comments = Comment.query.order_by(db.desc(Comment.id)).all()
    return render_template('admin/comment.html', comments=comments)
def user():
    users = User.query.order_by(db.desc(User.id)).all()
    return render_template('admin/user.html', users=users)
Beispiel #15
0
def index():
    images = Image.query.order_by(db.desc(Image.id)).limit(20).all()
    # images = Image.query.order_by('-id').limit(10).all()
    # images = Image.query.order_by('id desc').limit(10).all()
    return render_template('index.html', images=images)