Renamed the add_param() method to add(), the del_param() method to remove(), and the set_param() method to set() in UrlBuilder in the Mia core application.
This commit is contained in:
parent
1a27d87400
commit
aec234fc01
@ -898,12 +898,12 @@ def transaction_store(request, txn_type, transaction=None):
|
|||||||
"accounting:transactions.edit", args=(txn_type, transaction))
|
"accounting:transactions.edit", args=(txn_type, transaction))
|
||||||
return error_redirect(
|
return error_redirect(
|
||||||
request,
|
request,
|
||||||
str(UrlBuilder(url).add_param("r", request.GET.get("r"))),
|
str(UrlBuilder(url).add("r", request.GET.get("r"))),
|
||||||
form,
|
form,
|
||||||
errors)
|
errors)
|
||||||
return success_redirect(
|
return success_redirect(
|
||||||
request,
|
request,
|
||||||
str(UrlBuilder(reverse("accounting:transactions.show",
|
str(UrlBuilder(reverse("accounting:transactions.show",
|
||||||
args=(txn_type, transaction)))
|
args=(txn_type, transaction)))
|
||||||
.add_param("r", request.GET.get("r"))),
|
.add("r", request.GET.get("r"))),
|
||||||
gettext_noop("This transaction was saved successfully."))
|
gettext_noop("This transaction was saved successfully."))
|
||||||
|
@ -39,7 +39,7 @@ def success_redirect(request, url, success):
|
|||||||
HttpResponseRedirect: The redirect response.
|
HttpResponseRedirect: The redirect response.
|
||||||
"""
|
"""
|
||||||
id = _store(request, {"success": success})
|
id = _store(request, {"success": success})
|
||||||
return HttpResponseRedirect(str(UrlBuilder(url).add_param("s", id)))
|
return HttpResponseRedirect(str(UrlBuilder(url).add("s", id)))
|
||||||
|
|
||||||
|
|
||||||
def error_redirect(request, url, form, errors_by_field):
|
def error_redirect(request, url, form, errors_by_field):
|
||||||
@ -58,7 +58,7 @@ def error_redirect(request, url, form, errors_by_field):
|
|||||||
HttpResponseRedirect: The redirect response.
|
HttpResponseRedirect: The redirect response.
|
||||||
"""
|
"""
|
||||||
id = _store(request, {"form": form, "errors_by_field": errors_by_field})
|
id = _store(request, {"form": form, "errors_by_field": errors_by_field})
|
||||||
return HttpResponseRedirect(str(UrlBuilder(url).add_param("s", id)))
|
return HttpResponseRedirect(str(UrlBuilder(url).add("s", id)))
|
||||||
|
|
||||||
|
|
||||||
def retrieve_status(request):
|
def retrieve_status(request):
|
||||||
|
@ -95,7 +95,7 @@ def url_with_return(context, view_name, *args):
|
|||||||
"""
|
"""
|
||||||
url = reverse(view_name, args=args)
|
url = reverse(view_name, args=args)
|
||||||
return_to = context.request.get_full_path()
|
return_to = context.request.get_full_path()
|
||||||
return str(UrlBuilder(url).set_param("r", return_to))
|
return str(UrlBuilder(url).set("r", return_to))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
@ -111,7 +111,7 @@ def url_keep_return(context, view_name, *args):
|
|||||||
str: The URL.
|
str: The URL.
|
||||||
"""
|
"""
|
||||||
url = reverse(view_name, args=args)
|
url = reverse(view_name, args=args)
|
||||||
return str(UrlBuilder(url).set_param("r", context.request.GET.get("r")))
|
return str(UrlBuilder(url).set("r", context.request.GET.get("r")))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True, name="retrieve_status")
|
@register.simple_tag(takes_context=True, name="retrieve_status")
|
||||||
|
@ -174,7 +174,7 @@ class UrlBuilder:
|
|||||||
value = urllib.parse.unquote(piece[pos + 1:])
|
value = urllib.parse.unquote(piece[pos + 1:])
|
||||||
self.params.append(self.Param(name, value))
|
self.params.append(self.Param(name, value))
|
||||||
|
|
||||||
def add_param(self, name, value):
|
def add(self, name, value):
|
||||||
"""Adds a query parameter.
|
"""Adds a query parameter.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -189,7 +189,7 @@ class UrlBuilder:
|
|||||||
self.params.append(self.Param(name, value))
|
self.params.append(self.Param(name, value))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def del_param(self, name):
|
def remove(self, name):
|
||||||
"""Removes a query parameter.
|
"""Removes a query parameter.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -202,7 +202,7 @@ class UrlBuilder:
|
|||||||
self.params = [x for x in self.params if x.name != name]
|
self.params = [x for x in self.params if x.name != name]
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def set_param(self, name, value):
|
def set(self, name, value):
|
||||||
"""Sets a query parameter. The current parameters with the
|
"""Sets a query parameter. The current parameters with the
|
||||||
same name will be replaced.
|
same name will be replaced.
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ class UrlBuilder:
|
|||||||
UrlBuilder: The URL builder itself, with the parameter
|
UrlBuilder: The URL builder itself, with the parameter
|
||||||
modified.
|
modified.
|
||||||
"""
|
"""
|
||||||
return self.del_param(name).add_param(name, value)
|
return self.remove(name).add(name, value)
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
"""Returns a copy of this URL builder.
|
"""Returns a copy of this URL builder.
|
||||||
@ -313,15 +313,15 @@ class Pagination:
|
|||||||
self.page_size = int(request.GET["page-size"])
|
self.page_size = int(request.GET["page-size"])
|
||||||
if self.page_size == self.DEFAULT_PAGE_SIZE:
|
if self.page_size == self.DEFAULT_PAGE_SIZE:
|
||||||
raise PaginationException(str(
|
raise PaginationException(str(
|
||||||
UrlBuilder(current_url).del_param("page-size")))
|
UrlBuilder(current_url).remove("page-size")))
|
||||||
if self.page_size < 1:
|
if self.page_size < 1:
|
||||||
raise PaginationException(str(
|
raise PaginationException(str(
|
||||||
UrlBuilder(current_url).del_param("page-size")))
|
UrlBuilder(current_url).remove("page-size")))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.page_size = self.DEFAULT_PAGE_SIZE
|
self.page_size = self.DEFAULT_PAGE_SIZE
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise PaginationException(str(
|
raise PaginationException(str(
|
||||||
UrlBuilder(current_url).del_param("page-size")))
|
UrlBuilder(current_url).remove("page-size")))
|
||||||
self.total_pages = int(
|
self.total_pages = int(
|
||||||
(len(items) - 1) / self.page_size) + 1
|
(len(items) - 1) / self.page_size) + 1
|
||||||
default_page_no = 1 if not is_reversed else self.total_pages
|
default_page_no = 1 if not is_reversed else self.total_pages
|
||||||
@ -332,21 +332,21 @@ class Pagination:
|
|||||||
self.page_no = int(request.GET["page"])
|
self.page_no = int(request.GET["page"])
|
||||||
if not self.is_paged:
|
if not self.is_paged:
|
||||||
raise PaginationException(str(
|
raise PaginationException(str(
|
||||||
UrlBuilder(current_url).del_param("page")))
|
UrlBuilder(current_url).remove("page")))
|
||||||
if self.page_no == default_page_no:
|
if self.page_no == default_page_no:
|
||||||
raise PaginationException(str(
|
raise PaginationException(str(
|
||||||
UrlBuilder(current_url).del_param("page")))
|
UrlBuilder(current_url).remove("page")))
|
||||||
if self.page_no < 1:
|
if self.page_no < 1:
|
||||||
raise PaginationException(str(
|
raise PaginationException(str(
|
||||||
UrlBuilder(current_url).del_param("page")))
|
UrlBuilder(current_url).remove("page")))
|
||||||
if self.page_no > self.total_pages:
|
if self.page_no > self.total_pages:
|
||||||
raise PaginationException(str(
|
raise PaginationException(str(
|
||||||
UrlBuilder(current_url).del_param("page")))
|
UrlBuilder(current_url).remove("page")))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.page_no = default_page_no
|
self.page_no = default_page_no
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise PaginationException(str(
|
raise PaginationException(str(
|
||||||
UrlBuilder(current_url).del_param("page")))
|
UrlBuilder(current_url).remove("page")))
|
||||||
|
|
||||||
if not self.is_paged:
|
if not self.is_paged:
|
||||||
self.page_no = 1
|
self.page_no = 1
|
||||||
@ -361,7 +361,7 @@ class Pagination:
|
|||||||
def links(self):
|
def links(self):
|
||||||
"""Returns the navigation links of the pagination bar."""
|
"""Returns the navigation links of the pagination bar."""
|
||||||
if self._links is None:
|
if self._links is None:
|
||||||
base_url = UrlBuilder(self._current_url).del_param("page")
|
base_url = UrlBuilder(self._current_url).remove("page")
|
||||||
self._links = []
|
self._links = []
|
||||||
# The previous page
|
# The previous page
|
||||||
link = self.Link()
|
link = self.Link()
|
||||||
@ -371,10 +371,10 @@ class Pagination:
|
|||||||
if not self.is_reversed:
|
if not self.is_reversed:
|
||||||
link.url = str(base_url)
|
link.url = str(base_url)
|
||||||
else:
|
else:
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", "1"))
|
"page", "1"))
|
||||||
else:
|
else:
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", str(self.page_no - 1)))
|
"page", str(self.page_no - 1)))
|
||||||
link.is_small_screen = True
|
link.is_small_screen = True
|
||||||
self._links.append(link)
|
self._links.append(link)
|
||||||
@ -384,7 +384,7 @@ class Pagination:
|
|||||||
if not self.is_reversed:
|
if not self.is_reversed:
|
||||||
link.url = str(base_url)
|
link.url = str(base_url)
|
||||||
else:
|
else:
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", "1"))
|
"page", "1"))
|
||||||
if self.page_no == 1:
|
if self.page_no == 1:
|
||||||
link.is_active = True
|
link.is_active = True
|
||||||
@ -396,7 +396,7 @@ class Pagination:
|
|||||||
link.title = pgettext("Pagination|", "...")
|
link.title = pgettext("Pagination|", "...")
|
||||||
else:
|
else:
|
||||||
link.title = "2"
|
link.title = "2"
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", "2"))
|
"page", "2"))
|
||||||
self._links.append(link)
|
self._links.append(link)
|
||||||
# The nearby pages
|
# The nearby pages
|
||||||
@ -405,7 +405,7 @@ class Pagination:
|
|||||||
continue
|
continue
|
||||||
link = self.Link()
|
link = self.Link()
|
||||||
link.title = str(no)
|
link.title = str(no)
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", str(no)))
|
"page", str(no)))
|
||||||
if no == self.page_no:
|
if no == self.page_no:
|
||||||
link.is_active = True
|
link.is_active = True
|
||||||
@ -417,7 +417,7 @@ class Pagination:
|
|||||||
link.title = pgettext("Pagination|", "...")
|
link.title = pgettext("Pagination|", "...")
|
||||||
else:
|
else:
|
||||||
link.title = str(self.total_pages - 1)
|
link.title = str(self.total_pages - 1)
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", str(self.total_pages - 1)))
|
"page", str(self.total_pages - 1)))
|
||||||
self._links.append(link)
|
self._links.append(link)
|
||||||
# The last page
|
# The last page
|
||||||
@ -426,7 +426,7 @@ class Pagination:
|
|||||||
if self.is_reversed:
|
if self.is_reversed:
|
||||||
link.url = str(base_url)
|
link.url = str(base_url)
|
||||||
else:
|
else:
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", str(self.total_pages)))
|
"page", str(self.total_pages)))
|
||||||
if self.page_no == self.total_pages:
|
if self.page_no == self.total_pages:
|
||||||
link.is_active = True
|
link.is_active = True
|
||||||
@ -439,10 +439,10 @@ class Pagination:
|
|||||||
if self.is_reversed:
|
if self.is_reversed:
|
||||||
link.url = str(base_url)
|
link.url = str(base_url)
|
||||||
else:
|
else:
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", str(self.total_pages)))
|
"page", str(self.total_pages)))
|
||||||
else:
|
else:
|
||||||
link.url = str(base_url.clone().add_param(
|
link.url = str(base_url.clone().add(
|
||||||
"page", str(self.page_no + 1)))
|
"page", str(self.page_no + 1)))
|
||||||
link.is_small_screen = True
|
link.is_small_screen = True
|
||||||
self._links.append(link)
|
self._links.append(link)
|
||||||
@ -465,8 +465,8 @@ class Pagination:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def page_size_options(self):
|
def page_size_options(self):
|
||||||
base_url = UrlBuilder(self._current_url).del_param(
|
base_url = UrlBuilder(self._current_url).remove(
|
||||||
"page").del_param("page-size")
|
"page").remove("page-size")
|
||||||
return [self.PageSizeOption(x, self._page_size_url(base_url, x))
|
return [self.PageSizeOption(x, self._page_size_url(base_url, x))
|
||||||
for x in [10, 100, 200]]
|
for x in [10, 100, 200]]
|
||||||
|
|
||||||
@ -483,7 +483,7 @@ class Pagination:
|
|||||||
"""
|
"""
|
||||||
if size == Pagination.DEFAULT_PAGE_SIZE:
|
if size == Pagination.DEFAULT_PAGE_SIZE:
|
||||||
return str(base_url)
|
return str(base_url)
|
||||||
return str(base_url.clone().add_param("page-size", str(size)))
|
return str(base_url.clone().add("page-size", str(size)))
|
||||||
|
|
||||||
class PageSizeOption:
|
class PageSizeOption:
|
||||||
"""A page size option.
|
"""A page size option.
|
||||||
|
Loading…
Reference in New Issue
Block a user