本文整理汇总了Python中uliweb.utils.generic.AddView类的典型用法代码示例。如果您正苦于以下问题:Python AddView类的具体用法?Python AddView怎么用?Python AddView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AddView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generic_add
def generic_add(model=None, get_url=get_url, layout='layout.html',
template=None, title=None, view=None, data=None):
from uliweb.utils.generic import AddView
from uliweb import response
if not view:
Model = get_model(model)
if not model or not Model:
return error("Can't find model [%s], please check it" % model)
get_url = partial(get_url, action='view')
view = AddView(model, get_url)
result = view.run()
if isinstance(result, dict):
template = template or 'generic_add.html'
response.template = template
if not title:
name = getattr(model, '__verbose_name__', '')
title = _("Add") + safe_unicode(name)
elif callable(title):
title = title('add')
data = data or {}
result['get_url'] = get_url
result['title'] = title
result.update(data)
return render_template(template, layout, result)
else:
return result
示例2: new_topic
def new_topic(self, id):
"""
发表新主题
"""
from uliweb.utils.generic import AddView
type = request.GET.get('type', '')
Forum = get_model('forum')
forum = Forum.get(int(id))
if forum.manager_only and not forum.managers.has(request.user.id):
error('本论坛被设置为只有管理员才可以发贴!')
def post_save(obj, data):
from sqlalchemy.sql import select, func
Post = get_model('forumpost')
p = Post(topic=obj.id, posted_by=request.user, slug=obj.slug,
content=data['content'], floor=1, reply_email=data['reply_email'])
p.save()
obj.last_post = p.id
obj.save()
Forum.filter(Forum.c.id==int(id)).update(num_posts=Forum.c.num_posts+1,
num_topics=Forum.c.num_topics+1,
last_post_user=request.user.id, last_reply_on=date.now(), last_post=p.id)
#根据slug的值清除附件中无效的文件
self._clear_files(obj.slug, data['content'])
def get_form_field(name):
from uliweb.utils.generic import ReferenceSelectField
from uliweb.form import TextField, BooleanField
forumtopictype = get_model('forumtopictype')
if name == 'content':
return TextField('内容', required=True, convert_html=True)
elif name == 'topic_type':
if type:
return ReferenceSelectField('forumtopictype',
condition=forumtopictype.c.forum==forum.id, label='主题分类名称', default=type)
else:
return ReferenceSelectField('forumtopictype',
condition=forumtopictype.c.forum==forum.id, label='主题分类名称')
elif name == 'reply_email':
return BooleanField('有回复时邮件通知我')
slug = uuid.uuid1().hex
data = {'slug':slug, 'reply_email':False, 'enable_comment':True}
has_email = bool(request.user and request.user.email)
view = AddView('forumtopic', url_for(ForumView.forum_index, id=int(id)),
default_data={'forum':int(id), 'last_post_user':request.user.id, 'last_reply_on':date.now()},
hidden_fields=['slug'], data=data,
post_save=post_save, get_form_field=get_form_field, template_data={'forum':forum, 'has_email':has_email, 'slug':slug})
return view.run()
示例3: forumtopictype_add
def forumtopictype_add(self):
"""
添加新的论坛
"""
from uliweb.utils.generic import AddView
view = AddView('forumtopictype', url_for(ForumView.admin_forumtopictype))
return view.run()
示例4: category_add
def category_add(self):
"""
添加新的板块
"""
from uliweb.utils.generic import AddView
view = AddView('forumcategory', url_for(ForumView.admin_category))
return view.run()
示例5: forum_add
def forum_add(self):
"""
添加新的论坛
"""
from uliweb.utils.generic import AddView
view = AddView("forum", url_for(ForumView.admin_forum))
return view.run()
示例6: add
def add(self):
from uliweb.utils.generic import AddView
def get_url(id):
return url_for(BlogView.view, id=id)
view = AddView(self.model, ok_url=get_url)
return view.run()
示例7: forumtopictype_add
def forumtopictype_add(self):
"""
添加新的论坛
"""
from uliweb.utils.generic import AddView
forum_id = int(request.POST.get("forum_id"))
view = AddView("forumtopictype", success_data=True, default_data={"forum": forum_id})
return view.run(json_result=True)
示例8: new_topic
def new_topic(self, id):
"""
发表新主题
"""
from uliweb.utils.generic import AddView
import uuid
Forum = get_model("forum")
forum = Forum.get(int(id))
def post_save(obj, data):
from sqlalchemy.sql import select, func
Post = get_model("forumpost")
p = Post(topic=obj.id, posted_by=request.user, content=data["content"], floor=1)
p.save()
Forum.filter(Forum.c.id == int(id)).update(
num_posts=Forum.c.num_posts + 1,
num_topics=Forum.c.num_topics + 1,
last_post_user=request.user.id,
last_reply_on=date.now(),
)
# 根据slug的值清除附件中无效的文件
self._clear_files(obj.slug, data["content"])
def get_form_field(name):
from uliweb.utils.generic import ReferenceSelectField
from uliweb.form import TextField
forumtopictype = get_model("forumtopictype")
if name == "content":
return TextField("内容", required=True, rows=20, convert_html=True)
if name == "topic_type":
return ReferenceSelectField(
"forumtopictype", condition=forumtopictype.c.forum == forum.id, label="主题分类名称"
)
slug = uuid.uuid1().hex
data = {"slug": slug}
view = AddView(
"forumtopic",
url_for(ForumView.forum_index, id=int(id)),
default_data={"forum": int(id), "last_post_user": request.user.id, "last_reply_on": date.now()},
hidden_fields=["slug"],
data=data,
post_save=post_save,
get_form_field=get_form_field,
template_data={"forum": forum},
)
return view.run()
示例9: add
def add(self):
from uliweb.utils.generic import AddView
from uliweb.orm import get_model
from forms import AddUserForm
def post_save(obj, data):
obj.set_password(settings.USER_ADMIN.DEFAULT_PASSWORD)
if request.user.is_superuser:
view = AddView('user', get_url('view'), post_save=post_save, form_cls=AddUserForm)
return view.run()
else:
flash(_('You have no previlege to create user.'), 'error')
return redirect(url_for(config_users_list))
示例10: add
def add(self):
"""
Add new role
"""
from uliweb.utils.generic import AddView
default_data = {'reverse':False}
fields = [
{'name':'name', 'verbose_name':_('Name')},
{'name':'description', 'verbose_name':_('Description')},
]
view = AddView(self.model, url_for(self.__class__.view, _format=True), default_data=default_data, fields=fields)
return view.run()
示例11: add
def add(self):
from uliweb.utils.generic import AddView
helper = ApproveHelper()
def pre_save(data):
data["submitter"] = request.user.id
data["submitter_date"] = datetime.datetime.now()
def post_save(obj, data):
helper.bind(obj)
helper.create_workflow()
view = AddView(self.model, url_for(self.__class__.list), pre_save=pre_save, post_save=post_save)
result = view.run()
return result
示例12: add_chapter
def add_chapter(self, t_id):
"""
増加章节, t_id为教程id
"""
from uliweb.utils.generic import AddView
from sqlalchemy.sql import func
obj = self.model.get_or_notfound(int(t_id))
if not self._can_edit_tutorial(obj):
flash("你无权添加新章节", 'error')
# return redirect(url_for(TutorialView.read, id=t_id))
Redirect(url_for(TutorialView.read, id=t_id))
def get_url(**kwargs):
return url_for(TutorialView.view_chapter, **kwargs)
def pre_save(data):
if 'parent' in request.GET:
data['parent'] = int(request.GET.get('parent'))
data['tutorial'] = int(t_id)
order, = self.model_chapters.filter(self.model_chapters.c.tutorial==int(t_id)).values_one(func.max(self.model_chapters.c.order))
data['order'] = order+1 if order>0 else 1
# data['content'] = self._prepare_content(data['content'], data['render'])
data['html'] = self._get_chapter_html(data['content'], data['format'], data['render'], data['scrollable'])
data['chars_count'] = len(data['content'])
data['modified_date'] = date.now()
data['modified_user'] = request.user.id
data['format'] = '2'
def post_save(obj, data):
obj.tutorial.modified_date = date.now()
obj.tutorial.modified_user = request.user.id
obj.tutorial.save();
#删除章节顺序cache
cache = functions.get_cache()
cache.delete(self._get_tutorial_chapters_cache_key(int(t_id)))
template_data = {'object':obj}
data = {'scrollable':True}
view = AddView(self.model_chapters, ok_url=get_url, pre_save=pre_save,
template_data=template_data, post_save=post_save, data=data)
return view.run()
示例13: add_paragraph_comment
def add_paragraph_comment(self, cid):
"""
添加某个段落的评论
"""
from uliweb.utils.generic import AddView
def post_save(obj, data):
t = obj.chapter.tutorial
t.last_comment_user = request.user.id
t.last_comment_date = date.now()
t.comments_count += 1
t.save()
obj.chapter.comments_count += 1
obj.chapter.save()
default_data = {'chapter':int(cid), 'anchor':int(request.GET.get('para'))}
view = AddView(self.model_comments, success_data=self._get_comment_data,
default_data=default_data, post_save=post_save)
return view.run(json_result=True)
示例14: admin_forum_add
def admin_forum_add(self):
"""
添加新的论坛
"""
from uliweb.utils.generic import AddView, get_field_display
def post_created_form(fcls, model):
fcls.managers.choices = [('', '')]
def success_data(obj, data):
d = obj.to_dict()
d['managers'] = convert_managers(None, obj)
return d
view = AddView(self.model,
success_data=success_data,
post_created_form=post_created_form,
default_data={'category':request.GET.get('category')},
)
return view.run(json_result=True)
示例15: new_post
def new_post(self, forum_id, topic_id):
"""
发表新回复
"""
from uliweb.utils.generic import AddView
Post = get_model("forumpost")
Topic = get_model("forumtopic")
Forum = get_model("forum")
def pre_save(data):
from sqlalchemy.sql import select, func
data["topic"] = int(topic_id)
data["floor"] = (do_(select([func.max(Post.c.floor)], Post.c.topic == int(topic_id))).scalar() or 0) + 1
def post_save(obj, data):
Topic.filter(Topic.c.id == int(topic_id)).update(
num_replies=Topic.c.num_replies + 1, last_post_user=request.user.id, last_reply_on=date.now()
)
Forum.filter(Forum.c.id == int(forum_id)).update(
num_posts=Forum.c.num_posts + 1, last_post_user=request.user.id, last_reply_on=date.now()
)
self._clear_files(obj.slug, data["content"])
def get_form_field(name):
from uliweb.form import TextField
if name == "content":
return TextField("内容", required=True, convert_html=True, rows=20)
view = AddView(
"forumpost",
url_for(ForumView.topic_view, forum_id=int(forum_id), topic_id=int(topic_id)),
hidden_fields=["slug"],
pre_save=pre_save,
get_form_field=get_form_field,
post_save=post_save,
)
return view.run()