Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gabriel Silva Vinha
codespeed
Commits
37b023b6
Commit
37b023b6
authored
Aug 16, 2017
by
Miquel Torres
Browse files
Set default_branch based on repo type
parent
69fab17e
Changes
1
Hide whitespace changes
Inline
Side-by-side
codespeed/admin.py
View file @
37b023b6
# -*- coding: utf-8 -*-
from
django
import
forms
from
django.contrib
import
admin
from
codespeed.models
import
(
Project
,
Revision
,
Executable
,
Benchmark
,
Branch
,
Result
,
Environment
,
Report
)
from
django.contrib
import
admin
class
ProjectForm
(
forms
.
ModelForm
):
default_branch
=
forms
.
CharField
(
max_length
=
32
,
required
=
False
)
def
clean
(
self
):
if
not
self
.
cleaned_data
.
get
(
'default_branch'
):
repo_type
=
self
.
cleaned_data
[
'repo_type'
]
if
repo_type
in
[
Project
.
GIT
,
Project
.
GITHUB
]:
self
.
cleaned_data
[
'default_branch'
]
=
"master"
elif
repo_type
==
Project
.
MERCURIAL
:
self
.
cleaned_data
[
'default_branch'
]
=
"default"
elif
repo_type
==
Project
.
SUBVERSION
:
self
.
cleaned_data
[
'default_branch'
]
=
"trunk"
else
:
self
.
add_error
(
'default_branch'
,
'This field is required.'
)
class
Meta
:
model
=
Project
fields
=
'__all__'
@
admin
.
register
(
Project
)
class
ProjectAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'name'
,
'repo_type'
,
'repo_path'
,
'track'
)
form
=
ProjectForm
@
admin
.
register
(
Branch
)
class
BranchAdmin
(
admin
.
ModelAdmin
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment