def new(): if not g.current_user: flash('需要登录才能新增法规',category="danger") return redirect(url_for('login')) form=SearchForm() newform=newLawForm() if newform.validate_on_submit(): lawtype=LawType.objects(id=newform.LawTypeDetail.data).first() law_tags=newform.LawTags.data taglist=law_tags.split() newlaw=Law() newlaw.LawTitle=newform.LawTitle.data newlaw.LawFileNo=newform.LawFileNo.data newlaw.LawPublishDepart=newform.LawDepartment.data newlaw.LawType=lawtype newlaw.LawPublishDate=newform.LawPublishDate.data newlaw.LawMark=newform.LawMark.data newlaw.LawContent=newform.LawContent.data newlaw.LawTags=taglist newlaw.time=datetime.now() newlaw.user=g.current_user newlaw.check="0" newlaw.save() flash('新增成功') return redirect(url_for('default')) return render_template( 'new.html', newform=newform, form=form, year=datetime.now().year, title='新增法律法规' )
def detail(law_id,check): form=SearchForm() commentform=CommentForm() if commentform.validate_on_submit(): update_law=Law.objects(id=law_id).first() new_comment=Comment() new_comment.name=commentform.name.data new_comment.text=commentform.text.data new_comment.date=datetime.now() update_law.Lawcomments.append(new_comment) update_law.save() return redirect(url_for('detail',law_id=law_id)) commentform.name.data="" commentform.text.data="" law=Law.objects(id=law_id,check=check).first() parentType=LawType.objects(id=law.LawType.parentId).first() tags=law.LawTags comments=law.Lawcomments #return (WriteHtml(law,form)) return render_template( 'detail.html', law=law, parentType=parentType, form=form, commentform=commentform, comments=comments, tags=tags, title='法规详细信息', year=datetime.now().year )
def set_lawdetail(parentId): form=newLawForm() form.LawTypeDetail1.choices=[ (str(type.id),type.LawTypName) for type in LawType.objects(parentId=parentId).all() ] return render_template_string("{{form.LawTypeDetail1(class_='form-control')}}",form=form)
def listlaw(page,type): recent=sidebar_data() form=SearchForm() lawtype=LawType.objects(LawTypName=type).first() lawtypedetail=LawType.objects(parentId=str(lawtype.id)).all() lawtypedetailsub=LawType.objects(parentId__in=(str(detail.id) for detail in lawtypedetail)) laws=Law.objects(LawType__in=lawtypedetail,check='1').paginate(page,5) return render_template('listlaw.html', form=form,#搜索 lawtype=lawtype,#父类 laws=laws, recent=recent,#侧边栏数据 lawtypedetail=lawtypedetail,#子类 title='法规列表', lawtypedetailsub=lawtypedetailsub, year=datetime.now().year )#孙子类
def default(): form=SearchForm() types=LawType.objects(parentId='').order_by("+order").all() return render_template('default.html', form=form, year=datetime.now().year, title='主页', types=types)
class LawtypeForm(Form): addType = SelectField('添加类型', choices=[('', ''), ('一级分类', '一级分类'), ('二级分类', '二级分类'), ('三级分类', '三级分类')]) typename = StringField('类型名称', [DataRequired()]) parentName = SelectField( '一级分类', choices=[(str(lawtype.id), lawtype.LawTypName) for lawtype in MYLawType.objects(parentId='').all()]) detailTypeName = SelectField('二级分类', choices=[]) detailTypeName1 = SelectField('二级分类1', choices=[]) typeimage = FileField('类型图标', [DataRequired()]) def validate(self): return True
class newLawForm(Form): LawTitle = StringField('法规标题', [DataRequired()]) LawDepartment = StringField('发布部门') LawFileNo = StringField('法规文号', [DataRequired(), Length(max=255)]) LawType = SelectField('法规分类', choices=[ (str(type.id), type.LawTypName) for type in MYLawType.objects(parentId='').all() ]) LawTypeDetail = SelectField('分类明细', choices=[]) LawTypeDetail1 = SelectField('分类明细', choices=[]) LawPublishDate = DateField('发布日期', [DataRequired()]) LawMark = StringField('备注') LawContent = TextAreaField('法规正文', [DataRequired()]) LawTags = StringField('标签') def validate(self): return True #class PostForm(Form): # title=StringField('Title',[ # DataRequired(), # Length(max=255) # ]) # type=SelectField('Post Type',choices=[ # ('Blog','文字'), # ('VideoBlog','视频'), # ('ImageBlog','图片'), # ('QuoteBlog','Quto') # ]) # text=TextAreaField('内容') # image=StringField('图片URL',[Length(max=500)]) # video=StringField('视频URL',[Length(max=500)]) # author=StringField('作者',[Length(max=500)]) # tag=StringField('Tags') #class OpenIDForm(Form): # openid=StringField('OpenID URL',[DataRequired()],URL)
def edit(law_id): if not g.current_user: flash('需要登录才能修改法规',category="danger") return redirect(url_for('login')) form=SearchForm() fromedit=newLawForm() law=Law.objects(id=law_id).first() ss="" for s in law.LawTags: ss=ss+" "+s if fromedit.validate_on_submit(): fromcomment=CommentForm() law_tags=fromedit.LawTags.data taglist=law_tags.split() lawtyp=LawType.objects(LawTypName=fromedit.LawTypeDetail.data).first() result=Law.objects(id=law_id).update( LawTitle=fromedit.LawTitle.data, LawFileNo=fromedit.LawFileNo.data, LawPublishDepart=fromedit.LawDepartment.data, LawType=lawtyp, LawPublishDate=fromedit.LawPublishDate.data, LawContent=fromedit.LawContent.data, LawMark=fromedit.LawMark.data, LawTags=taglist ) if result==1: flash('修改成功') return redirect(url_for('admin')) return render_template( 'edit.html', form=form, fromedit=fromedit, law=law, tags=ss, year=datetime.now().year, title='修改法规' )
def listlawFrame(page,type): recent=sidebar_data() lawtypedetail=LawType.objects(LawTypName=type).first() laws=Law.objects(LawType=lawtypedetail,check='1').paginate(page,15) return render_template('listlawFrame.html', laws=laws,type=type)
def lawtype(): form=SearchForm() lawtypeform=LawtypeForm() ptypes=LawType.objects(parentId='').all() types=LawType.objects(parentId__ne='').all() if lawtypeform.validate_on_submit(): if lawtypeform.addType.data=='一级分类': type=LawType() #添加显示图片 file=request.files['typeimage'] if file.filename!="": extention=str(file.filename).split('.')[1]#取扩展名 p=app.static_folder+'/image/icon/'+lawtypeform.typename.data+'.'+extention#保存路径 file.save(p)#保存图片 type.typeimage=lawtypeform.typename.data+'.'+extention#保存到数据库里面的文件名 else: type.typeimage='' type.LawTypName=lawtypeform.typename.data type.parentId="" type.save() flash('添加成功','message') elif lawtypeform.addType.data=='二级分类': type=LawType() type.LawTypName=lawtypeform.typename.data type.parentId=lawtypeform.parentName.data type.save() flash('添加成功','message') elif lawtypeform.addType.data=='三级分类': type=LawType() type.LawTypName=lawtypeform.typename.data type.parentId=lawtypeform.detailTypeName.data type.save() flash('添加成功','message') return redirect(url_for('lawtype')) return render_template('lawtype.html',form=form,lawtypeform=lawtypeform,ptypes=ptypes,types=types)