本文整理汇总了Python中uliweb.utils.generic.AddView类的典型用法代码示例。如果您正苦于以下问题:Python AddView类的具体用法?Python AddView怎么用?Python AddView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AddView类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:chyhutu,项目名称:plugs,代码行数:29,代码来源:views.py
示例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()
开发者ID:chyhutu,项目名称:plugs,代码行数:59,代码来源:views.py
示例3: forumtopictype_add
def forumtopictype_add(self):
"""
添加新的论坛
"""
from uliweb.utils.generic import AddView
view = AddView('forumtopictype', url_for(ForumView.admin_forumtopictype))
return view.run()
开发者ID:pyhunterpig,项目名称:plugs,代码行数:8,代码来源:views.py
示例4: category_add
def category_add(self):
"""
添加新的板块
"""
from uliweb.utils.generic import AddView
view = AddView('forumcategory', url_for(ForumView.admin_category))
return view.run()
开发者ID:pyhunterpig,项目名称:plugs,代码行数:8,代码来源:views.py
示例5: forum_add
def forum_add(self):
"""
添加新的论坛
"""
from uliweb.utils.generic import AddView
view = AddView("forum", url_for(ForumView.admin_forum))
return view.run()
开发者ID:datakungfu,项目名称:plugs,代码行数:8,代码来源:views.py
示例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()
开发者ID:damonchen,项目名称:uliweb-doc,代码行数:8,代码来源:views.py
示例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)
开发者ID:tangjn,项目名称:plugs,代码行数:10,代码来源:views.py
示例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()
开发者ID:datakungfu,项目名称:plugs,代码行数:53,代码来源:views.py
示例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))
开发者ID:datakungfu,项目名称:plugs,代码行数:15,代码来源:views_admin.py
示例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()
开发者ID:limodou,项目名称:plugs,代码行数:16,代码来源:views.py
示例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
开发者ID:uliwebext,项目名称:uliweb-redbreast-doc,代码行数:17,代码来源:views.py
示例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()
开发者ID:Yixiaohan,项目名称:uliwebzone,代码行数:44,代码来源:views.py
示例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)
开发者ID:Yixiaohan,项目名称:uliwebzone,代码行数:20,代码来源:views.py
示例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)
开发者ID:qq40660,项目名称:forum2,代码行数:20,代码来源:views.py
示例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()
开发者ID:datakungfu,项目名称:plugs,代码行数:40,代码来源:views.py
示例16: add
def add(self):
"""
添加课程
"""
from uliweb.utils.generic import AddView
def get_url(id):
return url_for(self.__class__.index)
def get_form_field(name):
from uliweb.form import SelectField
if name == 'teachers':
return SelectField('教师', multiple=True, help_string='添加除你之外的教师', datatype=int)
def pre_save(data):
if request.user.id not in data['teachers']:
data['teachers'].append(request.user.id)
view = AddView(self.model, ok_url=get_url,
get_form_field=get_form_field,
pre_save=pre_save,
form_args={'title':'添加新课程'})
return view.run()
开发者ID:Yixiaohan,项目名称:uliwebzone,代码行数:23,代码来源:views.py
示例17: add
def add(self):
from uliweb.utils.generic import AddView
def pre_save(data):
data['submitter'] = request.user.id
data['submitter_date'] = datetime.datetime.now()
def post_save(obj, data):
Workflow = functions.get_workflow()
workflow = Workflow.create("YesNoWorkflow", operator=request.user)
workflow.ref_unique_id = "yesno,%d" % obj.id
workflow.start()
workflow.run()
obj.workflow = workflow.get_id()
obj.save()
view = AddView(self.model, url_for(self.__class__.list),
pre_save=pre_save, post_save=post_save)
result = view.run()
return result
开发者ID:uliwebext,项目名称:uliweb-redbreast-doc,代码行数:24,代码来源:views.py
示例18: add
def add(self):
from uliweb.utils.generic import AddView
view = AddView(self.model, url_for(BlogView.list), default_data={'author':request.user.id})
return view.run()
开发者ID:chu888chu888,项目名称:Python-uliwebzone,代码行数:5,代码来源:views.py
示例19: 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")
User = get_model("user")
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):
from uliweb import functions
from uliweb.utils.common import Serial
from uliweb.mail import Mail
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(),
last_post=obj.id,
)
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(),
last_post=obj.id,
)
self._clear_files(obj.slug, data["content"])
# 増加发送邮件的处理
emails = []
for u_id in Post.filter(
(Post.c.topic == int(topic_id)) & (Post.c.reply_email == True) & (Post.c.floor < obj.floor)
).values(Post.c.posted_by):
user = User.get(u_id[0])
if user and user.email and (user.email not in emails) and (user.email != request.user.email):
emails.append(user.email)
if not emails:
return
_type = settings.get_var("PARA/FORUM_REPLY_PROCESS", "print")
url = "%s/forum/%s/%s" % (settings.get_var("PARA/DOMAIN"), forum_id, topic_id)
d = {"url": str(url)}
mail = {
"from_": settings.get_var("PARA/EMAIL_SENDER"),
"to_": emails,
"subject": settings.get_var("FORUM_EMAIL/FORUM_EMAIL_TITLE"),
"message": settings.get_var("FORUM_EMAIL/FORUM_EMAIL_TEXT") % d,
"html": True,
}
if _type == "mail":
Mail().send_mail(**mail)
elif _type == "noprint":
pass
elif _type == "print":
print mail
elif _type == "redis":
redis = functions.get_redis()
_t = Serial.dump(mail)
redis.lpush("send_mails", _t)
def get_form_field(name):
from uliweb.form import TextField
if name == "content":
return TextField("内容", required=True, convert_html=True, rows=20)
slug = uuid.uuid1().hex
data = {"slug": slug, "reply_email": False, "content": ""}
def success_data(obj, data):
import math
return {"page": int(math.ceil(1.0 * obj.floor / settings.get_var("PARA/FORUM_PAGE_NUMS")))}
view = AddView(
"forumpost",
url_for(ForumView.topic_view, forum_id=int(forum_id), topic_id=int(topic_id)),
hidden_fields=["slug"],
template_data={"slug": slug},
data=data,
success_data=success_data,
pre_save=pre_save,
get_form_field=get_form_field,
post_save=post_save,
)
return view.run(json_result=True)
开发者ID:tangjn,项目名称:plugs,代码行数:96,代码来源:views.py
示例20: new_reply
def new_reply(self, forum_id, topic_id, parent_id):
"""
发表新回复
"""
from uliweb.utils.generic import AddView
Forum = get_model("forum")
forum = Forum.get(int(forum_id))
Topic = get_model("forumtopic")
topic = Topic.get(int(topic_id))
Post = get_model("forumpost")
post = Post.get(int(parent_id))
User = get_model("user")
def pre_save(data):
from sqlalchemy.sql import select, func
data["topic"] = int(topic_id)
data["parent"] = int(parent_id)
data["floor"] = (do_(select([func.max(Post.c.floor)], Post.c.parent == post.id)).scalar() or 0) + 1
def post_save(obj, data):
from uliweb import functions
from uliweb.utils.common import Serial
from uliweb.mail import Mail
Post.filter(Post.c.id == int(parent_id)).update(
num_replies=Post.c.num_replies + 1, last_post_user=request.user.id, last_reply_on=date.now()
)
self._clear_files(obj.slug, data["content"])
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(),
last_post=obj.id,
)
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(),
last_post=obj.id,
)
# 増加发送邮件的处理
emails = []
for u_id in Post.filter(
(Post.c.topic == int(topic_id)) & (Post.c.reply_email == True) & (Post.c.id == parent_id)
).values(Post.c.posted_by):
user = User.get(u_id[0])
if user and user.email and (user.email not in emails) and (user.email != request.user.email):
emails.append(user.email)
if not emails:
return
_type = settings.get_var("PARA/FORUM_REPLY_PROCESS", "print")
url = "%s/forum/%s/%s" % (settings.get_var("PARA/DOMAIN"), forum_id, topic_id)
d = {"url": str(url)}
mail = {
"from_": settings.get_var("PARA/EMAIL_SENDER"),
"to_": emails,
"subject": settings.get_var("FORUM_EMAIL/FORUM_EMAIL_TITLE"),
"message": settings.get_var("FORUM_EMAIL/FORUM_EMAIL_TEXT") % d,
"html": True,
}
if _type == "mail":
Mail().send_mail(**mail)
elif _type == "print":
print mail
elif _type == "redis":
redis = functions.get_redis()
_t = Serial.dump(mail)
redis.lpush("send_mails", _t)
def get_form_field(name):
from uliweb.form import TextField
if name == "content":
return TextField("内容", required=True, convert_html=True, default="")
slug = uuid.uuid1().hex
data = {"slug": slug, "reply_email": False, "content": _("RE") + " @" + unicode(post.posted_by) + ": "}
has_email = bool(request.user and request.user.email)
view = AddView(
"forumpost",
url_for(ForumView.topic_view, forum_id=int(forum_id), topic_id=int(topic_id)),
# default_data={'last_post_user':request.user.id, 'last_reply_on':date.now()},
hidden_fields=["slug"],
data=data,
pre_save=pre_save,
get_form_field=get_form_field,
post_save=post_save,
template_data={"forum": forum, "topic": topic, "has_email": has_email, "slug": slug},
)
return view.run()
开发者ID:tangjn,项目名称:plugs,代码行数:97,代码来源:views.py
注:本文中的uliweb.utils.generic.AddView类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论