Skip to content

Commit

Permalink
Merge pull request doableware#255 from nesdis/bugfix_235
Browse files Browse the repository at this point in the history
Changes to fix bug 207
  • Loading branch information
nesdis authored Apr 13, 2019
2 parents e861293 + ddb5100 commit 342afef
Show file tree
Hide file tree
Showing 18 changed files with 751 additions and 238 deletions.
43 changes: 36 additions & 7 deletions djongo/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ def clear(self):
def set(self, objs, *, clear=False):
objs = tuple(objs)

db = router.db_for_write(self.through, instance=self.instance)
db = router.db_for_write(self.instance.__class__, instance=self.instance)
with transaction.atomic(using=db, savepoint=False):
if clear:
self.clear()
Expand Down Expand Up @@ -1024,11 +1024,15 @@ def __init__(self, to, on_delete=None, related_name=None, related_query_name=Non
db_constraint=True, **kwargs):

on_delete = on_delete or self._on_delete
super().__init__(to, on_delete=on_delete, related_name=related_name,
super().__init__(to,
on_delete=on_delete,
related_name=related_name,
related_query_name=related_query_name,
limit_choices_to=limit_choices_to,
parent_link=parent_link, to_field=to_field,
db_constraint=db_constraint, **kwargs)
parent_link=parent_link,
to_field=to_field,
db_constraint=db_constraint,
**kwargs)

self.concrete = False

Expand All @@ -1049,10 +1053,35 @@ def to_python(self, value):
def get_db_prep_value(self, value, connection, prepared=False):
if value is None:
return []
elif isinstance(value, set):
return list(value)
return value
# return super().get_db_prep_value(value, connection, prepared)

def get_db_prep_save(self, value, connection):
if value is None:
return []
return list(value)
return self.get_db_prep_value(value, connection)
# if value is None:
# return []
# return list(value)

def validate(self, value, model_instance):
pass
# super().validate(list(value), model_instance)

def save_form_data(self, instance, data):
getattr(instance, self.name).set(list(data), clear=True)

def formfield(self, *, using=None, **kwargs):
defaults = {
'form_class': forms.ModelMultipleChoiceField,
'queryset': self.remote_field.model._default_manager.using(using),
**kwargs,
}
# If initial is passed in, it's a list of related objects, but the
# MultipleChoiceField takes a list of IDs.
if defaults.get('initial') is not None:
initial = defaults['initial']
if callable(initial):
initial = initial()
defaults['initial'] = [i.pk for i in initial]
return super().formfield(**defaults)
4 changes: 4 additions & 0 deletions djongo/sql2mongo/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ def __iter__(self):
import djongo
exe = SQLDecodeError(
f'FAILED SQL: {self._sql}\n'
f'Params: {self._params}\n'
f'Pymongo error: {e.details}\n'
f'Version: {djongo.__version__}'
)
Expand All @@ -777,6 +778,7 @@ def __iter__(self):
import djongo
exe = SQLDecodeError(
f'FAILED SQL: {self._sql}\n'
f'Params: {self._params}\n'
f'Version: {djongo.__version__}'
)
raise exe from e
Expand Down Expand Up @@ -812,6 +814,7 @@ def parse(self):
import djongo
exe = SQLDecodeError(
f'FAILED SQL: {self._sql}\n'
f'Params: {self._params}\n'
f'Pymongo error: {e.details}\n'
f'Version: {djongo.__version__}'
)
Expand All @@ -821,6 +824,7 @@ def parse(self):
import djongo
exe = SQLDecodeError(
f'FAILED SQL: {self._sql}\n'
f'Params: {self._params}\n'
f'Version: {djongo.__version__}'
)
raise exe from e
Expand Down
2 changes: 1 addition & 1 deletion docs/api/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 1f67724dd463b4d490261e93f7eb9b0f
config: 64eebd5b83a905471a711d417f57a1fb
tags: d77d1c0d9ca2f4c8421862c7c5a0d620
2 changes: 1 addition & 1 deletion docs/api/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.2.24',
VERSION: '1.2.32',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '',
Expand Down
2 changes: 1 addition & 1 deletion docs/api/djongo.dynamic_formsets.templatetags/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>djongo.dynamic_formsets.templatetags package &#8212; djongo 1.2.24 documentation</title>
<title>djongo.dynamic_formsets.templatetags package &#8212; djongo 1.2.32 documentation</title>
<link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" src="../_static/documentation_options.js"></script>
Expand Down
7 changes: 6 additions & 1 deletion docs/api/djongo.dynamic_formsets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>djongo.dynamic_formsets package &#8212; djongo 1.2.24 documentation</title>
<title>djongo.dynamic_formsets package &#8212; djongo 1.2.32 documentation</title>
<link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" src="../_static/documentation_options.js"></script>
Expand Down Expand Up @@ -60,6 +60,11 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
<code class="descname">name</code><em class="property"> = 'dynamic_formsets'</em><a class="headerlink" href="#djongo.dynamic_formsets.apps.DynamicFormsetsConfig.name" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="djongo.dynamic_formsets.apps.DynamicFormsetsConfig.verbose_name">
<code class="descname">verbose_name</code><em class="property"> = 'Dynamic Formsets'</em><a class="headerlink" href="#djongo.dynamic_formsets.apps.DynamicFormsetsConfig.verbose_name" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</dd></dl>

</div>
Expand Down
Loading

0 comments on commit 342afef

Please sign in to comment.