Skip to content

Commit 9cb119d

Browse files
authored
Merge pull request #18 from pbs-data-solutions/user-native
Add parser for user native
2 parents f58d9a7 + fc4c588 commit 9cb119d

File tree

8 files changed

+564
-410
lines changed

8 files changed

+564
-410
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ deserializing to Python classes with PyO3.
1010

1111
- [x] Subject native XML
1212
- [x] Site Native XML
13-
- [ ] User Native XML
13+
- [x] User Native XML

src/lib.rs

Lines changed: 207 additions & 14 deletions
Large diffs are not rendered by default.

src/native/common.rs

Lines changed: 215 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ pub struct Field {
176176
#[serde(alias = "type")]
177177
pub field_type: String,
178178

179-
pub data_type: String,
179+
#[serde(
180+
default = "default_string_none",
181+
deserialize_with = "deserialize_empty_string_as_none"
182+
)]
183+
pub data_type: Option<String>,
180184
pub error_code: String,
181185
pub when_created: DateTime<Utc>,
182186
pub keep_history: bool,
@@ -195,7 +199,12 @@ pub struct Field {
195199
#[serde(alias = "type")]
196200
pub field_type: String,
197201

198-
pub data_type: String,
202+
#[serde(
203+
default = "default_string_none",
204+
deserialize_with = "deserialize_empty_string_as_none"
205+
)]
206+
pub data_type: Option<String>,
207+
199208
pub error_code: String,
200209
pub when_created: DateTime<Utc>,
201210
pub keep_history: bool,
@@ -218,7 +227,7 @@ impl Field {
218227
}
219228

