Depreciated templatetags and Updated docs to django-nepali package
This commit is contained in:
4 files changed
+71
-80
No files matched your search
+6
-1
@@ -1,6 +1,11 @@
|
||||
# CHANGELOG
|
||||
|
||||
## v1.0.1
|
||||
## main
|
||||
|
||||
- Depreciated templatetags.
|
||||
- Updated README.md for `django-nepali` package.
|
||||
|
||||
## v1.0.1 (May 16, 2023)
|
||||
- Fixes on `nepalinumber` templatetags
|
||||
- Bug fix on Django templatetags 'nepalinumber' (was returning in en-US locale)
|
||||
- Added templatetag `nepali_comma`
|
||||
|
||||
@@ -433,86 +433,9 @@ get_municipality(name_nepali="विराटनगर")
|
||||
|
||||
---
|
||||
|
||||
## For Django Template
|
||||
|
||||
Add `'nepali'` to your `INSTALLED_APPS` setting.
|
||||
|
||||
```python
|
||||
INSTALLED_APPS = [
|
||||
...
|
||||
'nepali',
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
### nepalidatetime
|
||||
|
||||
In your Template
|
||||
|
||||
```python
|
||||
{% load nepalidatetime %}
|
||||
```
|
||||
|
||||
#### nepalinow
|
||||
|
||||
`nepalinow` renders the current Nepali date and time in 'en-US' locale (English).
|
||||
|
||||
```python
|
||||
{% nepalinow %}
|
||||
```
|
||||
|
||||
```python
|
||||
{% nepalinow '%Y-%m-%d' %}
|
||||
```
|
||||
|
||||
#### nepalinow_ne
|
||||
|
||||
`nepalinow_ne` renders the current Nepali date and time in 'ne' locale (Nepali).
|
||||
|
||||
```python
|
||||
{% nepalinow_ne %}
|
||||
```
|
||||
|
||||
#### nepalidate
|
||||
|
||||
`nepalidate` renders the datetime object into nepali datetime format in 'en-US' locale (English).
|
||||
|
||||
```python
|
||||
{{ datetime_obj|nepalidate:"%Y-%m-%d" }}
|
||||
```
|
||||
|
||||
#### nepalidate_ne
|
||||
|
||||
`nepalidate_ne` renders the datetime object into nepali datetime format in 'ne' locale (Nepali).
|
||||
|
||||
```python
|
||||
{{ datetime_obj|nepalidate_ne:"%Y-%m-%d" }}
|
||||
```
|
||||
|
||||
#### nepalihumanize
|
||||
|
||||
`nepalihumanize` renders the datetime object to a human readable form for 'ne' locale (Nepali)
|
||||
|
||||
```python
|
||||
{{ datetime_obj|nepalihumanize }}
|
||||
```
|
||||
|
||||
### nepalinumber
|
||||
|
||||
In your Template
|
||||
|
||||
```python
|
||||
{% load nepalinumber %}
|
||||
```
|
||||
|
||||
`nepalinumber` renders the english number into nepali format (devanagari)
|
||||
|
||||
```python
|
||||
{{ forloop.counter|nepalinumber }}
|
||||
|
||||
{{ 150|nepalinumber }}
|
||||
```
|
||||
## For Django
|
||||
|
||||
We have created a new Django package called [django-nepali](https://github.com/opensource-nepal/django-nepali) to support `nepali` package. For more information, please visit [django-nepali](https://github.com/opensource-nepal/django-nepali).
|
||||
|
||||
## Contribution
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
"""
|
||||
This module contains django templatetags for nepali date and time.
|
||||
"""
|
||||
import datetime
|
||||
import warnings
|
||||
from typing import Optional, Union
|
||||
|
||||
from django import template
|
||||
@@ -11,6 +15,11 @@ from nepali.exceptions import InvalidNepaliDateTimeObjectException
|
||||
from nepali.utils import to_nepalidatetime
|
||||
|
||||
_DEFAULT_DATE_FORMAT = "%B %d, %Y, %A"
|
||||
DEPRECIATION_WARNING_MESSAGE = (
|
||||
"The templatetag 'nepalidatetime' has been depreciated "
|
||||
"and will be removed in the future release. "
|
||||
"Please use `django-nepali` package."
|
||||
)
|
||||
_datetime = Union[datetime.date, datetime.datetime, _nepalidate, _nepalidatetime]
|
||||
register = template.Library()
|
||||
|
||||
@@ -32,6 +41,10 @@ def nepalidate(
|
||||
:param format: Output format, defaults to "%B %d, %Y, %A"
|
||||
:returns: Nepali datetime format in 'en-US' locale
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return nepalidate_en(datetime_obj, format=format)
|
||||
|
||||
|
||||
@@ -52,6 +65,10 @@ def nepalidate_en(
|
||||
:param format: Output format, defaults to "%B %d, %Y, %A"
|
||||
:returns: Nepali datetime format in 'en-US' locale
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
try:
|
||||
nepali_datetime_obj = to_nepalidatetime(datetime_obj)
|
||||
return nepali_datetime_obj.strftime_en(format)
|
||||
@@ -76,6 +93,10 @@ def nepalidate_ne(
|
||||
:param format: Output format, defaults to "%B %d, %Y, %A"
|
||||
:returns: Nepali datetime format in 'ne' locale
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
try:
|
||||
nepali_datetime_obj = to_nepalidatetime(datetime_obj)
|
||||
return nepali_datetime_obj.strftime_ne(format)
|
||||
@@ -103,6 +124,10 @@ def nepalihumanize(
|
||||
:param format: Output format if threshold exceeded, optional
|
||||
:returns: Datetime object in human readable form
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
try:
|
||||
nepali_datetime_obj = to_nepalidatetime(datetime_obj)
|
||||
return humanize(nepali_datetime_obj, threshold=threshold, format=format)
|
||||
@@ -125,6 +150,10 @@ def nepalinow(format: str = _DEFAULT_DATE_FORMAT) -> str:
|
||||
:param format: Output format, defaults to "%B %d, %Y, %A"
|
||||
:returns: Current nepali datetime
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return nepalinow_en(format)
|
||||
|
||||
|
||||
@@ -143,6 +172,10 @@ def nepalinow_en(format: str = _DEFAULT_DATE_FORMAT) -> str:
|
||||
:param format: Output format, defaults to "%B %d, %Y, %A"
|
||||
:returns: Current nepali datetime
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return to_nepalidatetime(timezone.now()).strftime(format)
|
||||
|
||||
|
||||
@@ -161,4 +194,8 @@ def nepalinow_ne(format: str = _DEFAULT_DATE_FORMAT) -> str:
|
||||
:param format: Output format, defaults to "%B %d, %Y, %A"
|
||||
:returns: Current nepali datetime
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return to_nepalidatetime(timezone.now()).strftime_ne(format)
|
||||
@@ -1,3 +1,7 @@
|
||||
"""
|
||||
This module contains django templatetags for nepali number.
|
||||
"""
|
||||
import warnings
|
||||
from typing import Any
|
||||
|
||||
from django import template
|
||||
@@ -11,6 +15,12 @@ from nepali.number import (
|
||||
|
||||
register = template.Library()
|
||||
|
||||
DEPRECIATION_WARNING_MESSAGE = (
|
||||
"The templatetag 'nepalinumber' has been depreciated "
|
||||
"and will be removed in the future release. "
|
||||
"Please use `django-nepali` package."
|
||||
)
|
||||
|
||||
|
||||
@register.filter(name="nepalinumber")
|
||||
def nepalinumber(value: Any) -> str:
|
||||
@@ -25,6 +35,10 @@ def nepalinumber(value: Any) -> str:
|
||||
:param value: Number to be converted
|
||||
:returns: Nepali output of given number
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return english_to_nepali(value)
|
||||
|
||||
|
||||
@@ -42,6 +56,10 @@ def nepalinumber_with_comma(value: Any) -> str:
|
||||
:param value: Number to be converted and commas added
|
||||
:returns: Nepali output of given number with commas
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return convert_and_add_comma(value)
|
||||
|
||||
|
||||
@@ -58,6 +76,10 @@ def nepali_comma(value: Any) -> str:
|
||||
:param value: Number to be added with commas
|
||||
:returns: Output of given number with commas
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return add_comma(value)
|
||||
|
||||
|
||||
@@ -74,4 +96,8 @@ def english_comma(value: Any) -> str:
|
||||
:param value: Number to be added with commas
|
||||
:returns: Output of given number with commas
|
||||
"""
|
||||
warnings.warn(
|
||||
message=DEPRECIATION_WARNING_MESSAGE,
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return add_comma_english(value)
|
||||
Reference in new issue
Block a user