Merge lp:~daker/ubuntu-api-website/fix.1275721 into lp:ubuntu-api-website
- fix.1275721
- Merge into trunk
Proposed by
Adnane Belmadiaf
Status: | Merged |
---|---|
Merged at revision: | 56 |
Proposed branch: | lp:~daker/ubuntu-api-website/fix.1275721 |
Merge into: | lp:ubuntu-api-website |
Diff against target: |
478 lines (+151/-124) 3 files modified
developer_network/apidocs/models.py (+34/-35) developer_network/web/forms.py (+85/-0) developer_network/web/views.py (+32/-89) |
To merge this branch: | bzr merge lp:~daker/ubuntu-api-website/fix.1275721 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu API Website Developers | Pending | ||
Review via email: mp+206594@code.launchpad.net |
Commit message
Code adjustments
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'developer_network/apidocs/models.py' | |||
2 | --- developer_network/apidocs/models.py 2013-12-19 21:14:27 +0000 | |||
3 | +++ developer_network/apidocs/models.py 2014-02-15 20:59:13 +0000 | |||
4 | @@ -1,64 +1,63 @@ | |||
5 | 1 | # -*- coding: utf-8 -*- | ||
6 | 2 | |||
7 | 1 | from django.db import models | 3 | from django.db import models |
10 | 2 | from common.models import Topic, Version, Section | 4 | from common.models import Section |
9 | 3 | # Create your models here. | ||
11 | 4 | 5 | ||
12 | 5 | class Namespace(models.Model): | 6 | class Namespace(models.Model): |
17 | 6 | 7 | ||
14 | 7 | class Meta: | ||
15 | 8 | ordering = ('name',) | ||
16 | 9 | |||
18 | 10 | platform_section = models.ForeignKey(Section) | 8 | platform_section = models.ForeignKey(Section) |
19 | 11 | name = models.CharField(max_length=64) | 9 | name = models.CharField(max_length=64) |
20 | 12 | display_name = models.CharField(max_length=64, blank=True, default='') | 10 | display_name = models.CharField(max_length=64, blank=True, default='') |
22 | 13 | 11 | ||
23 | 12 | class Meta: | ||
24 | 13 | ordering = ('name',) | ||
25 | 14 | |||
26 | 14 | def __unicode__(self): | 15 | def __unicode__(self): |
28 | 15 | return self.name | 16 | return u'%s' % self.name |
29 | 16 | 17 | ||
30 | 17 | 18 | ||
31 | 18 | class Element(models.Model): | 19 | class Element(models.Model): |
32 | 19 | 'Displayable API Element' | 20 | 'Displayable API Element' |
34 | 20 | 21 | ||
35 | 22 | name = models.CharField(max_length=64) | ||
36 | 23 | description= models.CharField(max_length=256, blank=True, default='') | ||
37 | 24 | namespace = models.ForeignKey(Namespace, blank=True, null=True) | ||
38 | 25 | |||
39 | 26 | section = models.ForeignKey(Section) | ||
40 | 27 | fullname = models.CharField(max_length=128) | ||
41 | 28 | keywords = models.CharField(max_length=256, blank=True, default='') | ||
42 | 29 | data = models.TextField(blank=True, default='') | ||
43 | 30 | |||
44 | 21 | class Meta: | 31 | class Meta: |
45 | 22 | verbose_name = "Rendered Element" | 32 | verbose_name = "Rendered Element" |
46 | 23 | verbose_name_plural = "Rendered Elements" | 33 | verbose_name_plural = "Rendered Elements" |
47 | 24 | ordering = ('name',) | 34 | ordering = ('name',) |
57 | 25 | 35 | ||
58 | 26 | name = models.CharField(max_length=64) | 36 | def __unicode__(self): |
59 | 27 | description= models.CharField(max_length=256, blank=True, default='') | 37 | return u'%s' % self.fullname |
51 | 28 | namespace = models.ForeignKey(Namespace, blank=True, null=True) | ||
52 | 29 | |||
53 | 30 | section = models.ForeignKey(Section) | ||
54 | 31 | fullname = models.CharField(max_length=128) | ||
55 | 32 | keywords = models.CharField(max_length=256, blank=True, default='') | ||
56 | 33 | data = models.TextField(blank=True, default='') | ||
60 | 34 | 38 | ||
61 | 35 | @property | 39 | @property |
62 | 36 | def platform_section(self): | 40 | def platform_section(self): |
63 | 37 | return self.section | 41 | return self.section |
64 | 38 | |||
65 | 39 | def __unicode__(self): | ||
66 | 40 | return self.fullname | ||
67 | 41 | 42 | ||
68 | 42 | 43 | ||
69 | 43 | class Page(models.Model): | 44 | class Page(models.Model): |
70 | 44 | 'Displayable Page of non-Element content' | 45 | 'Displayable Page of non-Element content' |
72 | 45 | 46 | ||
73 | 47 | slug = models.CharField(max_length=64) | ||
74 | 48 | title = models.CharField(max_length=64) | ||
75 | 49 | description= models.CharField(max_length=256, blank=True, default='') | ||
76 | 50 | namespace = models.ForeignKey(Namespace, blank=True, null=True) | ||
77 | 51 | |||
78 | 52 | section = models.ForeignKey(Section) | ||
79 | 53 | fullname = models.CharField(max_length=128) | ||
80 | 54 | keywords = models.CharField(max_length=256, blank=True, default='') | ||
81 | 55 | data = models.TextField(blank=True, default='') | ||
82 | 56 | |||
83 | 46 | class Meta: | 57 | class Meta: |
84 | 47 | verbose_name = "Rendered Page" | 58 | verbose_name = "Rendered Page" |
85 | 48 | verbose_name_plural = "Rendered Pages" | 59 | verbose_name_plural = "Rendered Pages" |
86 | 49 | ordering = ('slug',) | 60 | ordering = ('slug',) |
87 | 50 | |||
88 | 51 | slug = models.CharField(max_length=64) | ||
89 | 52 | title = models.CharField(max_length=64) | ||
90 | 53 | description= models.CharField(max_length=256, blank=True, default='') | ||
91 | 54 | namespace = models.ForeignKey(Namespace, blank=True, null=True) | ||
92 | 55 | |||
93 | 56 | section = models.ForeignKey(Section) | ||
94 | 57 | fullname = models.CharField(max_length=128) | ||
95 | 58 | keywords = models.CharField(max_length=256, blank=True, default='') | ||
96 | 59 | data = models.TextField(blank=True, default='') | ||
97 | 60 | 61 | ||
98 | 61 | def __unicode__(self): | 62 | def __unicode__(self): |
102 | 62 | return self.fullname | 63 | return u'%s' % self.fullname |
100 | 63 | |||
101 | 64 | |||
103 | 65 | 64 | ||
104 | === added file 'developer_network/web/forms.py' | |||
105 | --- developer_network/web/forms.py 1970-01-01 00:00:00 +0000 | |||
106 | +++ developer_network/web/forms.py 2014-02-15 20:59:13 +0000 | |||
107 | @@ -0,0 +1,85 @@ | |||
108 | 1 | # -*- coding: utf-8 -*- | ||
109 | 2 | |||
110 | 3 | from django.forms import ModelForm | ||
111 | 4 | from django.contrib.auth.models import User | ||
112 | 5 | |||
113 | 6 | from common.models import Topic, Version, Section | ||
114 | 7 | from apidocs.models import Namespace, Element, Page | ||
115 | 8 | from rest_framework.authtoken.models import Token | ||
116 | 9 | |||
117 | 10 | |||
118 | 11 | class TopicForm(ModelForm): | ||
119 | 12 | class Meta: | ||
120 | 13 | model = Topic | ||
121 | 14 | |||
122 | 15 | |||
123 | 16 | class VersionForm(ModelForm): | ||
124 | 17 | class Meta: | ||
125 | 18 | model = Version | ||
126 | 19 | |||
127 | 20 | |||
128 | 21 | class SectionForm(ModelForm): | ||
129 | 22 | class Meta: | ||
130 | 23 | model = Section | ||
131 | 24 | |||
132 | 25 | |||
133 | 26 | class NamespaceForm(ModelForm): | ||
134 | 27 | class Meta: | ||
135 | 28 | model = Namespace | ||
136 | 29 | |||
137 | 30 | def __init__(self, *args, **kargs): | ||
138 | 31 | if 'version' in kargs: | ||
139 | 32 | version = kargs['version'] | ||
140 | 33 | del kargs['version'] | ||
141 | 34 | elif hasattr(self, 'instance') and self.instance.section: | ||
142 | 35 | version = self.instance.section.topic_version | ||
143 | 36 | else: | ||
144 | 37 | version=None | ||
145 | 38 | super(NamespaceForm, self).__init__(*args, **kargs) | ||
146 | 39 | self.fields['platform_section'].queryset = Section.objects.filter(topic_version=version) | ||
147 | 40 | |||
148 | 41 | |||
149 | 42 | class PageForm(ModelForm): | ||
150 | 43 | class Meta: | ||
151 | 44 | model = Page | ||
152 | 45 | |||
153 | 46 | def __init__(self, *args, **kargs): | ||
154 | 47 | if 'version' in kargs: | ||
155 | 48 | version = kargs['version'] | ||
156 | 49 | del kargs['version'] | ||
157 | 50 | elif hasattr(self, 'instance') and self.instance.section: | ||
158 | 51 | version = self.instance.section.topic_version | ||
159 | 52 | else: | ||
160 | 53 | version=None | ||
161 | 54 | super(PageForm, self).__init__(*args, **kargs) | ||
162 | 55 | self.fields['section'].queryset = Section.objects.filter(topic_version=version) | ||
163 | 56 | self.fields['namespace'].queryset = Namespace.objects.filter(platform_section__topic_version=version) | ||
164 | 57 | |||
165 | 58 | |||
166 | 59 | class ElementForm(ModelForm): | ||
167 | 60 | class Meta: | ||
168 | 61 | model = Element | ||
169 | 62 | |||
170 | 63 | def __init__(self, *args, **kargs): | ||
171 | 64 | if 'version' in kargs: | ||
172 | 65 | version = kargs['version'] | ||
173 | 66 | del kargs['version'] | ||
174 | 67 | elif hasattr(self, 'instance') and self.instance.section: | ||
175 | 68 | version = self.instance.section.topic_version | ||
176 | 69 | else: | ||
177 | 70 | version=None | ||
178 | 71 | super(ElementForm, self).__init__(*args, **kargs) | ||
179 | 72 | self.fields['section'].queryset = Section.objects.filter(topic_version=version) | ||
180 | 73 | self.fields['namespace'].queryset = Namespace.objects.filter(platform_section__topic_version=version) | ||
181 | 74 | |||
182 | 75 | |||
183 | 76 | class TokenForm(ModelForm): | ||
184 | 77 | class Meta: | ||
185 | 78 | model = Token | ||
186 | 79 | fields = ('user',) | ||
187 | 80 | |||
188 | 81 | |||
189 | 82 | class UserForm(ModelForm): | ||
190 | 83 | class Meta: | ||
191 | 84 | model = User | ||
192 | 85 | fields = ('username',) | ||
193 | 0 | 86 | ||
194 | === modified file 'developer_network/web/views.py' | |||
195 | --- developer_network/web/views.py 2014-02-07 18:39:18 +0000 | |||
196 | +++ developer_network/web/views.py 2014-02-15 20:59:13 +0000 | |||
197 | @@ -1,8 +1,9 @@ | |||
198 | 1 | # -*- coding: utf-8 -*- | ||
199 | 2 | |||
200 | 1 | from django.shortcuts import render_to_response, get_object_or_404 | 3 | from django.shortcuts import render_to_response, get_object_or_404 |
202 | 2 | from django.http import HttpResponse, HttpResponseRedirect | 4 | from django.http import HttpResponseRedirect |
203 | 3 | from django.core.urlresolvers import reverse | 5 | from django.core.urlresolvers import reverse |
206 | 4 | from django.template import loader, RequestContext | 6 | from django.template import RequestContext |
205 | 5 | from django.forms import ModelForm | ||
207 | 6 | from django.contrib.auth.models import User, Group | 7 | from django.contrib.auth.models import User, Group |
208 | 7 | 8 | ||
209 | 8 | from common.models import Topic, Version, Section | 9 | from common.models import Topic, Version, Section |
210 | @@ -10,26 +11,25 @@ | |||
211 | 10 | from related.models import Snippet, Link, LINK_QUESTION, LINK_TUTORIAL | 11 | from related.models import Snippet, Link, LINK_QUESTION, LINK_TUTORIAL |
212 | 11 | from rest_framework.authtoken.models import Token | 12 | from rest_framework.authtoken.models import Token |
213 | 12 | 13 | ||
215 | 13 | # Create your views here. | 14 | from forms import * |
216 | 15 | |||
217 | 14 | def overview(request): | 16 | def overview(request): |
218 | 15 | topics = Topic.objects.all() | 17 | topics = Topic.objects.all() |
220 | 16 | 18 | ||
221 | 17 | context = { | 19 | context = { |
222 | 18 | 'topics': topics, | 20 | 'topics': topics, |
223 | 19 | } | 21 | } |
224 | 20 | return render_to_response('web/overview.html', context, RequestContext(request)) | 22 | return render_to_response('web/overview.html', context, RequestContext(request)) |
226 | 21 | 23 | ||
227 | 24 | |||
228 | 22 | def topic_view(request, topic_name): | 25 | def topic_view(request, topic_name): |
229 | 23 | topic = get_object_or_404(Topic, slug=topic_name) | 26 | topic = get_object_or_404(Topic, slug=topic_name) |
231 | 24 | 27 | ||
232 | 25 | context = { | 28 | context = { |
233 | 26 | 'topic': topic, | 29 | 'topic': topic, |
234 | 27 | } | 30 | } |
235 | 28 | return render_to_response('web/distro.html', context, RequestContext(request)) | 31 | return render_to_response('web/distro.html', context, RequestContext(request)) |
236 | 29 | 32 | ||
237 | 30 | class TopicForm(ModelForm): | ||
238 | 31 | class Meta: | ||
239 | 32 | model = Topic | ||
240 | 33 | 33 | ||
241 | 34 | def topic_edit(request, topic_id=0): | 34 | def topic_edit(request, topic_id=0): |
242 | 35 | if topic_id: | 35 | if topic_id: |
243 | @@ -53,6 +53,7 @@ | |||
244 | 53 | } | 53 | } |
245 | 54 | return render_to_response('web/topic_edit.html', context, RequestContext(request)) | 54 | return render_to_response('web/topic_edit.html', context, RequestContext(request)) |
246 | 55 | 55 | ||
247 | 56 | |||
248 | 56 | def version_view(request, topic_name, release_version): | 57 | def version_view(request, topic_name, release_version): |
249 | 57 | version = get_object_or_404(Version, topic__slug=topic_name, slug=release_version) | 58 | version = get_object_or_404(Version, topic__slug=topic_name, slug=release_version) |
250 | 58 | 59 | ||
251 | @@ -74,7 +75,7 @@ | |||
252 | 74 | else: | 75 | else: |
253 | 75 | break | 76 | break |
254 | 76 | sorted_sections.insert(i, section) | 77 | sorted_sections.insert(i, section) |
256 | 77 | 78 | ||
257 | 78 | first_column_size = 0 | 79 | first_column_size = 0 |
258 | 79 | for section in sorted_sections: | 80 | for section in sorted_sections: |
259 | 80 | section_size = section.namespace_set.count() + section.free_element_set().count() + 2 # Extra 2 for the section header | 81 | section_size = section.namespace_set.count() + section.free_element_set().count() + 2 # Extra 2 for the section header |
260 | @@ -93,9 +94,6 @@ | |||
261 | 93 | } | 94 | } |
262 | 94 | return render_to_response('web/release.html', context, RequestContext(request)) | 95 | return render_to_response('web/release.html', context, RequestContext(request)) |
263 | 95 | 96 | ||
264 | 96 | class VersionForm(ModelForm): | ||
265 | 97 | class Meta: | ||
266 | 98 | model = Version | ||
267 | 99 | 97 | ||
268 | 100 | def version_edit(request, topic_name, version_id=0): | 98 | def version_edit(request, topic_name, version_id=0): |
269 | 101 | if version_id: | 99 | if version_id: |
270 | @@ -122,9 +120,6 @@ | |||
271 | 122 | } | 120 | } |
272 | 123 | return render_to_response('web/version_edit.html', context, RequestContext(request)) | 121 | return render_to_response('web/version_edit.html', context, RequestContext(request)) |
273 | 124 | 122 | ||
274 | 125 | class SectionForm(ModelForm): | ||
275 | 126 | class Meta: | ||
276 | 127 | model = Section | ||
277 | 128 | 123 | ||
278 | 129 | def section_edit(request, topic_name, version_name, section_id=0): | 124 | def section_edit(request, topic_name, version_name, section_id=0): |
279 | 130 | if section_id: | 125 | if section_id: |
280 | @@ -153,14 +148,14 @@ | |||
281 | 153 | 'name': section.name, | 148 | 'name': section.name, |
282 | 154 | } | 149 | } |
283 | 155 | return render_to_response('web/delete_confirm.html', context, RequestContext(request)) | 150 | return render_to_response('web/delete_confirm.html', context, RequestContext(request)) |
285 | 156 | 151 | ||
286 | 157 | elif request.GET.get('action', None) == 'delete_cancel': | 152 | elif request.GET.get('action', None) == 'delete_cancel': |
287 | 158 | return HttpResponseRedirect(reverse(version_view, args=[topic_name, version_name])) | 153 | return HttpResponseRedirect(reverse(version_view, args=[topic_name, version_name])) |
289 | 159 | 154 | ||
290 | 160 | elif request.GET.get('action', None) == 'delete_confirm': | 155 | elif request.GET.get('action', None) == 'delete_confirm': |
291 | 161 | section.delete() | 156 | section.delete() |
292 | 162 | return HttpResponseRedirect(reverse(version_view, args=[topic_name, version_name])) | 157 | return HttpResponseRedirect(reverse(version_view, args=[topic_name, version_name])) |
294 | 163 | 158 | ||
295 | 164 | else: | 159 | else: |
296 | 165 | form = SectionForm(instance=section) | 160 | form = SectionForm(instance=section) |
297 | 166 | context = { | 161 | context = { |
298 | @@ -182,7 +177,7 @@ | |||
299 | 182 | links = Link.objects.filter(rendered_element=namespace) | 177 | links = Link.objects.filter(rendered_element=namespace) |
300 | 183 | questions = [link for link in links if link.link_type is LINK_QUESTION] | 178 | questions = [link for link in links if link.link_type is LINK_QUESTION] |
301 | 184 | tutorials = [link for link in links if link.link_type is LINK_TUTORIAL] | 179 | tutorials = [link for link in links if link.link_type is LINK_TUTORIAL] |
303 | 185 | 180 | ||
304 | 186 | context = { | 181 | context = { |
305 | 187 | 'sidenav': topic_name, | 182 | 'sidenav': topic_name, |
306 | 188 | 'topic': namespace.platform_section.topic_version.topic, | 183 | 'topic': namespace.platform_section.topic_version.topic, |
307 | @@ -193,21 +188,7 @@ | |||
308 | 193 | } | 188 | } |
309 | 194 | return render_to_response('web/namespace.html', context, RequestContext(request)) | 189 | return render_to_response('web/namespace.html', context, RequestContext(request)) |
310 | 195 | 190 | ||
326 | 196 | class NamespaceForm(ModelForm): | 191 | |
312 | 197 | class Meta: | ||
313 | 198 | model = Namespace | ||
314 | 199 | |||
315 | 200 | def __init__(self, *args, **kargs): | ||
316 | 201 | if 'version' in kargs: | ||
317 | 202 | version = kargs['version'] | ||
318 | 203 | del kargs['version'] | ||
319 | 204 | elif hasattr(self, 'instance') and self.instance.section: | ||
320 | 205 | version = self.instance.section.topic_version | ||
321 | 206 | else: | ||
322 | 207 | version=None | ||
323 | 208 | super(NamespaceForm, self).__init__(*args, **kargs) | ||
324 | 209 | self.fields['platform_section'].queryset = Section.objects.filter(topic_version=version) | ||
325 | 210 | |||
327 | 211 | def namespace_edit(request, topic_name, version_name, namespace_id=0): | 192 | def namespace_edit(request, topic_name, version_name, namespace_id=0): |
328 | 212 | if namespace_id: | 193 | if namespace_id: |
329 | 213 | namespace = get_object_or_404(Namespace, platform_section__topic_version__slug=version_name, platform_section__topic_version__topic__slug=topic_name, id=namespace_id) | 194 | namespace = get_object_or_404(Namespace, platform_section__topic_version__slug=version_name, platform_section__topic_version__topic__slug=topic_name, id=namespace_id) |
330 | @@ -235,14 +216,14 @@ | |||
331 | 235 | 'type': 'namespace', | 216 | 'type': 'namespace', |
332 | 236 | } | 217 | } |
333 | 237 | return render_to_response('web/delete_confirm.html', context, RequestContext(request)) | 218 | return render_to_response('web/delete_confirm.html', context, RequestContext(request)) |
335 | 238 | 219 | ||
336 | 239 | elif request.GET.get('action', None) == 'delete_cancel': | 220 | elif request.GET.get('action', None) == 'delete_cancel': |
337 | 240 | return HttpResponseRedirect(reverse(element_view, args=[topic_name, version_name, namespace.name])) | 221 | return HttpResponseRedirect(reverse(element_view, args=[topic_name, version_name, namespace.name])) |
339 | 241 | 222 | ||
340 | 242 | elif request.GET.get('action', None) == 'delete_confirm': | 223 | elif request.GET.get('action', None) == 'delete_confirm': |
341 | 243 | namespace.delete() | 224 | namespace.delete() |
342 | 244 | return HttpResponseRedirect(reverse(version_view, args=[topic_name, version_name])) | 225 | return HttpResponseRedirect(reverse(version_view, args=[topic_name, version_name])) |
344 | 245 | 226 | ||
345 | 246 | else: | 227 | else: |
346 | 247 | form = NamespaceForm(instance=namespace, version=version) | 228 | form = NamespaceForm(instance=namespace, version=version) |
347 | 248 | context = { | 229 | context = { |
348 | @@ -260,7 +241,7 @@ | |||
349 | 260 | links = Link.objects.filter(rendered_element=page) | 241 | links = Link.objects.filter(rendered_element=page) |
350 | 261 | questions = [link for link in links if link.link_type is LINK_QUESTION] | 242 | questions = [link for link in links if link.link_type is LINK_QUESTION] |
351 | 262 | tutorials = [link for link in links if link.link_type is LINK_TUTORIAL] | 243 | tutorials = [link for link in links if link.link_type is LINK_TUTORIAL] |
353 | 263 | 244 | ||
354 | 264 | context = { | 245 | context = { |
355 | 265 | 'sidenav': topic_name, | 246 | 'sidenav': topic_name, |
356 | 266 | 'topic': page.section.topic_version.topic, | 247 | 'topic': page.section.topic_version.topic, |
357 | @@ -271,22 +252,7 @@ | |||
358 | 271 | } | 252 | } |
359 | 272 | return render_to_response('web/page.html', context, RequestContext(request)) | 253 | return render_to_response('web/page.html', context, RequestContext(request)) |
360 | 273 | 254 | ||
377 | 274 | class PageForm(ModelForm): | 255 | |
362 | 275 | class Meta: | ||
363 | 276 | model = Page | ||
364 | 277 | |||
365 | 278 | def __init__(self, *args, **kargs): | ||
366 | 279 | if 'version' in kargs: | ||
367 | 280 | version = kargs['version'] | ||
368 | 281 | del kargs['version'] | ||
369 | 282 | elif hasattr(self, 'instance') and self.instance.section: | ||
370 | 283 | version = self.instance.section.topic_version | ||
371 | 284 | else: | ||
372 | 285 | version=None | ||
373 | 286 | super(PageForm, self).__init__(*args, **kargs) | ||
374 | 287 | self.fields['section'].queryset = Section.objects.filter(topic_version=version) | ||
375 | 288 | self.fields['namespace'].queryset = Namespace.objects.filter(platform_section__topic_version=version) | ||
376 | 289 | |||
378 | 290 | def page_edit(request, topic_name, release_version, page_id=0): | 256 | def page_edit(request, topic_name, release_version, page_id=0): |
379 | 291 | if page_id: | 257 | if page_id: |
380 | 292 | page = get_object_or_404(Page, section__topic_version__slug=release_version, section__topic_version__topic__slug=topic_name, id=page_id) | 258 | page = get_object_or_404(Page, section__topic_version__slug=release_version, section__topic_version__topic__slug=topic_name, id=page_id) |
381 | @@ -315,7 +281,8 @@ | |||
382 | 315 | 'page': page, | 281 | 'page': page, |
383 | 316 | } | 282 | } |
384 | 317 | return render_to_response('web/page_edit.html', context, RequestContext(request)) | 283 | return render_to_response('web/page_edit.html', context, RequestContext(request)) |
386 | 318 | 284 | ||
387 | 285 | |||
388 | 319 | def element_view(request, topic_name, release_version, element_fullname): | 286 | def element_view(request, topic_name, release_version, element_fullname): |
389 | 320 | try: | 287 | try: |
390 | 321 | element = Element.objects.get(section__topic_version__slug=release_version, section__topic_version__topic__slug=topic_name, fullname=element_fullname) | 288 | element = Element.objects.get(section__topic_version__slug=release_version, section__topic_version__topic__slug=topic_name, fullname=element_fullname) |
391 | @@ -328,7 +295,7 @@ | |||
392 | 328 | 295 | ||
393 | 329 | questions = [link for link in links if link.link_type is LINK_QUESTION] | 296 | questions = [link for link in links if link.link_type is LINK_QUESTION] |
394 | 330 | tutorials = [link for link in links if link.link_type is LINK_TUTORIAL] | 297 | tutorials = [link for link in links if link.link_type is LINK_TUTORIAL] |
396 | 331 | 298 | ||
397 | 332 | context = { | 299 | context = { |
398 | 333 | 'sidenav': topic_name, | 300 | 'sidenav': topic_name, |
399 | 334 | 'topic': element.section.topic_version.topic, | 301 | 'topic': element.section.topic_version.topic, |
400 | @@ -340,22 +307,7 @@ | |||
401 | 340 | } | 307 | } |
402 | 341 | return render_to_response('web/element.html', context, RequestContext(request)) | 308 | return render_to_response('web/element.html', context, RequestContext(request)) |
403 | 342 | 309 | ||
420 | 343 | class ElementForm(ModelForm): | 310 | |
405 | 344 | class Meta: | ||
406 | 345 | model = Element | ||
407 | 346 | |||
408 | 347 | def __init__(self, *args, **kargs): | ||
409 | 348 | if 'version' in kargs: | ||
410 | 349 | version = kargs['version'] | ||
411 | 350 | del kargs['version'] | ||
412 | 351 | elif hasattr(self, 'instance') and self.instance.section: | ||
413 | 352 | version = self.instance.section.topic_version | ||
414 | 353 | else: | ||
415 | 354 | version=None | ||
416 | 355 | super(ElementForm, self).__init__(*args, **kargs) | ||
417 | 356 | self.fields['section'].queryset = Section.objects.filter(topic_version=version) | ||
418 | 357 | self.fields['namespace'].queryset = Namespace.objects.filter(platform_section__topic_version=version) | ||
419 | 358 | |||
421 | 359 | def element_edit(request, topic_name, release_version, element_id=0): | 311 | def element_edit(request, topic_name, release_version, element_id=0): |
422 | 360 | if element_id: | 312 | if element_id: |
423 | 361 | element = get_object_or_404(Element, section__topic_version__slug=release_version, section__topic_version__topic__slug=topic_name, id=element_id) | 313 | element = get_object_or_404(Element, section__topic_version__slug=release_version, section__topic_version__topic__slug=topic_name, id=element_id) |
424 | @@ -382,14 +334,14 @@ | |||
425 | 382 | 'element': element, | 334 | 'element': element, |
426 | 383 | } | 335 | } |
427 | 384 | return render_to_response('web/delete_confirm.html', context, RequestContext(request)) | 336 | return render_to_response('web/delete_confirm.html', context, RequestContext(request)) |
429 | 385 | 337 | ||
430 | 386 | elif request.GET.get('action', None) == 'delete_cancel': | 338 | elif request.GET.get('action', None) == 'delete_cancel': |
431 | 387 | return HttpResponseRedirect(reverse(element_view, args=[topic_name, release_version, element.fullname])) | 339 | return HttpResponseRedirect(reverse(element_view, args=[topic_name, release_version, element.fullname])) |
433 | 388 | 340 | ||
434 | 389 | elif request.GET.get('action', None) == 'delete_confirm': | 341 | elif request.GET.get('action', None) == 'delete_confirm': |
435 | 390 | element.delete() | 342 | element.delete() |
436 | 391 | return HttpResponseRedirect(reverse(version_view, args=[topic_name, release_version])) | 343 | return HttpResponseRedirect(reverse(version_view, args=[topic_name, release_version])) |
438 | 392 | 344 | ||
439 | 393 | else: | 345 | else: |
440 | 394 | form = ElementForm(instance=element, version=version) | 346 | form = ElementForm(instance=element, version=version) |
441 | 395 | context = { | 347 | context = { |
442 | @@ -400,12 +352,13 @@ | |||
443 | 400 | 'element': element, | 352 | 'element': element, |
444 | 401 | } | 353 | } |
445 | 402 | return render_to_response('web/element_edit.html', context, RequestContext(request)) | 354 | return render_to_response('web/element_edit.html', context, RequestContext(request)) |
447 | 403 | 355 | ||
448 | 356 | |||
449 | 404 | def search(request, topic_name, release_version): | 357 | def search(request, topic_name, release_version): |
450 | 405 | version = get_object_or_404(Version, topic__slug=topic_name, slug=release_version) | 358 | version = get_object_or_404(Version, topic__slug=topic_name, slug=release_version) |
451 | 406 | query = request.GET.get('query', '') | 359 | query = request.GET.get('query', '') |
452 | 407 | results = Element.objects.filter(section__topic_version=version, name__icontains=query).order_by('section', 'fullname') | 360 | results = Element.objects.filter(section__topic_version=version, name__icontains=query).order_by('section', 'fullname') |
454 | 408 | 361 | ||
455 | 409 | context = { | 362 | context = { |
456 | 410 | 'sidenav': topic_name, | 363 | 'sidenav': topic_name, |
457 | 411 | 'topic': version.topic, | 364 | 'topic': version.topic, |
458 | @@ -415,15 +368,6 @@ | |||
459 | 415 | } | 368 | } |
460 | 416 | return render_to_response('web/search.html', context, RequestContext(request)) | 369 | return render_to_response('web/search.html', context, RequestContext(request)) |
461 | 417 | 370 | ||
462 | 418 | class TokenForm(ModelForm): | ||
463 | 419 | class Meta: | ||
464 | 420 | model = Token | ||
465 | 421 | fields = ('user',) | ||
466 | 422 | |||
467 | 423 | class UserForm(ModelForm): | ||
468 | 424 | class Meta: | ||
469 | 425 | model = User | ||
470 | 426 | fields = ('username',) | ||
471 | 427 | 371 | ||
472 | 428 | def token_edit(request, token_key=None): | 372 | def token_edit(request, token_key=None): |
473 | 429 | if token_key: | 373 | if token_key: |
474 | @@ -468,4 +412,3 @@ | |||
475 | 468 | 'tokens': tokens, | 412 | 'tokens': tokens, |
476 | 469 | } | 413 | } |
477 | 470 | return render_to_response('web/token_edit.html', context, RequestContext(request)) | 414 | return render_to_response('web/token_edit.html', context, RequestContext(request)) |
478 | 471 |