示例#1
0
文件: views.py 项目: xiaowa3210/dcWeb
def adduser():
    form = AddProjectForm()
    if form.is_submitted():
        username =request.form.get("name")
        faculty =request.form.get("faculty")
        grade = request.form.get("grade")
        teammate = {  "name": username,
          "faculty": faculty,
          "grade": grade}
        teammates.append(teammate)
        flash("保存成功")
        return render_template('admin/addproject.html', form=AddProjectForm(), users=teammates)

    return render_template('admin/users.html', form=form)
示例#2
0
文件: views.py 项目: xiaowa3210/dcWeb
def operate(project_id):
    if  request.form.get("operate") == "编辑":
        print("3333")
        project = Project.query.filter(Project.id==project_id).one()
        form  =AddProjectForm()
        return render_template('admin/editproject.html',project=project,form=form)
    if  request.form.get("operate") == "删除":
        print("4444")
        p = Project.query.filter_by(id=project_id).first()
        db.session.delete(p)
        db.session.commit()
        flash("删除成功")
    projects = Project.query.order_by(Project.create_time.desc()).all()
    return redirect(url_for('admin.query_projects'))
示例#3
0
文件: views.py 项目: xiaowa3210/dcWeb
def editproject(project_id):
    form = AddProjectForm()
    if form.is_submitted():
        if request.method == 'POST':
            print("555")
            # f1= request.files["photo"]
            photos = request.files.getlist('photo')
            # f2 = request.files["video"]
            files = request.files.getlist('video')
            base_path = path.abspath(path.dirname(__file__))
            photo_db_paths = []
            video_db_paths = []
            for file in photos:
                filename = secure_filename(file.filename)
                upload_path = os.path.join(base_path, 'uploads', filename)
                photo_db_paths.append(upload_path)
                file.save(upload_path)
            for file in files:
                filename = secure_filename(file.filename)
                upload_path = os.path.join(base_path, 'uploads', filename)
                video_db_paths.append(upload_path)
                file.save(upload_path)
            photoPaths=";".join(photo_db_paths)
            videoPaths=";".join(video_db_paths)
        project  = Project.query.filter(Project.id == project_id).one()
        print(project)
        print(type(project))
        project.pname =  form.name.data
        project.introduction =form.introduction.data
        project.picture = photoPaths
        project.vedio = videoPaths
        # project = Project(pname = form.name.data,introduction =form.introduction.data,picture=photoPaths,vedio=videoPaths)
        # db.session.add(project)
        db.session.commit()
        flash("保存成功")
    return redirect(url_for('admin.query_projects'))
