Exemplo n.º 1
0
def test_formdata():
    stream = io.BytesIO(b"data")
    upload = UploadFile(filename="file", file=stream)
    form = FormData([("a", "123"), ("a", "456"), ("b", upload)])
    assert "a" in form
    assert "A" not in form
    assert "c" not in form
    assert form["a"] == "456"
    assert form.get("a") == "456"
    assert form.get("nope", default=None) is None
    assert form.getlist("a") == ["123", "456"]
    assert list(form.keys()) == ["a", "b"]
    assert list(form.values()) == ["456", upload]
    assert list(form.items()) == [("a", "456"), ("b", upload)]
    assert len(form) == 2
    assert list(form) == ["a", "b"]
    assert dict(form) == {"a": "456", "b": upload}
    assert (repr(form) == "FormData([('a', '123'), ('a', '456'), ('b', " +
            repr(upload) + ")])")
    assert FormData(form) == form
    assert FormData({
        "a": "123",
        "b": "789"
    }) == FormData([("a", "123"), ("b", "789")])
    assert FormData({"a": "123", "b": "789"}) != {"a": "123", "b": "789"}
Exemplo n.º 2
0
def save_samples(samples: Iterable[str], form: FormData, adapter: StatinaAdapter, user: User):
    """Function to update sample.comment and sample.include."""

    time_stamp: str = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
    for sample_id in samples:
        sample: DataBaseSample = find.sample(sample_id=sample_id, adapter=adapter)
        comment: str = form.get(f"comment_{sample_id}")
        include: bool = form.get(f"include_{sample_id}")
        if comment != sample.comment:
            sample.comment = comment
        if include and not sample.include:
            sample.include = True
            sample.change_include_date = f"{user.username} {time_stamp}"
        elif not include and sample.include:
            sample.include = False
        update.sample(adapter=adapter, sample=sample)
Exemplo n.º 3
0
 async def resolve_data(cls, request: Request, data: FormData):
     ret = {}
     m2m_ret = {}
     for field in cls.get_fields(is_display=False):
         input_ = field.input
         if input_.context.get("disabled") or isinstance(
                 input_, inputs.DisplayOnly):
             continue
         name = input_.context.get("name")
         if isinstance(input_, inputs.ManyToMany):
             v = data.getlist(name)
             value = await input_.parse_value(request, v)
             m2m_ret[name] = await input_.model.filter(pk__in=value)
         else:
             v = data.get(name)
             value = await input_.parse_value(request, v)
             ret[name] = value
     return ret, m2m_ret