28
28
from readthedocs .core .mixins import ListViewWithForm
29
29
from readthedocs .integrations .models import HttpExchange , Integration
30
30
from readthedocs .projects .forms import (
31
- ProjectBasicsForm , ProjectExtraForm ,
32
- ProjectAdvancedForm , UpdateProjectForm , SubprojectForm ,
31
+ ProjectBasicsForm , ProjectExtraForm , ProjectAdvancedForm ,
32
+ UpdateProjectForm , ProjectRelationshipForm ,
33
33
build_versions_form , UserForm , EmailHookForm , TranslationForm ,
34
34
RedirectForm , WebHookForm , DomainForm , IntegrationForm ,
35
35
ProjectAdvertisingForm )
36
- from readthedocs .projects .models import Project , EmailHook , WebHook , Domain
36
+ from readthedocs .projects .models import (
37
+ Project , ProjectRelationship , EmailHook , WebHook , Domain )
37
38
from readthedocs .projects .views .base import ProjectAdminMixin , ProjectSpamMixin
38
39
from readthedocs .projects import tasks
39
40
from readthedocs .oauth .services import registry
@@ -398,7 +399,7 @@ def edit_alias(request, project_slug, alias_id=None):
398
399
class AliasList (PrivateViewMixin , ListView ):
399
400
model = VersionAlias
400
401
template_context_name = 'alias'
401
- template_name = 'projects/alias_list.html' ,
402
+ template_name = 'projects/alias_list.html'
402
403
403
404
def get_queryset (self ):
404
405
self .project = get_object_or_404 (
@@ -407,44 +408,50 @@ def get_queryset(self):
407
408
return self .project .aliases .all ()
408
409
409
410
410
- @login_required
411
- def project_subprojects (request , project_slug ):
412
- """Project subprojects view and form view"""
413
- project = get_object_or_404 (Project .objects .for_admin_user (request .user ),
414
- slug = project_slug )
411
+ class ProjectRelationshipMixin (ProjectAdminMixin , PrivateViewMixin ):
415
412
416
- form_kwargs = {
417
- 'parent' : project ,
418
- 'user' : request .user ,
419
- }
420
- if request .method == 'POST' :
421
- form = SubprojectForm (request .POST , ** form_kwargs )
422
- if form .is_valid ():
423
- form .save ()
424
- broadcast (type = 'app' , task = tasks .symlink_subproject , args = [project .pk ])
425
- project_dashboard = reverse (
426
- 'projects_subprojects' , args = [project .slug ])
427
- return HttpResponseRedirect (project_dashboard )
428
- else :
429
- form = SubprojectForm (** form_kwargs )
413
+ model = ProjectRelationship
414
+ form_class = ProjectRelationshipForm
415
+ lookup_field = 'child__slug'
416
+ lookup_url_kwarg = 'subproject_slug'
430
417
431
- subprojects = project .subprojects .all ()
418
+ def get_queryset (self ):
419
+ self .project = self .get_project ()
420
+ return self .model .objects .filter (parent = self .project )
432
421
433
- return render_to_response (
434
- 'projects/project_subprojects.html' ,
435
- {'form' : form , 'project' : project , 'subprojects' : subprojects },
436
- context_instance = RequestContext (request )
437
- )
422
+ def get_form (self , data = None , files = None , ** kwargs ):
423
+ kwargs ['user' ] = self .request .user
424
+ return super (ProjectRelationshipMixin , self ).get_form (data , files , ** kwargs )
438
425
426
+ def form_valid (self , form ):
427
+ broadcast (type = 'app' , task = tasks .symlink_subproject ,
428
+ args = [self .get_project ().pk ])
429
+ return super (ProjectRelationshipMixin , self ).form_valid (form )
439
430
440
- @login_required
441
- def project_subprojects_delete (request , project_slug , child_slug ):
442
- parent = get_object_or_404 (Project .objects .for_admin_user (request .user ), slug = project_slug )
443
- child = get_object_or_404 (Project .objects .all (), slug = child_slug )
444
- parent .remove_subproject (child )
445
- broadcast (type = 'app' , task = tasks .symlink_subproject , args = [parent .pk ])
446
- return HttpResponseRedirect (reverse ('projects_subprojects' ,
447
- args = [parent .slug ]))
431
+ def get_success_url (self ):
432
+ return reverse ('projects_subprojects' , args = [self .get_project ().slug ])
433
+
434
+
435
+ class ProjectRelationshipList (ProjectRelationshipMixin , ListView ):
436
+
437
+ def get_context_data (self , ** kwargs ):
438
+ ctx = super (ProjectRelationshipMixin , self ).get_context_data (** kwargs )
439
+ ctx ['superproject' ] = self .project .superprojects .first ()
440
+ return ctx
441
+
442
+
443
+ class ProjectRelationshipCreate (ProjectRelationshipMixin , CreateView ):
444
+ pass
445
+
446
+
447
+ class ProjectRelationshipUpdate (ProjectRelationshipMixin , UpdateView ):
448
+ pass
449
+
450
+
451
+ class ProjectRelationshipDelete (ProjectRelationshipMixin , DeleteView ):
452
+
453
+ def get (self , request , * args , ** kwargs ):
454
+ return self .http_method_not_allowed (request , * args , ** kwargs )
448
455
449
456
450
457
@login_required
0 commit comments