示例#4
0
文件: views.py 项目: xiaowa3210/dcWeb
def addproject():
    form = AddProjectForm()

        # print(request.form.get("adduser"))
        # if request.form.get("adduser") == "+":
        #     print("3e764354")
        #     print(form.name.data)
        #     global a
        #     a = form.name.data
        #     return render_template('admin/users.html')
        # if request.form.get("submit") == "adduser":
        #     username =request.form.get("username")
        #     pro = request.form.get("pro")
        #     grade = request.form.get("grade")
        #     teammate = {"name":username,"faculty":pro,"grade":grade}
        #     global  teammates
        #     teammates.append(teammate)
        #     flash("保存成功")
        #     form.name.data = a
        #     print(form.name.data)
        #     return render_template('admin/addproject.html', form=form, users=teammates)
        # if request.method == 'POST':
    if form.is_submitted():
        print("555")
        # f1= request.files["photo"]
        photos = request.files.getlist('photo')
        # f2 = request.files["video"]
        files = request.files.getlist('video')
        base_path = path.abspath(path.dirname(__file__))
        print(path.dirname(__file__))
        print(base_path.split("app")[-2] + "upload")
        base_path = base_path.split("app")[-2]
        photoss = []
        video_db_paths = []
        for file in photos:
            print("000000")
            print(allowed_photo(file.filename))
            if allowed_photo(file.filename):
                filename = secure_filename(file.filename)
                upload_path = os.path.join(base_path, 'uploads', filename)
                photo= {"title":filename,"path":upload_path}
                file.save(upload_path)
                photoss.append(photo)
            else:
                flash("您上传的文件不是图片类型!")
                return render_template('admin/addproject.html', form=form)
        for file in files:
            if  allowed_video(file.filename):
                filename = secure_filename(file.filename)
                upload_path = os.path.join(base_path, 'uploads', filename)
                video_db_paths.append(upload_path)
                file.save(upload_path)
            else:
                flash("您上传的文件不是视频类型!")
                return render_template('admin/addproject.html', form=form)
        # print("22222222" + photos)
        photoPaths={"pics":photoss}
        # print("33333" + photoPaths)


        videoPaths=";".join(video_db_paths)
        global teammates

            # upload_path = path.join(base_path, 'uploads/')
            # print(upload_path)
            # file_name1 = upload_path + secure_filename(f1.filename)
            # f1.save(file_name1)
            # file_name2 = upload_path + secure_filename(f2.filename)
            # f2.save(file_name2)
        teaminfo = {"teammates":teammates}
        print("34222222222")
        print(teaminfo)
        print(photoPaths)
        project = Project(pname = form.name.data,introduction =form.introduction.data,teaminfo=str(teaminfo),picture= str(photoPaths),vedio=videoPaths)
        db.session.add(project)
        db.session.commit()
        
        teammates =[]

        flash("保存成功")
    return render_template('admin/addproject.html', form=form, users=teammates)
示例#5
0
def addproject():
    form = AddProjectForm()
    if form.is_submitted():
        print("555")
        # f1= request.files["photo"]
        photos = request.files.getlist('photo')
        # f2 = request.files["video"]
        files = request.files.getlist('video')
        base_path = path.abspath(path.dirname(__file__))
        photoss = []
        video_db_paths = []
        for file in photos:
            if allowed_photo(file.filename):
                filename = secure_filename(file.filename)
                upload_path = os.path.join(base_path, 'uploads', filename)
                photo = {"title": filename, "path": upload_path}
                file.save(upload_path)
                photoss.append(photo)
            else:
                flash("您上传的文件不是图片类型!")
                return render_template('admin/addproject.html', form=form)
        for file in files:
            if allowed_video(file.filename):
                filename = secure_filename(file.filename)
                upload_path = os.path.join(base_path, 'uploads', filename)
                video_db_paths.append(upload_path)
                file.save(upload_path)
            else:
                flash("您上传的文件不是视频类型!")
                return render_template('admin/addproject.html', form=form)

        photoPaths = {"pics": photoss}

        videoPaths = ";".join(video_db_paths)
        global teammates

        teaminfo = {"teammates": teammates}
        t = time.time()
        print(t)  # 原始时间数据
        print(int(t))  # 秒级时间戳
        tr = int(round((t*1000)))
        print(tr)  # 毫秒级时间戳

        nowTime = lambda: int(round(t * 1000))
        print(nowTime());  # 毫秒级时间戳,基于lambda

        print("2222222")
        print(form.isPublish.data)
        print(type(form.isPublish.data))
        if(form.isPublish.data):
            publish_flag = 1
        else:
            publish_flag = 0


        nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')  # 现在
        project = nProject(project_id = str(tr),title=form.name.data, brief=form.introduction.data, member_info=str(teaminfo),
                           ban_url=str(photoPaths),delete_flag=0,publish_flag=publish_flag,modified_flag=0,create_time=nowTime,publish_time=nowTime,broad_time=nowTime,creator_id=1)
        db.session.add(project)
        db.session.commit()

        teammates = []
        flash("保存成功")
    return render_template('back01/addproject.html', form=form, users=teammates)
示例#6
0
def edit(project_id):
    print("3333")
    project = Project.query.filter(Project.id == project_id).one()
    form  =AddProjectForm()
    return render_template('back01/editproject.html', project=project, form=form)