annotate bts_webui/amancay/toolbox.py @ 26:23ce17c621f7 draft

Tidied up. Fixed some small bugs
author marga
date Tue, 21 Aug 2007 15:36:11 +0000
parents 026d1bcf0746
children 47474c0d98a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
1 import datetime
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
2
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
3 # Needed to get_template, prepare context and output Response
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
4 from django.template import Context, loader
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
5 from django.http import HttpResponse, HttpResponseRedirect
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
6
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
7 # Shortcut for rendering a response
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
8 from django.shortcuts import get_object_or_404, render_to_response
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
9
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
10 # Model clases
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
11 from django.contrib.auth.models import User
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
12 from bts_webui.amancay.models import Package, Bug, SubmitterEmail, MaintainerEmail, UserEmail
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
13
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
14 # Needed for AJAX
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
15 from django.utils import simplejson
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
16
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
17 def render_toolbox(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
18 toolbox = get_toolbox(request)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
19 return render_to_response('toolbox.html',
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
20 {'toolbox': toolbox}
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
21 )
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
22
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
23 def get_toolbox(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
24
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
25 # Initialization
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
26 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
27 toolbox = {}
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
28
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
29 # Fill the info according to the type of toolbox needed
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
30 if (request.path.find("submitted_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
31 toolbox["title"] = "Submitter emails"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
32 toolbox["item_type"] = "submitter_email"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
33 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
34 email_list = request.user.submitteremail_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
35 toolbox["item_list"] = [ e.address for e in email_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
36 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
37 toolbox["item_list"] = request.session.get('submitter_emails')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
38
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
39 # Received bugs
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
40 elif (request.path.find("received_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
41 toolbox["title"] = "Maintainer emails"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
42 toolbox["item_type"] = "maintainer_email"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
43 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
44 email_list = request.user.maintaineremail_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
45 toolbox["item_list"] = [ e.address for e in email_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
46 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
47 toolbox["item_list"] = request.session.get('maintainer_emails')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
48
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
49 # Selected Packages
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
50 elif (request.path.find("package_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
51 toolbox["title"] = "Selected Packages"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
52 toolbox["item_type"] = "package"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
53 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
54 package_list = request.user.package_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
55 toolbox["item_list"] = [ p.package_name for p in package_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
56 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
57 toolbox["item_list"] = request.session.get('packages')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
58
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
59 # Selected bugs
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
60 elif (request.path.find("selected_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
61 toolbox["title"] = "Selected Bugs"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
62 toolbox["item_type"] = "bug"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
63 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
64 bug_list = request.user.bug_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
65 toolbox["item_list"] = [b.number for b in bug_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
66 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
67 toolbox["item_list"] = request.session.get('bugs')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
68
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
69 # Tagged bugs
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
70 elif (request.path.find("tagged_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
71 toolbox["title"] = "User emails"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
72 toolbox["item_type"] = "user_email"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
73 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
74 email_list = request.user.useremail_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
75 toolbox["item_list"] = [ e.address for e in email_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
76 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
77 toolbox["item_list"] = request.session.get('user_emails')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
78
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
79 # Done
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
80 return toolbox
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
81
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
82
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
83 def add_package(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
84 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
85 package_name = request.POST['package_name']
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
86 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
87 packages = user.package_set.filter(package_name=package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
88 if (len(packages) == 0):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
89 user.package_set.create(package_name=package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
90 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
91 packages = request.session.get('packages')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
92 if (packages == None):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
93 packages = request.session['packages'] = []
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
94 for package in packages:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
95 if (package == package_name):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
96 return
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
97 request.session['packages'].append(package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
98
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
99 def remove_packages(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
100 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
101 package_selected = request.POST.getlist("package_select")
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
102 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
103 for package_name in package_selected:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
104 packages = user.package_set.filter(package_name=package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
105 if (len(packages) != 0):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
106 packages[0].delete()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
107 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
108 packages = request.session.get('packages')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
109 if (packages == None):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
110 packages = request.session['packages'] = []
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
111 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
112 for package_name in package_selected:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
113 for package in packages:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
114 if (package == package_name):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
115 request.session['packages'].remove(package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
116
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
117 def add_bug(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
118 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
119 bug_number = request.POST['bug_number']
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
120 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
121 bugs = user.bug_set.filter(number=bug_number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
122 if (len(bugs) == 0):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
123 user.bug_set.create(number=bug_number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
124 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
125 bugs = request.session.get('bugs')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
126 if (bugs == None):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
127 bugs = request.session['bugs'] = []
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
128 for bug in bugs:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
129 if (bug == bug_number):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
130 return
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
131 request.session['bugs'].append(bug_number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
132
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
133 def remove_bugs(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
134 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
135 bug_selected = request.POST.getlist("bug_select")
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
136 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
137 for number in bug_selected:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
138 bugs = user.bug_set.filter(number=number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
139 if (len(bugs) != 0):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
140 bugs[0].delete()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
141 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
142 bugs = request.session.get('bugs')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
143 if (bugs == None):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
144 bugs = request.session['bugs'] = []
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
145 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
146 for bug_number in bug_selected:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
147 for bug in bugs:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
148 if (bug == bug_number):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
149 request.session['bugs'].remove(bug_number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
150
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
151 # Package page
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
152
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
153 def package(request, package_name):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
154 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
155 queries = soap_queries()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
156
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
157 bugs = queries.get_packages_bugs(package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
158 bugs.sort(reverse=True)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
159 bug_list = queries.get_bugs_status(bugs)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
160
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
161 # Check if it's AJAX or HTML
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
162 if (request.GET.has_key('xhr')):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
163 return HttpResponse( simplejson.dumps({"package":
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
164 package_name, "bug_list": bug_list}),
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
165 mimetype='application/javascript' )
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
166 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
167 return render_to_response('package.html',
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
168 {'package': package_name,
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
169 'bug_list': bug_list,
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
170 'current_user': user}
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
171 )
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
172