mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
rrs: default python2/3 environments for new maintenance plan layer branches
It's a bit of a pain to have to set the two python environment fields on every record in order to have things set correctly, and it can easily get forgotten, so try to set them automatically by default (assuming reasonable naming). Note that this does introduce an annoying behaviour whereby if you click "Add another Maintenance plan layer branch" and then decide you don't want it, the admin form will insist you fill in the fields unless you clear out the python2/3 environment fields. I'm not sure how to fix that, so I'm leaving it as-is for now. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
1f037470fb
commit
34466bac1d
|
@ -47,6 +47,20 @@ class PythonEnvironment(models.Model):
|
||||||
cmd = self.python_command
|
cmd = self.python_command
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_default_python2_environment():
|
||||||
|
for env in PythonEnvironment.objects.all().order_by('id'):
|
||||||
|
if env.name.replace(' ', '').lower().startswith(('python2', 'py2')):
|
||||||
|
return env
|
||||||
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_default_python3_environment():
|
||||||
|
for env in PythonEnvironment.objects.all().order_by('id'):
|
||||||
|
if env.name.replace(' ', '').lower().startswith(('python3', 'py3')):
|
||||||
|
return env
|
||||||
|
return None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
30
rrs/admin.py
30
rrs/admin.py
|
@ -4,16 +4,46 @@
|
||||||
#
|
#
|
||||||
# Licensed under the MIT license, see COPYING.MIT for details
|
# Licensed under the MIT license, see COPYING.MIT for details
|
||||||
|
|
||||||
|
from django.utils.functional import curry
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.admin import DateFieldListFilter
|
from django.contrib.admin import DateFieldListFilter
|
||||||
|
from django.forms.models import BaseInlineFormSet
|
||||||
|
|
||||||
from rrs.models import Release, Milestone, Maintainer, RecipeMaintainerHistory, \
|
from rrs.models import Release, Milestone, Maintainer, RecipeMaintainerHistory, \
|
||||||
RecipeMaintainer, RecipeDistro, RecipeUpgrade, RecipeUpstream, \
|
RecipeMaintainer, RecipeDistro, RecipeUpgrade, RecipeUpstream, \
|
||||||
RecipeUpstreamHistory, MaintenancePlan, MaintenancePlanLayerBranch, \
|
RecipeUpstreamHistory, MaintenancePlan, MaintenancePlanLayerBranch, \
|
||||||
RecipeMaintenanceLink
|
RecipeMaintenanceLink
|
||||||
|
|
||||||
|
class MaintenancePlanLayerBranchFormSet(BaseInlineFormSet):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
from layerindex.models import PythonEnvironment
|
||||||
|
initialfields = {}
|
||||||
|
py2env = PythonEnvironment.get_default_python2_environment()
|
||||||
|
if py2env:
|
||||||
|
initialfields['python2_environment'] = py2env.id
|
||||||
|
py3env = PythonEnvironment.get_default_python3_environment()
|
||||||
|
if py3env:
|
||||||
|
initialfields['python3_environment'] = py3env.id
|
||||||
|
if initialfields:
|
||||||
|
kwargs['initial'] = [initialfields]
|
||||||
|
super(MaintenancePlanLayerBranchFormSet, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def empty_form(self):
|
||||||
|
from layerindex.models import PythonEnvironment
|
||||||
|
form = super(MaintenancePlanLayerBranchFormSet, self).empty_form
|
||||||
|
py2env = PythonEnvironment.get_default_python2_environment()
|
||||||
|
if py2env:
|
||||||
|
form.fields['python2_environment'].initial = py2env
|
||||||
|
py3env = PythonEnvironment.get_default_python3_environment()
|
||||||
|
if py3env:
|
||||||
|
form.fields['python3_environment'].initial = py3env
|
||||||
|
return form
|
||||||
|
|
||||||
class MaintenancePlanLayerBranchInline(admin.StackedInline):
|
class MaintenancePlanLayerBranchInline(admin.StackedInline):
|
||||||
model = MaintenancePlanLayerBranch
|
model = MaintenancePlanLayerBranch
|
||||||
|
formset = MaintenancePlanLayerBranchFormSet
|
||||||
readonly_fields = ['upgrade_date', 'upgrade_rev']
|
readonly_fields = ['upgrade_date', 'upgrade_rev']
|
||||||
min_num = 1
|
min_num = 1
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user