File size: 666 Bytes
79a50aa
 
 
 
 
6a403bf
 
 
 
 
 
 
 
 
79a50aa
 
 
 
 
a597d50
79a50aa
a597d50
79a50aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from django.shortcuts import redirect
from django.urls import reverse
from urllib.parse import urlencode


def getId(value: object | int) -> int | None:
    if isinstance(value, int):
        return value
    elif hasattr(value, "id"):
        return value.id
    elif hasattr(value, "pk"):
        return value.pk

    return None


def noValidTechnique(params: dict, query_params: dict, name_view: str):
    if query_params:
        query_string = urlencode(query_params)
        url_redireccion = f"{reverse(name_view, kwargs=params)}?{query_string}"
    else:
        url_redireccion = f"{reverse(name_view, kwargs=params)}"
    return redirect(url_redireccion)