annotate bts_webui/amancay/toolbox.py @ 3:026d1bcf0746 draft

The migration to the new interface is almost done
author marga
date Mon, 09 Jul 2007 21:47:39 +0000
parents
children 23ce17c621f7
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 print user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
28 toolbox = {}
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
29
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
30 # Fill the info according to the type of toolbox needed
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
31 if (request.path.find("submitted_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
32 toolbox["title"] = "Submitter emails"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
33 toolbox["item_type"] = "submitter_email"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
34 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
35 email_list = request.user.submitteremail_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
36 toolbox["item_list"] = [ e.address for e in email_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
37 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
38 toolbox["item_list"] = request.session.get('submitter_emails')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
39
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
40 # Received bugs
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
41 elif (request.path.find("received_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
42 toolbox["title"] = "Maintainer emails"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
43 toolbox["item_type"] = "maintainer_email"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
44 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
45 email_list = request.user.maintaineremail_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
46 toolbox["item_list"] = [ e.address for e in email_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
47 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
48 toolbox["item_list"] = request.session.get('maintainer_emails')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
49
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
50 # Selected Packages
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
51 elif (request.path.find("package_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
52 toolbox["title"] = "Selected Packages"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
53 toolbox["item_type"] = "package"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
54 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
55 package_list = request.user.package_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
56 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
57 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
58 toolbox["item_list"] = request.session.get('packages')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
59
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
60 # Selected bugs
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
61 elif (request.path.find("selected_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
62 toolbox["title"] = "Selected Bugs"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
63 toolbox["item_type"] = "bug"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
64 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
65 bug_list = request.user.bug_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
66 toolbox["item_list"] = [b.number for b in bug_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
67 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
68 toolbox["item_list"] = request.session.get('bugs')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
69
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
70 # Tagged bugs
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
71 elif (request.path.find("tagged_bugs") != -1):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
72 toolbox["title"] = "User emails"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
73 toolbox["item_type"] = "user_email"
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
74 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
75 email_list = request.user.useremail_set.all()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
76 toolbox["item_list"] = [ e.address for e in email_list]
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
77 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
78 toolbox["item_list"] = request.session.get('user_emails')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
79
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
80 # Done
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
81 return toolbox
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
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
84 def add_package(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
85 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
86 package_name = request.POST['package_name']
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
87 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
88 packages = user.package_set.filter(package_name=package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
89 if (len(packages) == 0):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
90 user.package_set.create(package_name=package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
91 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
92 packages = request.session.get('packages')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
93 if (packages == None):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
94 packages = request.session['packages'] = []
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
95 for package in packages:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
96 if (package == package_name):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
97 return
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
98 request.session['packages'].append(package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
99
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
100 def remove_packages(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
101 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
102 package_selected = request.POST.getlist("package_select")
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
103 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
104 for package_name in package_selected:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
105 packages = user.package_set.filter(package_name=package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
106 if (len(packages) != 0):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
107 packages[0].delete()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
108 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
109 packages = request.session.get('packages')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
110 if (packages == None):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
111 packages = request.session['packages'] = []
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
112 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
113 for package_name in package_selected:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
114 for package in packages:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
115 if (package == package_name):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
116 request.session['packages'].remove(package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
117
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
118 def add_bug(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
119 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
120 bug_number = request.POST['bug_number']
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
121 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
122 bugs = user.bug_set.filter(number=bug_number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
123 if (len(bugs) == 0):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
124 user.bug_set.create(number=bug_number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
125 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
126 bugs = request.session.get('bugs')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
127 if (bugs == None):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
128 bugs = request.session['bugs'] = []
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
129 for bug in bugs:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
130 if (bug == bug_number):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
131 return
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
132 request.session['bugs'].append(bug_number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
133
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
134 def remove_bugs(request):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
135 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
136 bug_selected = request.POST.getlist("bug_select")
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
137 if (user.is_authenticated()):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
138 for number in bug_selected:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
139 bugs = user.bug_set.filter(number=number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
140 if (len(bugs) != 0):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
141 bugs[0].delete()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
142 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
143 bugs = request.session.get('bugs')
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
144 if (bugs == None):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
145 bugs = request.session['bugs'] = []
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
146 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
147 for bug_number in bug_selected:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
148 for bug in bugs:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
149 if (bug == bug_number):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
150 request.session['bugs'].remove(bug_number)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
151
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
152 # Package page
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
153
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
154 def package(request, package_name):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
155 user = request.user
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
156 queries = soap_queries()
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
157
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
158 bugs = queries.get_packages_bugs(package_name)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
159 bugs.sort(reverse=True)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
160 bug_list = queries.get_bugs_status(bugs)
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
161
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
162 # Check if it's AJAX or HTML
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
163 if (request.GET.has_key('xhr')):
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
164 return HttpResponse( simplejson.dumps({"package":
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
165 package_name, "bug_list": bug_list}),
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
166 mimetype='application/javascript' )
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
167 else:
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
168 return render_to_response('package.html',
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
169 {'package': package_name,
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
170 'bug_list': bug_list,
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
171 'current_user': user}
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
172 )
026d1bcf0746 The migration to the new interface is almost done
marga
parents:
diff changeset
173