Example #1
0
def test_edit_choice_question(browser: DriverAPI, registry, 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, 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)
Example #2
0
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)
Example #3
0
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()
Example #4
0
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":

        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()
Example #5
0
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)
Example #6
0
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
Example #7
0
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")
Example #8
0
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)
Example #9
0
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)
Example #10
0
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)
Example #11
0
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)
Example #12
0
def test_add_choice_question(browser: DriverAPI, registry, 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, 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
Example #13
0
def test_edit_choice_remove_question(browser: DriverAPI, registry, 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, 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 is None
Example #14
0
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)
Example #15
0
def test_question_delete(browser: DriverAPI, registry, 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, 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
Example #16
0
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
Example #17
0
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)
Example #18
0
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
Example #19
0
def test_user_group_choices_preserved_on_validation_error(
        web_server, init, browser, dbsession):
    """When user edit form validation fails, we should preserve the existing group choices.

    This stresses out hacky implementation of websauna.system.form.colander and deserialization.
    """

    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()

    # We are in group 2 initially, assert checkbox is checked
    assert b.find_by_css(
        "input[type='checkbox'][value='{}'][checked='True']".format(
            group_uuid))

    # Do validation error by leaving username empty
    b.fill("username", "")
    b.find_by_name("save").click()
    assert b.is_text_present("There was a problem")

    # Both group checkboxes should be still selected
    with transaction.manager:
        for g in dbsession.query(Group).all():
            assert b.find_by_css(
                "input[type='checkbox'][value='{}'][checked='True']".format(
                    uuid_to_slug(g.uuid)))
Example #20
0
    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))
Example #21
0
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)
Example #22
0
 def get_template_values(self, field, cstruct, kw):
     values = {
         'cstruct': str(cstruct),
         'field': field,
         'slug': uuid_to_slug(cstruct) if cstruct else ''
     }
     values.update(kw)
     values.pop('template', None)
     return values
Example #23
0
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)
Example #24
0
    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))
Example #25
0
    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))
Example #26
0
    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))
