示例#1
0
def dislike(request, user_id):
    response = {'success': False}

    me = request.user
    my_recs = me.get_recommendations()
    my_taste = me.get_taste()

    # If the user_id that he is trying to like is not
    # in his recommendations, return false
    # to prevent liking anyone in the db
    try:
        my_recs.recommendations.index(int(user_id))
    except ValueError:
        return render_json(response)

    # Counting how many times I liked this user (see Taste doc in models)
    if user_id in my_taste.dislikes:
        # F*****g mongodb queries makes me sick...
        # This is for incrementing the counter in {user_id: counter}
        my_taste.update(**{'inc__dislikes__%s' % user_id: 1})
    else:
        my_taste.dislikes = {user_id: 1}
        my_taste.save()

    remove_user_from_recommendations(user_id, my_recs)

    response['success'] = True

    return render_json(response)
示例#2
0
文件: views.py 项目: pengwow/R-ERP
def get_list(request):
    params = request.GET
    print(params)
    result = list()
    zy_objs = ZYImportData.objects.all()
    for item in zy_objs:
        zy_dict = model_to_dict(item)
        result.append(zy_dict)
    # TODO: 分页
    return render_json(result,"获取数据完成")
示例#3
0
def login(request):
    if request.method == "GET":
        return render(request, "login.html")
    data = json.loads(request.body)
    username = data.get("username")
    password = data.get("password")
    ip = get_ip(request)
    # 验证账号
    status, message = verify_account(username, ip)
    if not status:
        return render_json({}, message, code=100001)
    user_obj = auth.authenticate(username=username, password=password)
    if user_obj:
        auth.login(request, user_obj)
        result = dict(id=user_obj.id,
                      username=user_obj.username,
                      token=get_token(user_obj.username, 60))
        return render_json(result, "登录成功!")
    else:
        update_failnumber(username, ip)
        return render_json({}, "登录失败!", code=100002)
示例#4
0
文件: views.py 项目: pengwow/R-ERP
def upload_report(request):
    if request.method == "GET":
        return render(request, "login.html")
    fd = request.FILES.get('file')
    report_data = fd.read()
    storage_path = get_storage_path()
    file_name = str(uuid.uuid1())
    file_path = os.path.join(storage_path,file_name)
    with open(file_path,'wb') as uuid_fd:
        uuid_fd.write(report_data)
    data = xlrd.open_workbook(file_path)
    table = data.sheets()[0] #通过索引顺序获取
    nrows = table.nrows
    # ncols = table.ncols
    title = table.row_values(0)
    # print(title)
    zy_obj = ZYImportData()
    models_dict = zy_obj.get_models_dict()
    for i in range(1, nrows):
        row_dict = dict(zip(title,table.row_values(i)))
        new_dict = dict()
        for k, v in row_dict.items():
            new_key = models_dict.get(k)
            if new_key:
                new_dict[new_key] = v
        if new_dict.get('datetime',''):
            new_dict['datetime'] = datetime.strptime(new_dict.get('datetime',''),'%Y/%m/%d')
        if new_dict.get('id'):
            try:
                zy_obj = ZYImportData(**new_dict)
                zy_obj.save()
            except Exception as e:
                print(e)
                print(new_dict)
    # print(ZYImportData._meta.get_field('refund').help_text)
    # print(ZYImportData().get_models_dict())
    return render_json({},"导入成功!")
示例#5
0
def user_info(request):
    from .temp import get_role, user_info
    userinfo = user_info()
    return render_json(userinfo, "用户信息")
示例#6
0
def twofactor(request):
    result = dict(stepCode=random.randint(0, 1))
    return render_json(result)
示例#7
0
def logout(request):
    if request.method == "GET":
        raise Exception("1111")
    redirect('user/login')
    return render_json("注销成功")
示例#8
0
def reset_account(request):
    data = json.loads(request.body)
    username = data.get('username')
    reset_user(username)
    return render_json({}, "重置账号完成!")
示例#9
0
def match(request):
    response = {}
    return render_json(response)
示例#10
0
def recommendations(request):
    response = {'recs': None}

    me = request.user

    my_recs = me.get_recommendations()

    if RESET_RECOMMENDATION_VIEWS_CACHE:
        start_temp = request.user.last_seeked_user_index
        start = start_temp - SEARCH_WINDOW

        if start < 0:
            start = 0

        stop = start + SEARCH_WINDOW

    else:
        # If there are still recommendations in my bucket, return them
        if len(my_recs.recommendations) > 0:
            print "This user still has users to like"
            response['recs'] = my_recs.recommendation_views
            return render_json(response)

        start = request.user.last_seeked_user_index
        stop = start + SEARCH_WINDOW

    users = SallasanaUser.objects.all()[start:stop]

    # TODO: Renan separate this as a neat function
    # If there is less users than the search window
    # the end will become the starting point plus the
    # number of users found
    me.last_seeked_user_index = start + users.count()
    me.save()

    new_rec_views = []
    new_recs = []

    for user in users:
        # Don't return myself
        if user == request.user:
            continue

        user_view = UserView(user, me).to_dict()

        # Filter according to the user settings
        # TODO: Renan do this in the sql query
        # TODO: Add the location filtering
        if GENDER[user_view['gender']] == request.user.interest_gender:
            new_rec_views.append(user_view)
            new_recs.append(user.id)

    # Saving these to my recommendations list
    my_recs.recommendation_views = new_rec_views
    my_recs.recommendations = new_recs
    my_recs.save()

    response['recs'] = new_rec_views

    #user = request.user
    return render_json(response)
示例#11
0
def ping(request):
    response = {}
    return render_json(response)