Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add relation between project and remote repoistory objects #2745

Merged
merged 2 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified readthedocs/core/static/core/font/Inconsolata-Bold.ttf
Binary file not shown.
Binary file modified readthedocs/core/static/core/font/Inconsolata-Regular.ttf
Binary file not shown.
Binary file modified readthedocs/core/static/core/font/Lato-Bold.ttf
Binary file not shown.
Binary file modified readthedocs/core/static/core/font/Lato-Regular.ttf
Binary file not shown.
21 changes: 21 additions & 0 deletions readthedocs/oauth/migrations/0008_add-project-relation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-03-22 20:10
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('oauth', '0007_org_slug_nonunique'),
]

operations = [
migrations.AddField(
model_name='remoterepository',
name='project',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='remote_repository', to='projects.Project'),
),
]
3 changes: 3 additions & 0 deletions readthedocs/oauth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class RemoteRepository(models.Model):
related_name='repositories', null=True, blank=True)
active = models.BooleanField(_('Active'), default=False)

project = models.OneToOneField(Project, on_delete=models.SET_NULL,
related_name='remote_repository', null=True,
blank=True)
name = models.CharField(_('Name'), max_length=255)
full_name = models.CharField(_('Full Name'), max_length=255)
description = models.TextField(_('Description'), blank=True, null=True,
Expand Down
33 changes: 32 additions & 1 deletion readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from readthedocs.builds.constants import TAG
from readthedocs.core.utils import trigger_build, slugify
from readthedocs.redirects.models import Redirect
from readthedocs.oauth.models import RemoteRepository
from readthedocs.projects import constants
from readthedocs.projects.exceptions import ProjectSpamError
from readthedocs.projects.models import Project, EmailHook, WebHook, Domain
Expand Down Expand Up @@ -74,6 +75,11 @@ class Meta:
model = Project
fields = ('name', 'repo', 'repo_type')

remote_repository = forms.CharField(
widget=forms.HiddenInput(),
required=False,
)

def __init__(self, *args, **kwargs):
show_advanced = kwargs.pop('show_advanced', False)
super(ProjectBasicsForm, self).__init__(*args, **kwargs)
Expand All @@ -85,6 +91,18 @@ def __init__(self, *args, **kwargs):
self.fields['repo'].widget.attrs['placeholder'] = self.placehold_repo()
self.fields['repo'].widget.attrs['required'] = True

def save(self, commit=True):
"""Add remote repository relationship to the project instance"""
instance = super(ProjectBasicsForm, self).save(commit)
remote_repo = self.cleaned_data.get('remote_repository', None)
if remote_repo:
if commit:
remote_repo.project = self.instance
remote_repo.save()
else:
instance.remote_repository = remote_repo
return instance

def clean_name(self):
name = self.cleaned_data.get('name', '')
if not self.instance.pk:
Expand All @@ -105,6 +123,18 @@ def clean_repo(self):
u'public (http:// or git://) clone url'))
return repo

def clean_remote_repository(self):
remote_repo = self.cleaned_data.get('remote_repository', None)
if not remote_repo:
return None
try:
return RemoteRepository.objects.get(
pk=remote_repo,
users=self.user,
)
except RemoteRepository.DoesNotExist:
raise forms.ValidationError(_(u'Repository invalid'))

def placehold_repo(self):
return choice([
'https://bitbucket.org/cherrypy/cherrypy',
Expand All @@ -126,7 +156,8 @@ class Meta:
fields = (
'description',
'documentation_type',
'language', 'programming_language',
'language',
'programming_language',
'project_url',
'tags',
)
Expand Down
1 change: 1 addition & 0 deletions readthedocs/projects/static-src/projects/js/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function Project (instance, view) {
repo_type: self.vcs(),
description: self.description(),
project_url: self.html_url(),
remote_repository: self.id(),
},
form = $('<form />');

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/static/projects/js/import.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,8 @@ def get_form_kwargs(self, step=None):
kwargs['user'] = self.request.user
if step == 'basics':
kwargs['show_advanced'] = True
if step == 'extra':
extra_form = self.get_form_from_step('basics')
project = extra_form.save(commit=False)
kwargs['instance'] = project
return kwargs

def get_form_from_step(self, step):
form = self.form_list[step](
data=self.get_cleaned_data_for_step(step),
**self.get_form_kwargs(step)
)
form.full_clean()
return form

def get_template_names(self):
"""Return template names based on step name"""
return 'projects/import_{0}.html'.format(self.steps.current)
Expand Down Expand Up @@ -370,7 +358,7 @@ def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
initial_data = {}
initial_data['basics'] = {}
for key in ['name', 'repo', 'repo_type']:
for key in ['name', 'repo', 'repo_type', 'remote_repository']:
initial_data['basics'][key] = request.POST.get(key)
initial_data['extra'] = {}
for key in ['description', 'project_url']:
Expand Down
Loading