本文整理汇总了Python中websauna.utils.slug.uuid_to_slug函数的典型用法代码示例。如果您正苦于以下问题:Python uuid_to_slug函数的具体用法?Python uuid_to_slug怎么用?Python uuid_to_slug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uuid_to_slug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_edit_choice_question
def test_edit_choice_question(browser: DriverAPI, tutorial_req, web_server, dbsession):
"""Change choice's assigned question in edit."""
from .tutorial import Question
from .tutorial import Choice
with transaction.manager:
q = Question(question_text="What is love")
dbsession.add(q)
dbsession.flush()
q2 = Question(question_text="Who shot JFK")
dbsession.add(q2)
dbsession.flush()
q2_slug = uuid_to_slug(q2.uuid)
c = Choice(choice_text="Foobar", question=q)
dbsession.add(c)
dbsession.flush()
c_slug = uuid_to_slug(c.uuid)
b = browser
create_logged_in_user(dbsession, tutorial_req.registry, web_server, browser, admin=True)
b.visit("{}/admin/models/choice/{}/edit".format(web_server, c_slug))
b.select("question", q2_slug)
b.find_by_name("save").click()
assert b.is_element_present_by_css("#msg-changes-saved")
with transaction.manager:
c = dbsession.query(Choice).get(1)
assert c.question.uuid == slug_to_uuid(q2_slug)
示例2: wallet_root
def wallet_root(wallet_root, request):
"""Root of all hosted wallet resources.
When wallet folder is accessed without path key, redirect to the users own wallet."""
url = request.resource_url(wallet_root[uuid_to_slug(request.user.uuid)])
return httpexceptions.HTTPFound(url)
示例3: create_activation
def create_activation(request, user):
"""Create through-the-web user sign up with his/her email.
We don't want to force the users to pick up an usernames, so we just generate an username.
The user is free to change their username later.
"""
assert user.id
user.username = user.generate_username()
user.registration_source = "email"
db = get_session(request)
Activation = request.registry.getUtility(IActivationClass)
activation = Activation()
db.add(activation)
user.activation = activation
db.flush()
# TODO Create a hook for this, don't assume create_activation() call
# TODO We don't need pystache just for this!
context = {
'link': request.route_url('activate', user_id=uuid_to_slug(user.uuid), code=user.activation.code)
}
send_templated_mail(request, [user.email], "login/email/activate", context)
site_creator = get_site_creator(request.registry)
site_creator.check_empty_site_init(request.dbsession, user)
示例4: detail
def detail(request: Request):
# Convert base64 encoded UUID string from request path to Python UUID object
question_uuid = slug_to_uuid(request.matchdict["question_uuid"])
question = request.dbsession.query(Question).filter_by(uuid=question_uuid).first()
if not question:
raise HTTPNotFound()
if request.method == "POST":
# Check that CSRF token was good
check_csrf_token(request)
question = request.dbsession.query(Question).filter_by(uuid=question_uuid).first()
if not question:
raise HTTPNotFound()
if "choice" in request.POST:
# Extracts the form choice and turn it to UUID object
chosen_uuid = slug_to_uuid(request.POST["choice"])
selected_choice = question.choices.filter_by(uuid=chosen_uuid).first()
selected_choice.votes += 1
messages.add(request, msg="Thank you for your vote", kind="success")
return HTTPFound(request.route_url("results", question_uuid=uuid_to_slug(question.uuid)))
else:
error_message = "You did not select any choice."
return locals()
示例5: test_remove_user_from_group
def test_remove_user_from_group(web_server, init, browser, dbsession):
"""Remove users from assigned groups in admin."""
b = browser
from websauna.system.user.models import Group
create_logged_in_user(dbsession, init.config.registry, web_server, browser, admin=True)
# Create a group where we
with transaction.manager:
g = Group(name=GROUP_NAME)
dbsession.add(g)
u = get_user(dbsession)
u.groups.append(g)
dbsession.flush()
group_uuid = uuid_to_slug(g.uuid)
b.find_by_css("#nav-admin").click()
b.find_by_css("#btn-panel-list-user").click()
b.find_by_css(".crud-row-1 .btn-crud-listing-edit").click()
# Check the group checkbox. We could put some more specific classes for controls here.
b.find_by_css("input[type='checkbox'][value='{}']".format(group_uuid)).click()
b.find_by_name("save").click()
assert b.is_text_present("Changes saved")
# After removing we should no longer see the removed group name on user show page
assert not b.is_text_present(GROUP_NAME)
示例6: test_put_user_to_group
def test_put_user_to_group(web_server, browser, dbsession, init):
"""Check that we can assign users to groups in admin interface."""
b = browser
from websauna.system.user.models import Group
create_logged_in_user(dbsession, init.config.registry, web_server, browser, admin=True)
# Create a group where we
with transaction.manager:
g = Group(name=GROUP_NAME)
dbsession.add(g)
dbsession.flush()
group_uuid = uuid_to_slug(g.uuid)
b.find_by_css("#nav-admin").click()
b.find_by_css("#btn-panel-list-user").click()
b.find_by_css(".crud-row-1 .btn-crud-listing-edit").click()
# Check the group checkbox. We could put some more specific classes for controls here.
b.find_by_css("input[type='checkbox'][value='{}']".format(group_uuid)).click()
b.find_by_name("save").click()
assert b.is_text_present("Changes saved")
# Now we are on Show page of the user, having the new group name visible
assert b.is_text_present(GROUP_NAME)
示例7: test_edit_choice_remove_question
def test_edit_choice_remove_question(browser: DriverAPI, tutorial_req, web_server, dbsession):
"""Editing choice allows us to reset question value back to null."""
from .tutorial import Question
from .tutorial import Choice
with transaction.manager:
q = Question(question_text="What is love")
dbsession.add(q)
dbsession.flush()
c = Choice(choice_text="Foobar", question=q)
dbsession.add(c)
dbsession.flush()
c_slug = uuid_to_slug(c.uuid)
b = browser
create_logged_in_user(dbsession, tutorial_req.registry, web_server, browser, admin=True)
b.visit("{}/admin/models/choice/{}/edit".format(web_server, c_slug))
b.select("question", "")
b.find_by_name("save").click()
assert b.is_element_present_by_css("#msg-changes-saved")
with transaction.manager:
c = dbsession.query(Choice).get(1)
assert c.question == None
示例8: test_question_delete
def test_question_delete(browser: DriverAPI, tutorial_req, web_server, dbsession):
"""Delete question and make sure it deletes related choices.."""
from .tutorial import Question
from .tutorial import Choice
with transaction.manager:
q = Question(question_text="What is love")
dbsession.add(q)
dbsession.flush()
c = Choice(choice_text="Baby don't hurt me", question=q)
dbsession.add(c)
dbsession.flush()
q_slug = uuid_to_slug(q.uuid)
b = browser
create_logged_in_user(dbsession, tutorial_req.registry, web_server, browser, admin=True)
b.visit("{}/admin/models/question/{}".format(web_server, q_slug))
b.find_by_css("#btn-crud-delete").click()
b.find_by_css("#btn-delete-yes").click()
with transaction.manager:
assert dbsession.query(Question).count() == 0
assert dbsession.query(Choice).count() == 0
示例9: test_add_choice_question
def test_add_choice_question(browser: DriverAPI, tutorial_req, web_server, dbsession):
from .tutorial import Question
from .tutorial import Choice
with transaction.manager:
q = Question(question_text="What is love")
dbsession.add(q)
dbsession.flush()
question_uuid = uuid_to_slug(q.uuid)
b = browser
create_logged_in_user(dbsession, tutorial_req.registry, web_server, browser, admin=True)
b.visit(web_server)
b.find_by_css("#nav-admin").click()
b.find_by_css("#btn-panel-add-choice").click()
b.fill("choice_text", "Baby don't hurt me")
b.select("question", question_uuid)
b.find_by_name("add").click()
assert b.is_element_present_by_css("#msg-item-added")
with transaction.manager:
assert dbsession.query(Choice).first().question is not None
示例10: network_choice_widget
def network_choice_widget(node: colander.SchemaNode, kw: dict):
request = kw["request"]
dbsession = request.dbsession
query = dbsession.query(AssetNetwork)
vocab = convert_query_to_tuples(
query,
first_column=lambda o: uuid_to_slug(o.id),
second_column=lambda o: o.human_friendly_name)
return deform.widget.SelectWidget(values=vocab)
示例11: get_operations
def get_operations(self, state: Iterable):
ops = (
self.wallet.user.owned_crypto_operations.join(CryptoOperation)
.filter(CryptoOperation.state.in_(state))
.order_by(CryptoOperation.created_at.desc())
)
for op in ops:
uo = UserOperation(self.request, op)
yield Resource.make_lineage(self, uo, uuid_to_slug(op.id))
示例12: __getitem__
def __getitem__(self, item):
uuid = slug_to_uuid(item)
uop = self.request.dbsession.query(UserCryptoOperation).get(uuid)
if not uop:
raise KeyError()
if uop.user != self.wallet.user:
raise httpexceptions.HTTPForbidden()
return Resource.make_lineage(self, UserOperation(self.request, uop), uuid_to_slug(uop.id))
示例13: uuid_to_slug
def uuid_to_slug(jinja_ctx, context, **kw):
"""Convert UUID object to a base64 encoded slug.
Example::
{% for question in latest_question_list %}
<li>
<a href="{{ route_url('details', question.uuid|uuid_to_slug) }}">
{{ question.question_text }}
</a>
</li>
{% endfor %}
"""
return slug.uuid_to_slug(context)
示例14: test_view_user_details
def test_view_user_details(browser, web_server, init, dbsession):
"""See that we can view the details of the user in a browser."""
b = browser
create_logged_in_user(dbsession, init.config.registry, web_server, browser, admin=True)
b.find_by_css("#nav-admin").click()
b.find_by_css("#latest-user-shortcut").click()
# TODO: Use CSS selector
assert b.is_text_present("[email protected]")
with transaction.manager:
# Check that we show the user uuid slug on the page correctly
u = dbsession.query(User).first()
assert b.is_text_present(uuid_to_slug(u.uuid))
示例15: test_question_shows_choices
def test_question_shows_choices(browser: DriverAPI, tutorial_req, web_server, dbsession):
"""If question has active choices they are shown on Show screen, albeit not editable."""
from .tutorial import Question
from .tutorial import Choice
with transaction.manager:
q = Question(question_text="What is love")
dbsession.add(q)
dbsession.flush()
q_slug = uuid_to_slug(q.uuid)
c = Choice(choice_text="Baby don't hurt me", question=q)
dbsession.add(c)
dbsession.flush()
b = browser
create_logged_in_user(dbsession, tutorial_req.registry, web_server, browser, admin=True)
b.visit("{}/admin/models/question/{}/show".format(web_server, q_slug))
assert b.is_text_present("Baby don't hurt me")