Example #27
0
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)
Example #28
0
def uuid_to_slug(jinja_ctx, context, **kw):
    """Convert UUID object to a base64 encoded slug.

    Example:

    .. code-block:: html+jinja

        {% 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)
Example #29
0
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("*****@*****.**")

    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))
Example #30
0
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("*****@*****.**")

    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))
Example #31
0
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")
Example #32
0
def test_register_email(web_server, browser, dbsession):
    """Register on the site and login after activation."""

    # Load user model
    # registry = get_current_registry()
    # User = registry.queryUtility(IUserClass)
    # assert User

    b = browser
    b.visit(web_server)

    b.click_link_by_text("Sign up")

    assert b.is_element_visible_by_css("#sign-up-form")

    b.fill("email", EMAIL)
    b.fill("password", PASSWORD)
    b.fill("password-confirm", PASSWORD)

    b.find_by_name("sign_up").click()

    assert b.is_element_visible_by_css("#waiting-for-activation")

    # Now peek the Activation link from the database
    user = get_user(dbsession)
    assert user.activation.code

    activation_link = "{}/activate/{}/{}".format(web_server, uuid_to_slug(user.uuid), user.activation.code)

    b.visit(activation_link)

    assert b.is_element_visible_by_css("#sign-up-complete")

    b.fill("username", EMAIL)
    b.fill("password", PASSWORD)
    b.find_by_name("login_email").click()

    # After login we see a profile link to our profile
    assert b.is_element_visible_by_css("#nav-logout")
Example #33
0
def test_user_group_choices_preserved_on_validation_error(web_server, init, browser, dbsession):
    """When user edit form validation fails, we should preserve the existing group choices.

    This stresses out hacky implementation of websauna.system.form.colander and deserialization.
    """

    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()

    # We are in group 2 initially, assert checkbox is checked
    assert b.find_by_css("input[type='checkbox'][value='{}'][checked='True']".format(group_uuid))

    # Do validation error by leaving username empty
    b.fill("username", "")
    b.find_by_name("save").click()
    assert b.is_text_present("There was a problem")

    # Both group checkboxes should be still selected
    with transaction.manager:
        for g in dbsession.query(Group).all():
            assert b.find_by_css("input[type='checkbox'][value='{}'][checked='True']".format(uuid_to_slug(g.uuid)))
Example #34
0
 def first_column_getter(group: Group):
     return uuid_to_slug(group.uuid)
Example #35
0
 def get_user_wallet(self, user):
     wallet = UserWallet(self.request, user)
     return Resource.make_lineage(self, wallet, uuid_to_slug(user.uuid))
Example #36
0
 def first_column_getter(group: Group):
     return uuid_to_slug(group.uuid)
Example #37
0
def get_user_crypto_operation_resource(
        request, uop: UserCryptoOperation) -> UserOperation:
    assert isinstance(uop, UserCryptoOperation)
    wallet_root = route_factory(request)
    wallet = wallet_root[uuid_to_slug(uop.user.uuid)]
    return wallet.get_uop_resource(uop)
Example #38
0
 def get_user_wallet(self, user):
     wallet = UserWallet(self.request, user)
     return Resource.make_lineage(self, wallet, uuid_to_slug(user.uuid))
Example #39
0
 def get_address_resource(self, address: UserCryptoAddress) -> UserAddress:
     assert address.user == self.user
     return self["accounts"][uuid_to_slug(address.id)]
Example #40
0
 def get_uop_resource(self, uop: UserCryptoOperation) -> UserOperation:
     assert uop.user == self.user
     return self["transactions"][uuid_to_slug(uop.id)]
Example #41
0
def get_user_wallet(request) -> UserWallet:
    wallet_root = route_factory(request)
    return wallet_root[uuid_to_slug(request.user.uuid)]
Example #42
0
 def get_addresses(self):
     addresses = self.user.owned_crypto_addresses
     for addr in addresses:
         ua = UserAddress(self.request, addr)
         yield Resource.make_lineage(self, ua, uuid_to_slug(addr.id))
Example #43
0
def available_networks(node, kw):
    request = kw["request"]
    query = request.dbsession.query(AssetNetwork).all()
    return [(uuid_to_slug(network.id), network.name) for network in query]
Example #44
0
 def preprocess_appstruct_values(self, node: colander.SchemaNode, appstruct: set) -> List[str]:
     """Convert items to appstruct ids.
     """
     return [uuid_to_slug(getattr(i, self.match_column)) for i in appstruct]
Example #45
0
def extract_uuid_to_slug(item):
    """Reads uuid attribute on the model name returns it as B64 encoded slug."""
    return uuid_to_slug(item.uuid)
Example #46
0
 def get_user_address_asset(self, crypto_account: CryptoAddressAccount):
     uaa = UserAddressAsset(self.request, crypto_account)
     return Resource.make_lineage(self, uaa,
                                  uuid_to_slug(crypto_account.id))
Example #47
0
 def get_addresses(self):
     addresses = self.user.owned_crypto_addresses
     for addr in addresses:
         ua = UserAddress(self.request, addr)
         yield Resource.make_lineage(self, ua, uuid_to_slug(addr.id))
Example #48
0
 def get_template_values(self, field, cstruct, kw):
     values = {'cstruct':str(cstruct), 'field':field, 'slug':uuid_to_slug(cstruct) if cstruct else ''}
     values.update(kw)
     values.pop('template', None)
     return values
Example #49
0
def deferred_tags_widget(_, kw):
    """Select tags widget."""
    dbsession = kw["request"].dbsession
    vocab = [(uuid_to_slug(tag_id), title) for tag_id, title in dbsession.query(Tag.id, Tag.title).all()]
    return deform.widget.Select2Widget(values=vocab, multiple=True, tags=True, css_class="tags-select2w")
Example #50
0
def test_uuid_slug():
    """Make short slugs for 64-bit UUID ids."""
    _uuid = uuid.uuid4()

    _uuid2 = slug_to_uuid(uuid_to_slug(_uuid))
    assert _uuid == _uuid2
Example #51
0
 def get_uop_resource(self, uop: UserCryptoOperation) -> UserOperation:
     assert uop.user == self.user
     return self["transactions"][uuid_to_slug(uop.id)]
Example #52
0
 def get_user_address_asset(self, crypto_account: CryptoAddressAccount):
     uaa = UserAddressAsset(self.request, crypto_account)
     return Resource.make_lineage(self, uaa, uuid_to_slug(crypto_account.id))
Example #53
0
 def get_address_resource(self, address: UserCryptoAddress) -> UserAddress:
     assert address.user == self.user
     return self["accounts"][uuid_to_slug(address.id)]
Example #54
0
def get_user_crypto_operation_resource(request, uop: UserCryptoOperation) -> UserOperation:
    assert isinstance(uop, UserCryptoOperation)
    wallet_root = route_factory(request)
    wallet = wallet_root[uuid_to_slug(uop.user.uuid)]
    return wallet.get_uop_resource(uop)
Example #55
0
def get_user_wallet(request) -> UserWallet:
    wallet_root = route_factory(request)
    return wallet_root[uuid_to_slug(request.user.uuid)]
Example #56
0
def available_networks(node, kw):
    request = kw["request"]
    query = request.dbsession.query(AssetNetwork).all()
    return [(uuid_to_slug(network.id), network.name) for network in query]