Re: Improve migration conflict detection

2020-02-11 Thread jackotonye
Definitely a plus one on auto resolving migrations a test package still in 
planning aims to solve this 
https://github.com/jackton1/django-migration-resolver-hook

> On Feb 11, 2020, at 1:42 PM, Caio Ariede  wrote:
> 
> Hey folks,
> 
> I was looking at the code used to detect conflicts in migrations [1]. It 
> seems to use a very safe approach, by avoiding with multiple node leafs in 
> the migration graph.
> 
> While this is safe, I’ve been having some problems when it comes to 
> scalability when having multiple migrations created in a short period of time 
> (for the same app).
> 
> Questions:
> 
> 1. Are there any obvious impediments on improving the conflicts detection?
> 2. Does anyone have ideas on how to improve the conflict detection? (eg. 
> going down from app-level to model-level detection)
> 
> 
> Thanks!
> 
> 
> [1] 
> https://github.com/django/django/blob/e3f6e18513224c8ad081e5a19da641f49b0b43da/django/db/migrations/loader.py#L301-L313
> 
> --
> Caio Ariede
> caio.ari...@gmail.com
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/FE717E60-7B66-4050-B233-20C47FBF6038%40gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/06C4829B-7A06-4C5F-81EB-AF9251CA4E78%40gmail.com.


Re: Allow disabling choices in a

2018-04-30 Thread jackotonye
This might be a late answer but this is a simplified version that can be 
modified using the form instance.

You can either pass a list of values to be disabled i.e

def __init__(self, disabled_choices, *args, **kwargs):
self.disabled_choices = disabled_choices

OR

from django.forms import Select


class SelectWidget(Select):
"""
Subclass of Django's select widget that allows disabling options.
"""
def __init__(self, *args, **kwargs):
self._disabled_choices = []
super(SelectWidget, self).__init__(*args, **kwargs)

@property
def disabled_choices(self):
return self._disabled_choices

@disabled_choices.setter
def disabled_choices(self, other):
self._disabled_choices = other

def create_option(self, name, value, label, selected, index, subindex=
None, attrs=None):
option_dict = super(SelectWidget, self).create_option(
name, value, label, selected, index, subindex=subindex, attrs=
attrs
)
if value in self.disabled_choices:
option_dict['attrs']['disabled'] = 'disabled'
return option_dict


To disabled an option based on a condition i.e user isn't a superuser.

class MyForm(forms.Form):
status = forms.ChoiceField(required=True, widget=SelectWidget, choices=
Status.choices())

def __init__(self, request, *args, **kwargs):
if not request.user.is_superuser:
self.fields['status'].widget.disabled_choices = [1, 4]
super().__init__(*args, **kwargs)


On Friday, June 3, 2011 at 12:50:12 PM UTC-4, Jody McIntyre wrote:
>
> We need to be able to disable choices in a , which is done by 
> setting the disabled attribute on the  tag, for example:
> Bananas
>
>  Currently we're doing this by subclassing the Select widget: 
> http://djangosnippets.org/snippets/2453/
>
> It would be nice if the built in Select widget supported this.  One way 
> would be to replace the existing render_option method with what I've 
> written, and I can prepare a patch if desired, but this approach changes 
> the format of the "choices" data structure to something that won't be 
> understood by other widgets.  Perhaps these widgets should be improved too, 
> but I don't want to do this unless my changes have a good chance of being 
> accepted.
>
> I logged this as a ticket (16149) and was told to discuss it here.  To 
> address aagustin's comments:
>
> 1. Backwards compatibility is already addressed.  If the widget is passed 
> a regular "choices" field, the existing behavior is preserved.
>
> 2. I don't understand what you mean by "boilerplate" in the API.  A 
> "choices" field with a disabled choice looks like:
>
> choices = (('apples', 'Apples'),
>('oranges', 'Oranges'),
>('bananas', {'label': 'Bananas',
> 'disabled': True}),
>('grobblefruit', 'Grobblefruit'))
>
> I can't think of a more concise way of clearly representing that 'bananas' 
> is disabled while still allowing it to have a label, unless we want to 
> change the "choices" data structure a lot more to something like:
>
> choices = (('apples', 'Apples'),
>('oranges', 'Oranges'),
>('bananas', 'Bananas',  {'disabled': True}),
>('grobblefruit', 'Grobblefruit'))
>
> Suggestions & other thoughts welcome :)
> Jody
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/bfb05112-e288-48c9-8daa-dbb9ece149d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Mixins] - Order of the Mixins - Is it a bug?

2018-06-15 Thread jackotonye
By design mixins are applied in the order they are inherited.

`class A: pass`
`class B: pass`

```
class C(A, B):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # This will call A.__init__() 
then B.__init__()
 


```

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/37bf280c-f471-4249-a91a-a1809076e367%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.