Esempio n. 1
0
def upload_movie(conn, dic):
    dic1 = comment.service_recv(conn)
    movie_name = dic1.get("movie_name")
    movie_md5 = dic1.get("movie_md5")
    flag = comment.check_movie(movie_name, movie_md5)
    if flag:
        dic_back = {"flag": 0, "msg": "电影已经存在!"}
    else:
        dic_back = {"flag": 1, "msg": "上传准备就绪!"}
    comment.service_send(conn, dic_back)
    movie_size = dic1.get("movie_size")
    movie_path = os.path.join(UPLOAD_MOVIES, movie_name)
    w_movie(conn, movie_path, movie_size)
    dic2 = {"msg": "上传成功!"}
    user_id = dic.get("user_id")
    is_free = dic1.get("is_free")
    movie_obj = models.Movie(name=movie_name,
                             path=movie_path,
                             is_free=is_free,
                             is_delete=0,
                             file_md5=movie_md5,
                             upload_time=comment.get_time(),
                             user_id=user_id)
    movie_obj.save()
    comment.service_send(conn, dic2)
Esempio n. 2
0
def release_notice(conn, dic):
    dic_back = comment.service_recv(conn)
    title = dic_back.get("title")
    content = dic_back.get("content")
    user_id = dic.get("user_id")
    notice_obj = models.Notice(title=title,
                               content=content,
                               create_time=comment.get_time(),
                               user_id=user_id)
    notice_obj.save()
    dic1 = {"msg": "发布成功!"}
    comment.service_send(conn, dic1)
Esempio n. 3
0
def register(conn, dic):
    name = dic.get("name")
    pwd = dic.get("pwd")
    pwd_md = comment.get_md5(pwd)
    flag = comment.check_user_name(name)
    if flag:
        dic_back = {"flag": 0, "msg": "用户已经存在!"}
    else:
        user_obj = models.User(name=name, password=pwd_md, is_vip=0, is_locked=0, user_type=dic.get("user_type"),
                               register_time=comment.get_time())
        user_obj.save()
        dic_back = {"flag": 1, "msg": "注册成功!"}
    comment.service_send(conn, dic_back)
Esempio n. 4
0
def download_charge_movie(conn, dic):
    movies_list = comment.get_movies_list(flag=2)
    if movies_list:
        dic1 = {"flag": 1, "movies_list": movies_list}
        comment.service_send(conn, dic1)
    else:
        dic1 = {"flag": 0, "msg": "暂无可以下载的电影!"}
        comment.service_send(conn, dic1)
        return
    dic_back = comment.service_recv(conn)
    movie_name = dic_back.get("movie_name")
    movie_path = os.path.join(UPLOAD_MOVIES, movie_name)
    movie_size = os.path.getsize(movie_path)
    dic3 = {"movie_size": movie_size}
    comment.service_send(conn, dic3)
    r_movie(conn, movie_path, movie_size)
    user_id = dic.get("user_id")
    movie_id = models.Movie.select(name=movie_name)[0].id
    record = models.DownloadRecord(user_id=user_id, movie_id=movie_id, download_time=comment.get_time())
    record.save()
    dic2 = {"msg": "下载成功!"}
    comment.service_send(conn, dic2)