220229
#[getter]
221-
fn data_type(&self) -> PyResult<String> {
230+
fn data_type(&self) -> PyResult<Option<String>> {
222231
Ok(self.data_type.clone())
223232
}
224233

@@ -328,3 +337,206 @@ impl State {
328337
to_py_datetime_option(py, &self.date_signed)
329338
}
330339
}
340+
341+
#[cfg(not(feature = "python"))]
342+
#[derive(Debug, Deserialize, PartialEq)]
343+
#[serde(rename_all = "camelCase")]
344+
pub struct Form {
345+
pub name: String,
346+
347+
#[serde(
348+
default = "default_datetime_none",
349+
deserialize_with = "deserialize_empty_string_as_none_datetime"
350+
)]
351+
pub last_modified: Option<DateTime<Utc>>,
352+
353+
#[serde(
354+
default = "default_string_none",
355+
deserialize_with = "deserialize_empty_string_as_none"
356+
)]
357+
pub who_last_modified_name: Option<String>,
358+
359+
#[serde(
360+
default = "default_string_none",
361+
deserialize_with = "deserialize_empty_string_as_none"
362+
)]
363+
pub who_last_modified_role: Option<String>,
364+
365+
pub when_created: usize,
366+
pub has_errors: bool,
367+
pub has_warnings: bool,
368+
pub locked: bool,
369+
370+
#[serde(
371+
default = "default_string_none",
372+
deserialize_with = "deserialize_empty_string_as_none"
373+
)]
374+
pub user: Option<String>,
375+
376+
#[serde(
377+
default = "default_datetime_none",
378+
deserialize_with = "deserialize_empty_string_as_none_datetime"
379+
)]
380+
pub date_time_changed: Option<DateTime<Utc>>,
381+
382+
pub form_title: String,
383+
pub form_index: usize,
384+
385+
#[serde(
386+
default = "default_string_none",
387+
deserialize_with = "deserialize_empty_string_as_none"
388+
)]
389+
pub form_group: Option<String>,
390+
391+
pub form_state: String,
392+
393+
#[serde(rename = "state", default)]
394+
pub states: Option<Vec<State>>,
395+
396+
#[serde(rename = "category", default)]
397+
pub categories: Option<Vec<Category>>,
398+
}
399+
400+
#[cfg(feature = "python")]
401+
#[derive(Clone, Debug, Deserialize, PartialEq)]
402+
#[serde(rename_all = "camelCase")]
403+
#[pyclass]
404+
pub struct Form {
405+
pub name: String,
406+
407+
#[serde(
408+
default = "default_datetime_none",
409+
deserialize_with = "deserialize_empty_string_as_none_datetime"
410+
)]
411+
pub last_modified: Option<DateTime<Utc>>,
412+
413+
#[serde(
414+
default = "default_string_none",
415+
deserialize_with = "deserialize_empty_string_as_none"
416+
)]
417+
pub who_last_modified_name: Option<String>,
418+
419+
#[serde(
420+
default = "default_string_none",
421+
deserialize_with = "deserialize_empty_string_as_none"
422+
)]
423+
pub who_last_modified_role: Option<String>,
424+
425+
pub when_created: usize,
426+
pub has_errors: bool,
427+
pub has_warnings: bool,
428+
pub locked: bool,
429+
430+
#[serde(
431+
default = "default_string_none",
432+
deserialize_with = "deserialize_empty_string_as_none"
433+
)]
434+
pub user: Option<String>,
435+
436+
#[serde(
437+
default = "default_datetime_none",
438+
deserialize_with = "deserialize_empty_string_as_none_datetime"
439+
)]
440+
pub date_time_changed: Option<DateTime<Utc>>,
441+
442+
pub form_title: String,
443+
pub form_index: usize,
444+
445+
#[serde(
446+
default = "default_string_none",
447+
deserialize_with = "deserialize_empty_string_as_none"
448+
)]
449+
pub form_group: Option<String>,
450+
451+
pub form_state: String,
452+
453+
#[serde(rename = "state", default)]
454+
pub states: Option<Vec<State>>,
455+
456+
#[serde(rename = "category", default)]
457+
pub categories: Option<Vec<Category>>,
458+
}
459+
460+
#[cfg(feature = "python")]
461+
#[pymethods]
462+
impl Form {
463+
#[getter]
464+
fn name(&self) -> PyResult<String> {
465+
Ok(self.name.clone())
466+
}
467+
468+
#[getter]
469+
fn last_modified<'py>(&self, py: Python<'py>) -> PyResult<Option<Bound<'py, PyDateTime>>> {
470+
to_py_datetime_option(py, &self.last_modified)
471+
}
472+
473+
#[getter]
474+
fn who_last_modified_name(&self) -> PyResult<Option<String>> {
475+
Ok(self.who_last_modified_name.clone())
476+
}
477+
478+
#[getter]
479+
fn who_last_modified_role(&self) -> PyResult<Option<String>> {
480+
Ok(self.who_last_modified_role.clone())
481+
}
482+
483+
#[getter]
484+
fn when_created(&self) -> PyResult<usize> {
485+
Ok(self.when_created)
486+
}
487+
488+
#[getter]
489+
fn has_errors(&self) -> PyResult<bool> {
490+
Ok(self.has_errors)
491+
}
492+
493+
#[getter]
494+
fn has_warnings(&self) -> PyResult<bool> {
495+
Ok(self.has_warnings)
496+
}
497+
498+
#[getter]
499+
fn locked(&self) -> PyResult<bool> {
500+
Ok(self.locked)
501+
}
502+
503+
#[getter]
504+
fn user(&self) -> PyResult<Option<String>> {
505+
Ok(self.user.clone())
506+
}
507+
508+
#[getter]
509+
fn date_time_changed<'py>(&self, py: Python<'py>) -> PyResult<Option<Bound<'py, PyDateTime>>> {
510+
to_py_datetime_option(py, &self.date_time_changed)
511+
}
512+
513+
#[getter]
514+
fn form_title(&self) -> PyResult<String> {
515+
Ok(self.form_title.clone())
516+
}
517+
518+
#[getter]
519+
fn form_index(&self) -> PyResult<usize> {
520+
Ok(self.form_index)
521+
}
522+
523+
#[getter]
524+
fn form_group(&self) -> PyResult<Option<String>> {
525+
Ok(self.form_group.clone())
526+
}
527+
528+
#[getter]
529+
fn form_state(&self) -> PyResult<String> {
530+
Ok(self.form_state.clone())
531+
}
532+
533+
#[getter]
534+
fn states(&self) -> PyResult<Option<Vec<State>>> {
535+
Ok(self.states.clone())
536+
}
537+
538+
#[getter]
539+
fn categories(&self) -> PyResult<Option<Vec<Category>>> {
540+
Ok(self.categories.clone())
541+
}
542+
}

src/native/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ mod common;
22
mod deserializers;
33
pub mod site_native;
44
pub mod subject_native;
5+
pub mod user_native;

0 commit comments

Comments
 (0)