request_casting 0.5.0__tar.gz → 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,16 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: request_casting
3
- Version: 0.5.0
3
+ Version: 0.7.0
4
4
  Summary: Provide method to cast django request data for POST and GET methods
5
5
  License: GPL-3.0 license
6
6
  Author: turulomio
7
7
  Author-email: turulomio@yahoo.es
8
- Requires-Python: >3.8,<4.0
8
+ Requires-Python: >3.10,<4.0
9
9
  Classifier: License :: Other/Proprietary License
10
10
  Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.9
12
- Classifier: Programming Language :: Python :: 3.10
13
11
  Classifier: Programming Language :: Python :: 3.11
14
12
  Classifier: Programming Language :: Python :: 3.12
15
- Requires-Dist: pydicts (>=0.9.0)
13
+ Requires-Dist: pydicts (>=0.16.0)
16
14
  Description-Content-Type: text/markdown
17
15
 
18
16
  # request_casting
@@ -109,6 +107,19 @@ curl http://localhost:8000/myview/?a=2011-10-05T14:48:00.000Z => a will be a d
109
107
  curl http://localhost:8000/myview/?a=2021-1-1 => a will be None
110
108
  ```
111
109
 
110
+ ### RequestEmail
111
+ Use this method inside a view to get a validated email
112
+
113
+ ```python
114
+ # ... The same as RequestBool example
115
+ a=request_casting.RequestEmail(request, "a")
116
+ ```
117
+ You'll get this answers
118
+ ```
119
+ curl http://localhost:8000/myview/?a=hi@hi.com => a will be an email
120
+ curl http://localhost:8000/myview/?a=hi.hi.com => a will be None
121
+ ```
122
+
112
123
  ### RequestInteger
113
124
 
114
125
  Use this method inside a view to get a casted Integer
@@ -242,6 +253,13 @@ Run `poe coverage` to test module.
242
253
 
243
254
  ## Changelog
244
255
 
256
+ ### 0.7.0 (2024-04-13)
257
+ - Using pydicts-0.16.0
258
+ - Added RequestEmail method
259
+
260
+ ### 0.6.0 (2023-12-14)
261
+ - Using pydicts-0.11.0 library to capture errors and fix bugs
262
+
245
263
  ### 0.5.0 (2023-12-05)
246
264
  - Added support to request_casting with json formats (APICLIENT)
247
265
 
@@ -92,6 +92,19 @@ curl http://localhost:8000/myview/?a=2011-10-05T14:48:00.000Z => a will be a d
92
92
  curl http://localhost:8000/myview/?a=2021-1-1 => a will be None
93
93
  ```
94
94
 
95
+ ### RequestEmail
96
+ Use this method inside a view to get a validated email
97
+
98
+ ```python
99
+ # ... The same as RequestBool example
100
+ a=request_casting.RequestEmail(request, "a")
101
+ ```
102
+ You'll get this answers
103
+ ```
104
+ curl http://localhost:8000/myview/?a=hi@hi.com => a will be an email
105
+ curl http://localhost:8000/myview/?a=hi.hi.com => a will be None
106
+ ```
107
+
95
108
  ### RequestInteger
96
109
 
97
110
  Use this method inside a view to get a casted Integer
@@ -225,6 +238,13 @@ Run `poe coverage` to test module.
225
238
 
226
239
  ## Changelog
227
240
 
241
+ ### 0.7.0 (2024-04-13)
242
+ - Using pydicts-0.16.0
243
+ - Added RequestEmail method
244
+
245
+ ### 0.6.0 (2023-12-14)
246
+ - Using pydicts-0.11.0 library to capture errors and fix bugs
247
+
228
248
  ### 0.5.0 (2023-12-05)
229
249
  - Added support to request_casting with json formats (APICLIENT)
230
250
 
@@ -1,21 +1,21 @@
1
1
  [tool.poetry]
2
2
  name = "request_casting"
3
- version = "0.5.0"
3
+ version = "0.7.0"
4
4
  description = "Provide method to cast django request data for POST and GET methods"
5
5
  authors = ["turulomio <turulomio@yahoo.es>"]
6
6
  license = "GPL-3.0 license"
7
7
  readme = "README.md"
8
8
 
9
9
  [tool.poetry.dependencies]
10
- python = ">3.8,<4.0"
11
- pydicts = ">=0.9.0"
10
+ python = ">3.10,<4.0"
11
+ pydicts = ">=0.16.0"
12
12
 
13
13
  [tool.poetry.group.dev.dependencies]
14
- poetry = ">=1.5.1"
15
- poethepoet = ">=0.22.0"
16
- django = ">=4.2.7"
17
- djangorestframework = ">=3.14.0"
18
- coverage = ">=7.3.2"
14
+ poetry = ">=1.8.2"
15
+ poethepoet = ">=0.25.0"
16
+ django = ">=5.0.4"
17
+ djangorestframework = ">=3.15.1"
18
+ coverage = ">=7.4.4"
19
19
 
20
20
  [build-system]
21
21
  requires = ["poetry-core"]
@@ -24,6 +24,7 @@ build-backend = "poetry.core.masonry.api"
24
24
  [tool.poe.tasks]
25
25
  release = { script = "request_casting.poethepoet:release" }
26
26
  reusing = { script = "request_casting.poethepoet:reusing" }
27
+ test = { script = "request_casting.poethepoet:test" }
27
28
  coverage = { script = "request_casting.poethepoet:coverage" }
28
29
  translate = { script = "request_casting.poethepoet:translate" }
29
30
 
@@ -1,4 +1,4 @@
1
1
  from datetime import datetime
2
- __version__="0.5.0"
3
- __version_datetime__=datetime(2023, 12, 5, 5, 33)
2
+ __version__="0.7.0"
3
+ __version_datetime__=datetime(2024, 4, 13, 11, 0)
4
4
  __version_date__=__version_datetime__.date()
@@ -8,7 +8,7 @@ msgid ""
8
8
  msgstr ""
9
9
  "Project-Id-Version: TooManyFiles\n"
10
10
  "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2023-12-03 11:18+0100\n"
11
+ "POT-Creation-Date: 2023-12-14 20:40+0100\n"
12
12
  "PO-Revision-Date: 2020-04-03 08:54+0200\n"
13
13
  "Last-Translator: trabajo <turulomio@yahoo.es>\n"
14
14
  "Language-Team: Spanish <kde-i18n-doc@kde.org>\n"
@@ -20,45 +20,21 @@ msgstr ""
20
20
  "X-Generator: Lokalize 19.12.3\n"
21
21
 
22
22
  #, python-brace-format
23
- msgid "Error in RequestDate with method {0}"
24
- msgstr "Error en RequestDate con método {0}"
25
-
26
- #, python-brace-format
27
- msgid "Error in RequestBool with method {0}"
28
- msgstr "Error en RequestBool con método {0}"
29
-
30
- #, python-brace-format
31
- msgid "Error in RequestDecimal with method {0}"
32
- msgstr "Error en RequestDecimal con método {0}"
33
-
34
- #, python-brace-format
35
- msgid "Error in RequestInteger with method {0}"
36
- msgstr ""
37
-
38
- #, python-brace-format
39
- msgid "Error in RequestListOfStrings with method {0}"
40
- msgstr ""
41
-
42
- #, python-brace-format
43
- msgid "Error in RequestListOfBools with method {0}"
44
- msgstr ""
45
-
46
- #, python-brace-format
47
- msgid "Error in RequestListOfIntegers with method {0}"
48
- msgstr ""
23
+ msgid "I couldn't get id from this url: {0}"
24
+ msgstr "No pude conseguir el id de esta url: {0}"
49
25
 
50
26
  #, python-brace-format
51
- msgid "Error in RequestDtaware with method {0}"
27
+ msgid "Url ({0}) couldn't be parsed. Model: {1}. Real string before id: {2}"
52
28
  msgstr ""
53
29
 
54
30
  #, python-brace-format
55
- msgid "Error in RequestString with method {0}"
56
- msgstr ""
31
+ #~ msgid "Error in RequestDate with method {0}"
32
+ #~ msgstr "Error en RequestDate con método {0}"
57
33
 
58
34
  #, python-brace-format
59
- msgid "I couldn't get id from this url: {0}"
60
- msgstr "No pude conseguir el id de esta url: {0}"
35
+ #~ msgid "Error in RequestBool with method {0}"
36
+ #~ msgstr "Error en RequestBool con método {0}"
61
37
 
62
38
  #, python-brace-format
63
- msgid "Url ({0}) couldn't be parsed. Model: {1}. Real string before id: {2}"
64
- msgstr ""
39
+ #~ msgid "Error in RequestDecimal with method {0}"
40
+ #~ msgstr "Error en RequestDecimal con método {0}"
@@ -0,0 +1,26 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: PACKAGE VERSION\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2024-04-13 11:04+0200\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=CHARSET\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+
20
+ #, python-brace-format
21
+ msgid "I couldn't get id from this url: {0}"
22
+ msgstr ""
23
+
24
+ #, python-brace-format
25
+ msgid "Url ({0}) couldn't be parsed. Model: {1}. Real string before id: {2}"
26
+ msgstr ""
@@ -13,6 +13,10 @@ def coverage():
13
13
  chdir("django_test")
