Skip to content

Commit

Permalink
Add separate version create view and create view URL
Browse files Browse the repository at this point in the history
This is not currently used outside the new theme, but enables the
solution for #6238 -- latest `master` of the new theme already expects
this code.

For now, the create URL does throw and exception, because we are
rendering template code inside the version form. I'm not going to
address this as the create view is not linked and unused, and we
probably shouldn't be rendering templates inside form instantiation
anyways.

The edit version URL does change with this, to append the `/edit/`
postfix. This was done to match similar URL patterns, and to give a path
for the create view URL that does not match the edit URL pattern.
  • Loading branch information
agjohnson committed Oct 23, 2020
1 parent a81d82e commit 3c4bb63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion readthedocs/projects/urls/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
ProjectUsersCreateList,
ProjectUsersDelete,
ProjectVersionDeleteHTML,
ProjectVersionCreate,
ProjectVersionDetail,
RegexAutomationRuleCreate,
RegexAutomationRuleUpdate,
Expand Down Expand Up @@ -82,7 +83,12 @@
name='project_version_delete_html',
),
url(
r'^(?P<project_slug>[-\w]+)/version/(?P<version_slug>[^/]+)/$',
r'^(?P<project_slug>[-\w]+)/version/create/$',
ProjectVersionCreate.as_view(),
name='project_version_create',
),
url(
r'^(?P<project_slug>[-\w]+)/version/(?P<version_slug>[^/]+)/edit/$',
ProjectVersionDetail.as_view(),
name='project_version_detail',
),
Expand Down
14 changes: 11 additions & 3 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ def get_success_url(self):
)


class ProjectVersionDetail(ProjectVersionMixin, UpdateView):

template_name = 'projects/project_version_detail.html'
class ProjectVersionEditMixin(ProjectVersionMixin):

def get_queryset(self):
return Version.internal.public(
Expand Down Expand Up @@ -222,6 +220,16 @@ def form_valid(self, form):
return HttpResponseRedirect(self.get_success_url())


class ProjectVersionCreate(ProjectVersionEditMixin, CreateView):

template_name = 'projects/project_version_detail.html'


class ProjectVersionDetail(ProjectVersionEditMixin, UpdateView):

template_name = 'projects/project_version_detail.html'


class ProjectVersionDeleteHTML(ProjectVersionMixin, GenericModelView):

http_method_names = ['post']
Expand Down

0 comments on commit 3c4bb63

Please sign in to comment.