Skip to content

Commit

Permalink
Set default_branch based on repo type
Browse files Browse the repository at this point in the history
  • Loading branch information
tobami committed Aug 16, 2017
1 parent 69fab17 commit 37b023b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion codespeed/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
# -*- 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):
Expand Down

0 comments on commit 37b023b

Please sign in to comment.