14
14
  system("python manage.py coverage")
15
15
 
16
+ def test():
17
+ chdir("django_test")
18
+ system("python manage.py test")
19
+
16
20
  def translate():
17
21
  system("xgettext -L Python --no-wrap --no-location --from-code='UTF-8' -o request_casting/locale/request_casting.pot request_casting/*.py")
18
22
  system("msgmerge -N --no-wrap -U request_casting/locale/es.po request_casting/locale/request_casting.pot")
@@ -1,4 +1,3 @@
1
- from decimal import Decimal
2
1
  from gettext import translation
3
2
  from importlib.resources import files
4
3
  from pydicts import casts
@@ -33,7 +32,7 @@ def RequestUrl(request, field, class_, default=None, select_related=[], prefetc
33
32
  try:
34
33
  return object_from_url(dictionary.get(field), class_, model_url, select_related, prefetch_related, validate_object)
35
34
  except:
36
- return None
35
+ return default
37
36
 
38
37
 
39
38
  ## Returns a query_set obect
@@ -78,11 +77,9 @@ def RequestDate(request, field, default=None):
78
77
 
79
78
  if not field in dictionary:
80
79
  return default
81
- try:
82
- return casts.str2date(dictionary.get(field))
83
- except:
84
- raise RequestCastingError(_("Error in RequestDate with method {0}").format(request.method))
85
-
80
+
81
+ return casts.str2date(dictionary.get(field), ignore_exception=True, ignore_exception_value=default)
82
+
86
83
  def RequestBool(request, field, default=None):
87
84
  if request.method=="GET":
88
85
  dictionary=request.GET
@@ -91,13 +88,8 @@ def RequestBool(request, field, default=None):
91
88
 
92
89
  if not field in dictionary:
93
90
  return default
94
- try:
95
- if dictionary.__class__==dict:
96
- return bool(dictionary.get(field))
97
- else:#Querydict
98
- return casts.str2bool(dictionary.get(field))
99
- except:
100
- raise RequestCastingError(_("Error in RequestBool with method {0}").format(request.method))
91
+
92
+ return casts.str2bool(str(dictionary.get(field)), ignore_exception=True, ignore_exception_value=default)
101
93
 
102
94
  def RequestDecimal(request, field, default=None):
103
95
  if request.method=="GET":
@@ -107,11 +99,8 @@ def RequestDecimal(request, field, default=None):
107
99
 
108
100
  if not field in dictionary:
109
101
  return default
110
-
111
- try:
112
- return Decimal(dictionary.get(field))
113
- except:
114
- raise RequestCastingError(_("Error in RequestDecimal with method {0}").format(request.method))
102
+
103
+ return casts.str2decimal(str(dictionary.get(field)), ignore_exception=True, ignore_exception_value=default)
115
104
 
116
105
  def RequestInteger(request, field, default=None):
117
106
  if request.method=="GET":
@@ -125,7 +114,7 @@ def RequestInteger(request, field, default=None):
125
114
  try:
126
115
  return int(dictionary.get(field))
127
116
  except:
128
- raise RequestCastingError(_("Error in RequestInteger with method {0}").format(request.method))
117
+ return default
129
118
 
130
119
  def RequestListOfStrings(request, field, default=None):
131
120
  if request.method=="GET":
@@ -147,7 +136,7 @@ def RequestListOfStrings(request, field, default=None):
147
136
  r.append(str(i))
148
137
  return r
149
138
  except:
150
- raise RequestCastingError(_("Error in RequestListOfStrings with method {0}").format(request.method))
139
+ return default
151
140
 
152
141
  def RequestListOfBools(request, field, default=None):
153
142
  if request.method=="GET":
@@ -162,14 +151,14 @@ def RequestListOfBools(request, field, default=None):
162
151
  r=[]
163
152
  if dictionary.__class__==dict:
164
153
  for value in dictionary[field]:
165
- r.append(bool(value))
154
+ r.append(casts.str2bool(str(value), ignore_exception=True, ignore_exception_value=None))
166
155
  else:#Querydict
167
156
  items=dictionary.getlist(field, [])
168
157
  for i in items:
169
- r.append(casts.str2bool(i))
158
+ r.append(casts.str2bool(str(i), ignore_exception=True, ignore_exception_value=None))
170
159
  return r
171
160
  except:
172
- raise RequestCastingError(_("Error in RequestListOfBools with method {0}").format(request.method))
161
+ return default
173
162
 
174
163
  def RequestListOfIntegers(request, field, default=None, separator=","):
175
164
  """
@@ -189,14 +178,20 @@ def RequestListOfIntegers(request, field, default=None, separator=","):
189
178
  r=[]
190
179
  if dictionary.__class__==dict:
191
180
  for value in dictionary[field]:
192
- r.append(int(value))
181
+ try:
182
+ r.append(int(value))
183
+ except:
184
+ r.append(None)
193
185
  else:#Querydict
194
186
  items=dictionary.getlist(field, [])
195
187
  for i in items:
196
- r.append(int(i))
188
+ try:
189
+ r.append(int(i))
190
+ except:
191
+ r.append(None)
197
192
  return r
198
193
  except:
199
- raise RequestCastingError(_("Error in RequestListOfIntegers with method {0}").format(request.method))
194
+ return default
200
195
 
201
196
  def RequestDtaware(request, field, timezone_string, default=None):
202
197
  if request.method=="GET":
@@ -206,13 +201,23 @@ def RequestDtaware(request, field, timezone_string, default=None):
206
201
 
207
202
  if not field in dictionary:
208
203
  return default
209
-
210
- try:
211
- return casts.str2dtaware(dictionary.get(field), "JsUtcIso", timezone_string)
212
- except:
213
- raise RequestCastingError(_("Error in RequestDtaware with method {0}").format(request.method))
214
-
215
-
204
+
205
+
206
+ return casts.str2dtaware(dictionary.get(field), "JsUtcIso", timezone_string, ignore_exception=True, ignore_exception_value=default)
207
+
208
+ def RequestEmail(request, field, default=None):
209
+ if request.method=="GET":
210
+ dictionary=request.GET
211
+ else:
212
+ dictionary=request.data
213
+
214
+ if not field in dictionary:
215
+ return default
216
+
217
+ if casts.is_email(dictionary.get(field)):
218
+ return dictionary.get(field)
219
+ else:
220
+ return default
216
221
 
217
222
  def RequestString(request, field, default=None):
218
223
  if request.method=="GET":
@@ -225,7 +230,7 @@ def RequestString(request, field, default=None):
225
230
  try:
226
231
  return dictionary.get(field)
227
232
  except:
228
- raise RequestCastingError(_("Error in RequestString with method {0}").format(request.method))
233
+ return default
229
234
 
230
235
 
231
236
 
@@ -1,62 +0,0 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
- # This file is distributed under the same license as the PACKAGE package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
- #
6
- #, fuzzy
7
- msgid ""
8
- msgstr ""
9
- "Project-Id-Version: PACKAGE VERSION\n"
10
- "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2023-12-05 05:34+0100\n"
12
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "Language: \n"
16
- "MIME-Version: 1.0\n"
17
- "Content-Type: text/plain; charset=CHARSET\n"
18
- "Content-Transfer-Encoding: 8bit\n"
19
-
20
- #, python-brace-format
21
- msgid "Error in RequestDate with method {0}"
22
- msgstr ""
23
-
24
- #, python-brace-format
25
- msgid "Error in RequestBool with method {0}"
26
- msgstr ""
27
-
28
- #, python-brace-format
29
- msgid "Error in RequestDecimal with method {0}"
30
- msgstr ""
31
-
32
- #, python-brace-format
33
- msgid "Error in RequestInteger with method {0}"
34
- msgstr ""
35
-
36
- #, python-brace-format
37
- msgid "Error in RequestListOfStrings with method {0}"
38
- msgstr ""
39
-
40
- #, python-brace-format
41
- msgid "Error in RequestListOfBools with method {0}"
42
- msgstr ""
43
-
44
- #, python-brace-format
45
- msgid "Error in RequestListOfIntegers with method {0}"
46
- msgstr ""
47
-
48
- #, python-brace-format
49
- msgid "Error in RequestDtaware with method {0}"
50
- msgstr ""
51
-
52
- #, python-brace-format
53
- msgid "Error in RequestString with method {0}"
54
- msgstr ""
55
-
56
- #, python-brace-format
57
- msgid "I couldn't get id from this url: {0}"
58
- msgstr ""
59
-
60
- #, python-brace-format
61
- msgid "Url ({0}) couldn't be parsed. Model: {1}. Real string before id: {2}"
62
- msgstr ""
File without changes