コード例 #1
0
ファイル: timeline.py プロジェクト: Gwill/pin-server-python
def show_timeline_before(timeline_id):
    if g.user_id:
        time_tag = Timeline.objects(id=timeline_id).first().create_at
        user = User.objects(id=g.user_id).first()
        timelines = Timeline.objects(Q(create_at__lt=time_tag)&Q(owner=g.user_id))[:5].order_by('-create_at')
        res_data = timeline_pack(timelines, user)
        return (json.dumps(res_data), 200)
    return ('timeline_before session timeout', 400)
コード例 #2
0
ファイル: timeline.py プロジェクト: Gwill/pin-server-python
def show_timeline():
    if g.user_id:
        user = User.objects(id=g.user_id).first()
        timelines = Timeline.objects(owner=g.user_id)[:5].order_by('-create_at')
        res_data = timeline_pack(timelines, user)
        return (json.dumps(res_data), 200)
    return ('timeline session timeout', 400)
コード例 #3
0
ファイル: admin.py プロジェクト: Gwill/pin-server-python
def admin_del_user(user_id):
    if g.admin:
        user = User.objects(id=user_id).first()
        user.delete()
        pins = Pin.objects(owner=user_id)
        for pin in pins:
            pin.delete()
        timelines = Timeline.objects(owner=user_id)
        for timeline in timelines:
            timeline.delete()
        return redirect(url_for('admin.admin_user'))
    return redirect(url_for('admin.admin_login'))

    
コード例 #4
0
ファイル: pin.py プロジェクト: Gwill/pin-server-python
def pin_post():
    if g.user_id:

        pin_type = request.form['type'] if ('type' in request.form) and request.form['type'] else 1
        content = request.form['content'] if 'content' in request.form else ''
        pic = request.form['pic'] if 'pic' in request.form else ''
        stamp = request.form['stamp'] if ('stamp' in request.form) and request.form['stamp'] else 1
        price = float(request.form['price']) if 'price' in request.form else 1.0
        currency = request.form['currency'] if ('currency' in request.form) and request.form['currency'] else 'CNY'

        # ex_rate = request.form['ex_rate'] if 'ex_rate' in request.form else 1.0

        owner = User.objects(id=g.user_id).first()
        pin = Pin(type=pin_type,
                  content=content,
                  pic=pic,
                  stamp=stamp,
                  price=price,
                  currency=currency,
                  owner=owner,
                  create_at=datetime.utcnow(),
                  avatar=owner.avatar)
        pin.save()

        timeline = Timeline(pin=pin,
                            owner=owner,
                            create_at=datetime.utcnow())
        timeline.save()

        if owner.fans:
            for fan in owner.fans:
                fan_timeline = Timeline(pin=pin,
                                        owner=fan,
                                        create_at=datetime.utcnow())
                fan_timeline.save()

        owner.update(inc__pins_count=1)

        res_data = {
            'pin_id':str(pin.id),
            'type':pin.type,
            'content':pin.content,
            'avatar':pin.avatar,
            'pic':pin.pic,
            'stamp':pin.stamp,
            'currency':pin.currency,
            'price':pin.price,
            'owner_id':str(pin.owner.id),
            'create_at':pin.create_at.strftime('%Y-%m-%d %H:%M:%S'),
        }
        response = make_response(json.dumps(res_data))
        #response.headers
        #response.headers['Version'] = '1'
        return response
    else:
        return ('pin post session timeout', 400)
コード例 #5
0
ファイル: pin.py プロジェクト: Gwill/pin-server-python
def del_pin(pin_id):
    if g.user_id:
        if len(pin_id) == 24:
            pin = Pin.objects(id=pin_id).first()
            if pin:
                pin.delete()

                # delete pin from timeline
                timelines = Timeline.objects(pin=pin_id)
                for timeline in timelines:
                    timeline.delete()
      
                return ('delete success', 200)
            return ('no this pin', 400)
        return ('need pin_id', 400)
    return ('del pin session timeout', 400)