Commit 37b023b6 authored by Miquel Torres's avatar Miquel Torres
Browse files

Set default_branch based on repo type

parent 69fab17e
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django import forms
from django.contrib import admin
from codespeed.models import (Project, Revision, Executable, Benchmark, Branch, from codespeed.models import (Project, Revision, Executable, Benchmark, Branch,
Result, Environment, Report) 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"
self.add_error('default_branch', 'This field is required.')
class Meta:
model = Project
fields = '__all__'
@admin.register(Project) @admin.register(Project)
class ProjectAdmin(admin.ModelAdmin): class ProjectAdmin(admin.ModelAdmin):
list_display = ('name', 'repo_type', 'repo_path', 'track') list_display = ('name', 'repo_type', 'repo_path', 'track')
form = ProjectForm
@admin.register(Branch) @admin.register(Branch)
class BranchAdmin(admin.ModelAdmin): class BranchAdmin(admin.ModelAdmin):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment