Merge lp:~toabctl/loco-team-portal/simplify_team_code into lp:~ltp-devs/loco-team-portal/trunk
- simplify_team_code
- Merge into trunk
Proposed by
Thomas Bechtold
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~toabctl/loco-team-portal/simplify_team_code |
Merge into: | lp:~ltp-devs/loco-team-portal/trunk |
Diff against target: |
373 lines (+87/-93) 12 files modified
loco_directory/teams/forms.py (+4/-24) loco_directory/teams/models.py (+1/-6) loco_directory/teams/tests.py (+43/-0) loco_directory/teams/urls.py (+3/-3) loco_directory/teams/views.py (+25/-38) loco_directory/templates/500.html (+1/-1) loco_directory/templates/about.html (+2/-2) loco_directory/templates/index.html (+1/-1) loco_directory/templates/teams/team_detail.html (+4/-7) loco_directory/templates/teams/team_list.html (+2/-2) loco_directory/templates/teams/team_reapprovals.html (+1/-1) loco_directory/templates/teams/team_update.html (+0/-8) |
To merge this branch: | bzr merge lp:~toabctl/loco-team-portal/simplify_team_code |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Holbach (community) | Approve | ||
Review via email: mp+16383@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Thomas Bechtold (toabctl) wrote : | # |
- 123. By Thomas Bechtold
-
remove unecessary teammanager method
- 124. By Thomas Bechtold
-
use more django-like url names and functions names
- 125. By Thomas Bechtold
-
fix url in index.html
- 126. By Thomas Bechtold
-
fix url in team_detail.html
- 127. By Thomas Bechtold
-
use {% url %} istead of get_absolute_url
- 128. By Thomas Bechtold
-
use {% url %} istead of get_absolute_url
- 129. By Thomas Bechtold
-
fix {% url %} and reverse() bugs because of new url names
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'loco_directory/teams/forms.py' |
2 | --- loco_directory/teams/forms.py 2009-11-18 22:56:44 +0000 |
3 | +++ loco_directory/teams/forms.py 2009-12-21 09:39:15 +0000 |
4 | @@ -4,32 +4,12 @@ |
5 | |
6 | from models import Team |
7 | |
8 | -class TeamForm(forms.ModelForm): |
9 | - def __init__(self, *args, **kwargs): |
10 | - super(TeamForm, self).__init__(*args, **kwargs) |
11 | - |
12 | - team = self.instance |
13 | - self.fields['country'].initial = team.country |
14 | - if self.fields['country'] == "United States": |
15 | - from django.contrib.localflavor.us.us_states import STATE_CHOICES |
16 | - self.fields['spr'].choices = STATE_CHOICES |
17 | - self.fields['spr'].initial = team.spr |
18 | - self.fields['city'].initial = team.city |
19 | - self.fields['wiki_url'].initial = team.wiki_url |
20 | - self.fields['web_url'].initial = team.web_url |
21 | - self.fields['ml_url'].initial = team.ml_url |
22 | - self.fields['forum_url'].initial = team.forum_url |
23 | - self.fields['email'].initial = team.email |
24 | - self.fields['irc_chan'].initial = team.irc_chan |
25 | - self.fields['provides_support'].initial = team.provides_support |
26 | - |
27 | +class UpdateTeamForm(forms.ModelForm): |
28 | class Meta: |
29 | model = Team |
30 | - |
31 | -class UpdateTeamForm(TeamForm): |
32 | - class Meta(TeamForm.Meta): |
33 | exclude = ('approved_date', 'approved', 'expires_date', 'name', 'lp_name', 'admins', 'owner') |
34 | |
35 | -class LoCoCouncilForm(TeamForm): |
36 | - class Meta(TeamForm.Meta): |
37 | +class LoCoCouncilForm(forms.ModelForm): |
38 | + class Meta: |
39 | + model = Team |
40 | exclude = ('approved', 'expires_date', 'name', 'lp_name', 'admins', 'owner') |
41 | |
42 | === modified file 'loco_directory/teams/models.py' |
43 | --- loco_directory/teams/models.py 2009-12-11 13:47:44 +0000 |
44 | +++ loco_directory/teams/models.py 2009-12-21 09:39:15 +0000 |
45 | @@ -2,9 +2,7 @@ |
46 | from django.utils.translation import ugettext as _ |
47 | |
48 | class TeamManager(models.Manager): |
49 | - def all_teams(self): |
50 | - teams = self.all() |
51 | - return teams |
52 | + pass |
53 | |
54 | class TeamAdministrator(models.Model): |
55 | lpid = models.SlugField(_("Launchpad ID"), max_length=40, null=False, blank=False) |
56 | @@ -43,6 +41,3 @@ |
57 | def __unicode__(self): |
58 | return self.lp_name |
59 | |
60 | - @models.permalink |
61 | - def get_absolute_url(self): |
62 | - return ('team_slug', [self.lp_name]) |
63 | |
64 | === modified file 'loco_directory/teams/tests.py' |
65 | --- loco_directory/teams/tests.py 2009-11-12 09:13:44 +0000 |
66 | +++ loco_directory/teams/tests.py 2009-12-21 09:39:15 +0000 |
67 | @@ -3,6 +3,9 @@ |
68 | from teams.models import * |
69 | from common import launchpad |
70 | |
71 | +from django.core.urlresolvers import reverse |
72 | + |
73 | + |
74 | class LoCoCouncilACLTestCase(TestCase): |
75 | def testACLs(self): |
76 | """Test if LoCo Council check works |
77 | @@ -26,3 +29,43 @@ |
78 | venezuela = teams.filter(lp_name="ubuntu-ve")[0] |
79 | self.assertEquals(launchpad.is_admin_or_owner("effie-jayx", venezuela), True) |
80 | self.assertEquals(launchpad.is_admin_or_owner("jorge", venezuela), False) |
81 | + |
82 | +class EditTeamTestCase(TestCase): |
83 | + """ |
84 | + test if team update works correct |
85 | + """ |
86 | + def test_anonymous_user(self): |
87 | + """ |
88 | + test the team update as anonymous user (not logged in) |
89 | + """ |
90 | + #try to access team-update page as not logged in user |
91 | + response = self.client.get(reverse( 'team-edit', args=['ubuntu-de-locoteam'] ), follow=True) |
92 | + self.assertRedirects(response, '/openid/login?next=/teams/ubuntu-de-locoteam/edit', status_code=302, target_status_code=200) |
93 | + #try to update team as not logged in user |
94 | + response = self.client.post(reverse('team-edit', args=['ubuntu-de-locoteam']), {'Country':'Germany', 'forum_url':'http://ubuntuusers.de', }) |
95 | + self.assertRedirects(response, '/openid/login?next=/teams/ubuntu-de-locoteam/edit', status_code=302, target_status_code=200) |
96 | + |
97 | + def test_user_with_no_rights(self): |
98 | + """ |
99 | + test the team update with a user which has no rights |
100 | + """ |
101 | + pass |
102 | + #FIXME How to use a user with no right with openid? |
103 | + |
104 | + def test_user_loco_council(self): |
105 | + """ |
106 | + test the team update with a user which is a member of loco council |
107 | + """ |
108 | + pass |
109 | + #FIXME How to use a user with this rights with openid? |
110 | + |
111 | + def test_user_admin_or_owner(self): |
112 | + """ |
113 | + test the team update with a user which is owner or admin |
114 | + """ |
115 | + pass |
116 | + #FIXME How to use a user with this rights with openid? |
117 | + |
118 | + |
119 | + |
120 | + |
121 | |
122 | === modified file 'loco_directory/teams/urls.py' |
123 | --- loco_directory/teams/urls.py 2009-12-04 08:51:48 +0000 |
124 | +++ loco_directory/teams/urls.py 2009-12-21 09:39:15 +0000 |
125 | @@ -1,8 +1,8 @@ |
126 | from django.conf.urls.defaults import * |
127 | |
128 | urlpatterns = patterns('', |
129 | - url(r'^$', 'teams.views.teams', name='teams'), |
130 | + url(r'^$', 'teams.views.team_list', name='team-list'), |
131 | url(r'reapprovals', 'teams.views.reapprovals'), |
132 | - url(r'(?P<teamedit_slug>[a-zA-Z0-9\-\.\+?]+)/edit$', 'teams.views.team_edit', name='team_editslug'), |
133 | - url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)$', 'teams.views.team', name='team_slug'), |
134 | + url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)/edit$', 'teams.views.team_edit', name='team-edit'), |
135 | + url(r'(?P<team_slug>[a-zA-Z0-9\-\.\+?]+)$', 'teams.views.team_detail', name='team-detail'), |
136 | ) |
137 | |
138 | === modified file 'loco_directory/teams/views.py' |
139 | --- loco_directory/teams/views.py 2009-12-13 13:58:03 +0000 |
140 | +++ loco_directory/teams/views.py 2009-12-21 09:39:15 +0000 |
141 | @@ -4,6 +4,10 @@ |
142 | from django.utils.translation import ugettext as _ |
143 | from django.core import serializers |
144 | |
145 | +from django.contrib.auth.decorators import login_required |
146 | +from django.core.urlresolvers import reverse |
147 | +from django.http import HttpResponseRedirect |
148 | + |
149 | from django.shortcuts import get_object_or_404 |
150 | |
151 | from django import http |
152 | @@ -18,7 +22,7 @@ |
153 | import forms |
154 | |
155 | def reapprovals(request): |
156 | - teams = Team.objects.all_teams().order_by('expires_date') |
157 | + teams = Team.objects.all().order_by('expires_date') |
158 | approved_teams = filter(lambda a: a.approved, teams) |
159 | context = { |
160 | 'approved_teams': approved_teams, |
161 | @@ -26,8 +30,8 @@ |
162 | return common.views.versioned_render('teams/team_reapprovals.html', |
163 | context, RequestContext(request)) |
164 | |
165 | -def teams(request): |
166 | - teams = Team.objects.all_teams() |
167 | +def team_list(request): |
168 | + teams = Team.objects.all() |
169 | context = { |
170 | 'pageSection': 'teams', |
171 | 'teams': utils.trans_sort_object_list(teams, 'name'), |
172 | @@ -35,7 +39,7 @@ |
173 | return common.views.versioned_render('teams/team_list.html', context, |
174 | RequestContext(request)) |
175 | |
176 | -def team(request, team_slug): |
177 | +def team_detail(request, team_slug): |
178 | team_object = get_object_or_404(Team, lp_name=team_slug) |
179 | context = { |
180 | 'pageSection': 'teams', |
181 | @@ -45,57 +49,40 @@ |
182 | context, RequestContext(request)) |
183 | |
184 | |
185 | -def team_edit(request, teamedit_slug): |
186 | - try: |
187 | - team_object = Team.objects.get(lp_name=teamedit_slug) |
188 | - except: |
189 | - raise Team.DoesNotExist, "%s" % teamedit_slug |
190 | +@login_required |
191 | +def team_edit(request, team_slug): |
192 | + #get team |
193 | + team_object = get_object_or_404(Team, lp_name=team_slug) |
194 | + |
195 | context = { |
196 | 'pageSection': 'teams', |
197 | 'team': team_object, |
198 | } |
199 | -# import logging |
200 | -# logging.basicConfig(level = logging.DEBUG, |
201 | -# format = '%(asctime)s %(levelname)s %(message)s', |
202 | -# filename = '/tmp/loco-directory.log', |
203 | -# filemode = 'a') |
204 | -# logging.debug("%s %s" % (teamedit_slug, request.user)) |
205 | - if type(request.user) == AnonymousUser: |
206 | - context["failure_message"] = _("You are not logged in.") |
207 | -# logging.debug("%s %s, not logged in" % (teamedit_slug, request.user)) |
208 | - return common.views.versioned_render('teams/team_detail.html', |
209 | - context, RequestContext(request)) |
210 | + |
211 | + #check if user has needed rights |
212 | is_on_lc = launchpad.is_user_on_loco_council(request.user.username) |
213 | is_contact = launchpad.is_admin_or_owner(request.user.username, team_object) |
214 | -# logging.debug("%s %s - LC: %s, Contact: %s" % (teamedit_slug, request.user, str(is_on_lc), str(is_contact))) |
215 | if not is_on_lc and not is_contact: |
216 | - context["failure_message"] = \ |
217 | - _("You are not allowed to make changes to the team details.") |
218 | -# logging.debug("%s %s - LC: %s, Contact: %s, not allowed" % (teamedit_slug, request.user, str(is_on_lc), str(is_contact))) |
219 | - return common.views.versioned_render('teams/team_detail.html', |
220 | - context, RequestContext(request)) |
221 | + request.user.message_set.create(message=_('You are not allowed to make changes to the team details.')) |
222 | + return HttpResponseRedirect( reverse( 'team-detail', args=[team_slug] ) ) |
223 | |
224 | if request.method == "POST": |
225 | -# logging.debug("%s %s - LC: %s, Contact: %s, POSTING" % (teamedit_slug, request.user, str(is_on_lc), str(is_contact))) |
226 | if is_on_lc: |
227 | form = forms.LoCoCouncilForm(data=request.POST, instance=team_object) |
228 | else: |
229 | form = forms.UpdateTeamForm(data=request.POST, instance=team_object) |
230 | if form.is_valid(): |
231 | form.save() |
232 | - message = _("Team details updated.") |
233 | + request.user.message_set.create(message=_('Team details updated')) |
234 | + return HttpResponseRedirect( reverse( 'team-detail', args=[team_slug] ) ) |
235 | else: |
236 | - message = _("Team details could not be saved.") |
237 | - return common.views.versioned_render('teams/team_update.html', |
238 | - {'form': form, |
239 | - 'team':team_object, |
240 | - 'user':request.user, |
241 | - 'message':message }) |
242 | - if is_on_lc: |
243 | - form = forms.LoCoCouncilForm(instance=team_object) |
244 | + request.user.message_set.create(message=_('Team details could not be saved.')) |
245 | else: |
246 | - form = forms.UpdateTeamForm(instance=team_object) |
247 | -# logging.debug("%s %s - LC: %s, Contact: %s, normal view" % (teamedit_slug, request.user, str(is_on_lc), str(is_contact))) |
248 | + if is_on_lc: |
249 | + form = forms.LoCoCouncilForm(instance=team_object) |
250 | + else: |
251 | + form = forms.UpdateTeamForm(instance=team_object) |
252 | + |
253 | return common.views.versioned_render('teams/team_update.html', |
254 | {'form': form, |
255 | 'team':team_object, |
256 | |
257 | === modified file 'loco_directory/templates/500.html' |
258 | --- loco_directory/templates/500.html 2009-11-17 17:35:48 +0000 |
259 | +++ loco_directory/templates/500.html 2009-12-21 09:39:15 +0000 |
260 | @@ -11,7 +11,7 @@ |
261 | |
262 | |
263 | <div class="main"> |
264 | - <h2><a href="{% url teams %}">{% trans "You can browse the full list of teams" noop %}</a></h2> |
265 | + <h2><a href="{% url team-list %}">{% trans "You can browse the full list of teams" noop %}</a></h2> |
266 | <p>{% trans "Please make sure the team you are looking for is a member of" noop %} <a href='https://launchpad.net/~locoteams'>{% trans "The LoCo Teams group in Launchpad" noop %}</a> |
267 | <p>{% trans "If you believe the reason you are here is an bug in the LoCo Directory please " noop %} <a href='https://bugs.launchpad.net/loco-directory'>{% trans "Report it!" noop %}</a> |
268 | </p> |
269 | |
270 | === modified file 'loco_directory/templates/about.html' |
271 | --- loco_directory/templates/about.html 2009-11-09 11:59:53 +0000 |
272 | +++ loco_directory/templates/about.html 2009-12-21 09:39:15 +0000 |
273 | @@ -11,7 +11,7 @@ |
274 | |
275 | |
276 | <div class="main"> |
277 | - <h2><a href="{% url teams %}">{% trans "What is the LoCo Directory?" noop %}</a></h2> |
278 | + <h2><a href="{% url team-list %}">{% trans "What is the LoCo Directory?" noop %}</a></h2> |
279 | <p>{% trans "The LoCo Directory is a place where you can find information regarding LoCo Teams. It was originally developed by <a href='https://launchpad.net/~nixternal'>Richard Johnson</a> and further development has been made possible by the <a href='https://launchpad.net/~loco-directory-dev'>The LoCo Directory Developers</a>." noop %} |
280 | {% trans "The LoCo Directory is made available under the <a href='http://www.gnu.org/licenses/gpl-3.0-standalone.html'>GNU GPL v3</a>." noop %} |
281 | </p> |
282 | @@ -20,7 +20,7 @@ |
283 | <div id="container2"> |
284 | <div id="left"> |
285 | |
286 | -<h2><a href="{% url teams %}">{% trans "The Directory Data" noop %}</a></h2> |
287 | +<h2><a href="{% url team-list %}">{% trans "The Directory Data" noop %}</a></h2> |
288 | <p>{% trans "The LoCo Directory comes from two sources, <a href='https://launchpad.net/'>Launchpad</a> and its <a href='https://help.launchpad.net/API/launchpadlib'>APIs</a>. The data that the LoCo Directory gathers is also made available as <a href='/data/xml'>XML</a> format to interoperate with other web apps and for possible mashups." noop %} |
289 | {% trans "The LoCo Directory is made available under the <a href='http://www.gnu.org/licenses/gpl-3.0-standalone.html'>GNU GPL v3</a> and the Code is available in <a href='https://code.launchpad.net/loco-directory'>Launchpad Code Hosting</a>." noop %} |
290 | </p> |
291 | |
292 | === modified file 'loco_directory/templates/index.html' |
293 | --- loco_directory/templates/index.html 2009-04-03 08:18:07 +0000 |
294 | +++ loco_directory/templates/index.html 2009-12-21 09:39:15 +0000 |
295 | @@ -11,7 +11,7 @@ |
296 | |
297 | <table><tr><td width="50%" valign="top"> |
298 | |
299 | -<h2><a href="{% url teams %}">{% trans "Teams" %}</a></h2> |
300 | +<h2><a href="{% url team-list %}">{% trans "Teams" %}</a></h2> |
301 | <p>{% trans "List of all Ubuntu LoCo Teams, with full information such as contact, web pages, mailing list, and more." %} |
302 | {% trans "If there are no teams in your country/region/area, you will be able to add a team in the near future." %} |
303 | </p> |
304 | |
305 | === modified file 'loco_directory/templates/teams/team_detail.html' |
306 | --- loco_directory/templates/teams/team_detail.html 2009-12-10 11:31:14 +0000 |
307 | +++ loco_directory/templates/teams/team_detail.html 2009-12-21 09:39:15 +0000 |
308 | @@ -5,13 +5,10 @@ |
309 | |
310 | {% block content %} |
311 | <div class="team_detail"> |
312 | -{% if failure_message %} |
313 | -<p> |
314 | - <b><font color="red">{{ failure_message }}</font></b> |
315 | -</p> |
316 | -{% endif %} |
317 | -<p><b><a href="/teams">{% trans "Go back to Team list." %}</a></b></p> |
318 | -<p><b><a href="/teams/{{ team.lp_name }}/edit">{% trans "Edit team details." %}</a></b></p> |
319 | + <p><b><a href="{% url team-list %}">{% trans "Go back to Team list." %}</a></b></p> |
320 | + {% if user.is_authenticated %} |
321 | + <p><b><a href="{% url team-edit team.lp_name %}">{% trans "Edit team details." %}</a></b></p> |
322 | + {% endif %} |
323 | <h2><a href="https://launchpad.net/~{{ team.lp_name }}">{% trans team.name %}</a></h2> |
324 | <table cellpadding="0" cellspacing="0"> |
325 | <tr><th colspan="2">{% trans "Location Information" %}</th></tr> |
326 | |
327 | === modified file 'loco_directory/templates/teams/team_list.html' |
328 | --- loco_directory/templates/teams/team_list.html 2009-06-24 09:29:09 +0000 |
329 | +++ loco_directory/templates/teams/team_list.html 2009-12-21 09:39:15 +0000 |
330 | @@ -22,9 +22,9 @@ |
331 | <ul> |
332 | {% for team in column %} |
333 | {% if team.approved %} |
334 | -<li class="approved"><a href="{{ team.get_absolute_url }}">{{ team.translated_name }}</a></li> |
335 | +<li class="approved"><a href="{% url team-detail team.lp_name %}">{{ team.translated_name }}</a></li> |
336 | {% else %} |
337 | -<li class="unapproved"><a href="{{ team.get_absolute_url }}">{{ team.translated_name }}</a></li> |
338 | +<li class="unapproved"><a href="{% url team-detail team.lp_name %}">{{ team.translated_name }}</a></li> |
339 | {% endif %} |
340 | {% endfor %} |
341 | </ul> |
342 | |
343 | === modified file 'loco_directory/templates/teams/team_reapprovals.html' |
344 | --- loco_directory/templates/teams/team_reapprovals.html 2009-06-24 09:29:09 +0000 |
345 | +++ loco_directory/templates/teams/team_reapprovals.html 2009-12-21 09:39:15 +0000 |
346 | @@ -14,7 +14,7 @@ |
347 | <td width="100%" valign="top" class="col2_container"> |
348 | <ul> |
349 | {% for team in approved_teams %} |
350 | -<li class="approved"><a href="{{ team.get_absolute_url }}">{{ team.name }}</a>: {{ team.expires_date }}</li> |
351 | +<li class="approved"><a href="{% url team-detail team.lp_name %}">{{ team.name }}</a>: {{ team.expires_date }}</li> |
352 | {% endfor %} |
353 | </ul> |
354 | </td> |
355 | |
356 | === modified file 'loco_directory/templates/teams/team_update.html' |
357 | --- loco_directory/templates/teams/team_update.html 2009-12-10 09:12:23 +0000 |
358 | +++ loco_directory/templates/teams/team_update.html 2009-12-21 09:39:15 +0000 |
359 | @@ -7,14 +7,6 @@ |
360 | |
361 | <p><b><a href="/teams">{% trans "Go back to Team list." %}</a></b></p> |
362 | <p><b><a href="/teams/{{ team.lp_name }}">{% trans "Go back to team details." %}</a></b></p> |
363 | -<div id="form"> |
364 | - {% if message %} |
365 | - <div class="box"> |
366 | - {{ message }} |
367 | - <img src="/media/img/delete.png" alt="delete" class="delete" /> |
368 | - </div> |
369 | - {% endif %} |
370 | - </div> |
371 | <div id="form"> |
372 | {% if form.errors %} |
373 | <p style="color: red;"> |
This branch should simplify the team code.
* simplify team forms
* use django message system
* use django login decorator
* add initial unittest for team update
* use {% url %} in templates and revert() in views