| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | import vouchers.models |
|---|
| 3 | from vouchers.models import ReimbursementRequest, Documentation |
|---|
| 4 | from finance_core.models import BudgetTerm, BudgetArea |
|---|
| 5 | from util.shortcuts import get_403_response |
|---|
| 6 | |
|---|
| 7 | from django.contrib.auth.decorators import user_passes_test, login_required |
|---|
| 8 | from django.shortcuts import render_to_response, get_object_or_404 |
|---|
| 9 | from django.template import RequestContext |
|---|
| 10 | from django.http import Http404, HttpResponseRedirect |
|---|
| 11 | import django.forms |
|---|
| 12 | from django.forms import ChoiceField, Form, ModelForm, ModelChoiceField |
|---|
| 13 | from django.core.urlresolvers import reverse |
|---|
| 14 | from django.core.mail import send_mail, mail_admins |
|---|
| 15 | from django.db.models import Q |
|---|
| 16 | from django.template import Context, Template |
|---|
| 17 | from django.template.loader import get_template |
|---|
| 18 | |
|---|
| 19 | import decimal |
|---|
| 20 | |
|---|
| 21 | import settings |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | class CommitteesField(ModelChoiceField): |
|---|
| 25 | def __init__(self, *args, **kargs): |
|---|
| 26 | base_area = BudgetArea.get_by_path(settings.BASE_COMMITTEE_PATH) |
|---|
| 27 | self.strip_levels = base_area.depth |
|---|
| 28 | areas = (base_area.get_descendants() |
|---|
| 29 | .filter(depth__lte=base_area.depth+settings.COMMITTEE_HIERARCHY_LEVELS) |
|---|
| 30 | .exclude(name='Holding') |
|---|
| 31 | ) |
|---|
| 32 | ModelChoiceField.__init__(self, queryset=areas, |
|---|
| 33 | help_text='Select the appropriate committe or other budget area', |
|---|
| 34 | *args, **kargs) |
|---|
| 35 | |
|---|
| 36 | def label_from_instance(self, obj,): |
|---|
| 37 | return obj.indented_name(strip_levels=self.strip_levels) |
|---|
| 38 | |
|---|
| 39 | class SelectRequestBasicsForm(Form): |
|---|
| 40 | area = CommitteesField() |
|---|
| 41 | term = ModelChoiceField(queryset = BudgetTerm.objects.all()) |
|---|
| 42 | recipient_type = ChoiceField(choices=vouchers.models.recipient_type_choices) |
|---|
| 43 | |
|---|
| 44 | class DocUploadForm(ModelForm): |
|---|
| 45 | def clean_backing_file(self, ): |
|---|
| 46 | f = self.cleaned_data['backing_file'] |
|---|
| 47 | ext = f.name.rsplit('.')[-1] |
|---|
| 48 | contenttype = f.content_type |
|---|
| 49 | if ext != 'pdf': |
|---|
| 50 | raise django.forms.ValidationError(u"Only PDF files are accepted – you submitted a .%s file" % (ext, )) |
|---|
| 51 | elif contenttype != 'application/pdf': |
|---|
| 52 | raise django.forms.ValidationError(u"Only PDF files are accepted – you submitted a %s file" % (contenttype, )) |
|---|
| 53 | else: |
|---|
| 54 | return f |
|---|
| 55 | |
|---|
| 56 | class Meta: |
|---|
| 57 | model = Documentation |
|---|
| 58 | fields = ( |
|---|
| 59 | 'label', |
|---|
| 60 | 'backing_file', |
|---|
| 61 | ) |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | @user_passes_test(lambda u: u.is_authenticated()) |
|---|
| 65 | def select_request_basics(http_request, ): |
|---|
| 66 | if http_request.method == 'POST': # If the form has been submitted... |
|---|
| 67 | form = SelectRequestBasicsForm(http_request.POST) # A form bound to the POST data |
|---|
| 68 | if form.is_valid(): # All validation rules pass |
|---|
| 69 | term = form.cleaned_data['term'].slug |
|---|
| 70 | area = form.cleaned_data['area'].id |
|---|
| 71 | recipient_type = form.cleaned_data['recipient_type'] |
|---|
| 72 | url = reverse(submit_request, args=[term, area, recipient_type],) |
|---|
| 73 | return HttpResponseRedirect(url) # Redirect after POST |
|---|
| 74 | else: |
|---|
| 75 | form = SelectRequestBasicsForm() # An unbound form |
|---|
| 76 | |
|---|
| 77 | context = { |
|---|
| 78 | 'form':form, |
|---|
| 79 | 'pagename':'request_reimbursement', |
|---|
| 80 | } |
|---|
| 81 | return render_to_response('vouchers/select.html', context, context_instance=RequestContext(http_request), ) |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | class CommitteeBudgetAreasField(ModelChoiceField): |
|---|
| 85 | def __init__(self, base_area, *args, **kargs): |
|---|
| 86 | self.strip_levels = base_area.depth |
|---|
| 87 | areas = base_area.get_descendants() |
|---|
| 88 | ModelChoiceField.__init__(self, queryset=areas, |
|---|
| 89 | help_text='In general, this should be a fully indented budget area, not one with children', |
|---|
| 90 | *args, **kargs) |
|---|
| 91 | |
|---|
| 92 | def label_from_instance(self, obj,): |
|---|
| 93 | return obj.indented_name(strip_levels=self.strip_levels) |
|---|
| 94 | |
|---|
| 95 | class ExpenseAreasField(ModelChoiceField): |
|---|
| 96 | def __init__(self, *args, **kargs): |
|---|
| 97 | base_area = vouchers.models.BudgetArea.get_by_path(['Accounts', 'Expenses']) |
|---|
| 98 | self.strip_levels = base_area.depth |
|---|
| 99 | areas = base_area.get_descendants() |
|---|
| 100 | ModelChoiceField.__init__(self, queryset=areas, |
|---|
| 101 | help_text='In general, this should be a fully indented budget area, not one with children', |
|---|
| 102 | *args, **kargs) |
|---|
| 103 | |
|---|
| 104 | def label_from_instance(self, obj,): |
|---|
| 105 | return obj.indented_name(strip_levels=self.strip_levels) |
|---|
| 106 | |
|---|
| 107 | class RequestForm(ModelForm): |
|---|
| 108 | expense_area = ExpenseAreasField() |
|---|
| 109 | |
|---|
| 110 | def __init__(self, *args, **kwargs): |
|---|
| 111 | super(RequestForm, self).__init__(*args, **kwargs) |
|---|
| 112 | if self.instance.recipient_type == 'mit': |
|---|
| 113 | addr_widget = django.forms.HiddenInput() |
|---|
| 114 | self.fields['check_to_addr'].widget = addr_widget |
|---|
| 115 | else: |
|---|
| 116 | rfp = vouchers.models.RFP |
|---|
| 117 | error_msgs = dict(invalid=rfp.addr_error) |
|---|
| 118 | addr_widget = self.fields['check_to_addr'].widget |
|---|
| 119 | addr_field = django.forms.RegexField(regex=rfp.addr_regex, error_messages=error_msgs) |
|---|
| 120 | addr_field.widget = addr_widget |
|---|
| 121 | self.fields['check_to_addr'] = addr_field |
|---|
| 122 | |
|---|
| 123 | class Meta: |
|---|
| 124 | model = ReimbursementRequest |
|---|
| 125 | fields = ( |
|---|
| 126 | 'name', |
|---|
| 127 | 'description', |
|---|
| 128 | 'incurred_time', |
|---|
| 129 | 'amount', |
|---|
| 130 | 'budget_area', |
|---|
| 131 | 'expense_area', |
|---|
| 132 | 'check_to_first_name', |
|---|
| 133 | 'check_to_last_name', |
|---|
| 134 | 'check_to_email', |
|---|
| 135 | 'check_to_addr', |
|---|
| 136 | ) |
|---|
| 137 | |
|---|
| 138 | @user_passes_test(lambda u: u.is_authenticated()) |
|---|
| 139 | def submit_request(http_request, term, committee, recipient_type, ): |
|---|
| 140 | term_obj = get_object_or_404(BudgetTerm, slug=term) |
|---|
| 141 | comm_obj = get_object_or_404(BudgetArea, pk=committee) |
|---|
| 142 | |
|---|
| 143 | new_request = ReimbursementRequest() |
|---|
| 144 | new_request.submitter = http_request.user.username |
|---|
| 145 | new_request.budget_term = term_obj |
|---|
| 146 | new_request.recipient_type = recipient_type |
|---|
| 147 | |
|---|
| 148 | # Prefill from user information (itself prefilled from LDAP now) |
|---|
| 149 | initial = {} |
|---|
| 150 | initial['check_to_first_name'] = http_request.user.first_name |
|---|
| 151 | initial['check_to_last_name'] = http_request.user.last_name |
|---|
| 152 | initial['check_to_email'] = http_request.user.email |
|---|
| 153 | |
|---|
| 154 | if http_request.method == 'POST': # If the form has been submitted... |
|---|
| 155 | form = RequestForm(http_request.POST, instance=new_request) # A form bound to the POST data |
|---|
| 156 | form.fields['budget_area'] = CommitteeBudgetAreasField(comm_obj) |
|---|
| 157 | |
|---|
| 158 | if form.is_valid(): # All validation rules pass |
|---|
| 159 | request_obj = form.save() |
|---|
| 160 | print "request_obj==new_request:", request_obj == new_request |
|---|
| 161 | |
|---|
| 162 | # Send email |
|---|
| 163 | tmpl = get_template('vouchers/emails/request_submit_admin.txt') |
|---|
| 164 | ctx = Context({ |
|---|
| 165 | 'submitter': http_request.user, |
|---|
| 166 | 'request': request_obj, |
|---|
| 167 | }) |
|---|
| 168 | body = tmpl.render(ctx) |
|---|
| 169 | recipients = [] |
|---|
| 170 | for name, addr in settings.ADMINS: |
|---|
| 171 | recipients.append(addr) |
|---|
| 172 | recipients.append(request_obj.budget_area.owner_address()) |
|---|
| 173 | if settings.CC_SUBMITTER: |
|---|
| 174 | recipients.append(http_request.user.email) |
|---|
| 175 | send_mail( |
|---|
| 176 | '%sRequest submittal: %s requested $%s' % ( |
|---|
| 177 | settings.EMAIL_SUBJECT_PREFIX, |
|---|
| 178 | http_request.user, |
|---|
| 179 | request_obj.amount, |
|---|
| 180 | ), |
|---|
| 181 | body, |
|---|
| 182 | settings.SERVER_EMAIL, |
|---|
| 183 | recipients, |
|---|
| 184 | ) |
|---|
| 185 | |
|---|
| 186 | return HttpResponseRedirect(reverse(review_request, args=[new_request.pk],) + '?new=true') # Redirect after POST |
|---|
| 187 | else: |
|---|
| 188 | form = RequestForm(instance=new_request, initial=initial, ) # An unbound form |
|---|
| 189 | form.fields['budget_area'] = CommitteeBudgetAreasField(comm_obj) |
|---|
| 190 | |
|---|
| 191 | context = { |
|---|
| 192 | 'term':term_obj, |
|---|
| 193 | 'comm':comm_obj, |
|---|
| 194 | 'request': new_request, |
|---|
| 195 | 'form':form, |
|---|
| 196 | 'pagename':'request_reimbursement', |
|---|
| 197 | } |
|---|
| 198 | return render_to_response('vouchers/submit.html', context, context_instance=RequestContext(http_request), ) |
|---|
| 199 | |
|---|
| 200 | class VoucherizeForm(Form): |
|---|
| 201 | name = django.forms.CharField(max_length=100, help_text='Signatory name for voucher',) |
|---|
| 202 | email = django.forms.EmailField(max_length=100, help_text='Signatory email for voucher') |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | @user_passes_test(lambda u: u.is_authenticated()) |
|---|
| 206 | def review_request(http_request, object_id): |
|---|
| 207 | request_obj = get_object_or_404(ReimbursementRequest, pk=object_id) |
|---|
| 208 | user = http_request.user |
|---|
| 209 | pagename = 'request_reimbursement' |
|---|
| 210 | new = False |
|---|
| 211 | if 'new' in http_request.REQUEST: |
|---|
| 212 | if http_request.REQUEST['new'].upper() == 'TRUE': |
|---|
| 213 | new = True |
|---|
| 214 | else: |
|---|
| 215 | new = False |
|---|
| 216 | |
|---|
| 217 | if (user.has_perm('vouchers.can_list') or |
|---|
| 218 | user.username == request_obj.submitter or |
|---|
| 219 | user.email.upper() == request_obj.check_to_email.upper() |
|---|
| 220 | ): |
|---|
| 221 | pass |
|---|
| 222 | else: |
|---|
| 223 | return get_403_response(http_request, errmsg="You do not have permission to access this reimbursement request. You can only view requests you submitted or are the recipient for, unless you have general viewing permissions.", pagename=pagename, ) |
|---|
| 224 | |
|---|
| 225 | # DOCUMENTATION # |
|---|
| 226 | if request_obj.documentation: |
|---|
| 227 | doc_upload_form = None |
|---|
| 228 | else: |
|---|
| 229 | new_docs = Documentation() |
|---|
| 230 | new_docs.submitter = http_request.user.username |
|---|
| 231 | if http_request.method == 'POST' and 'upload_documentation' in http_request.REQUEST: # If the form has been submitted... |
|---|
| 232 | doc_upload_form = DocUploadForm(http_request.POST, http_request.FILES, instance=new_docs) # A form bound to the POST data |
|---|
| 233 | |
|---|
| 234 | if doc_upload_form.is_valid(): # All validation rules pass |
|---|
| 235 | new_docs = doc_upload_form.save() |
|---|
| 236 | request_obj.documentation = new_docs |
|---|
| 237 | request_obj.save() |
|---|
| 238 | |
|---|
| 239 | return HttpResponseRedirect(reverse(review_request, args=[object_id],)) # Redirect after POST |
|---|
| 240 | else: |
|---|
| 241 | doc_upload_form = DocUploadForm(instance=new_docs, ) # An unbound form |
|---|
| 242 | |
|---|
| 243 | # SEND EMAILS |
|---|
| 244 | show_email = http_request.user.has_perm('vouchers.can_email') |
|---|
| 245 | if show_email: |
|---|
| 246 | email_message = '' |
|---|
| 247 | if http_request.method == 'POST' and 'send_email' in http_request.REQUEST: |
|---|
| 248 | mail = vouchers.models.stock_emails[http_request.REQUEST['email_name']] |
|---|
| 249 | assert mail.context == 'request' |
|---|
| 250 | mail.send_email_request(request_obj) |
|---|
| 251 | email_message = 'Sent email "%s".' % (mail.label, ) |
|---|
| 252 | email_options = [] |
|---|
| 253 | for mail in vouchers.models.stock_emails.values(): |
|---|
| 254 | if mail.context == 'request': |
|---|
| 255 | email_options.append({ |
|---|
| 256 | 'label': mail.label, |
|---|
| 257 | 'name' : mail.name, |
|---|
| 258 | }) |
|---|
| 259 | |
|---|
| 260 | # APPROVE VOUCHERS |
|---|
| 261 | show_approve = (http_request.user.has_perm('vouchers.can_approve') |
|---|
| 262 | and request_obj.approval_status == vouchers.models.APPROVAL_STATE_PENDING) |
|---|
| 263 | post_approve = (http_request.method == 'POST' and 'approve' in http_request.REQUEST) |
|---|
| 264 | approve_message = '' |
|---|
| 265 | approve_level = '' |
|---|
| 266 | if show_approve: |
|---|
| 267 | if not request_obj.documentation: |
|---|
| 268 | approve_message = "Documentation must be uploaded (above) before approving RFPs." |
|---|
| 269 | approve_level = 'warn' |
|---|
| 270 | elif post_approve: |
|---|
| 271 | request_obj.approve_as_rfp(approver=http_request.user) |
|---|
| 272 | approve_message = 'Queued RFP from request.' |
|---|
| 273 | approve_level = 'info' |
|---|
| 274 | elif post_approve: |
|---|
| 275 | approve_message = "You attempted to approve a reimbursement request that you could not approve. Most likely, either the voucher has already been approved, or you do not have adequate permissions." |
|---|
| 276 | approve_level = 'error' |
|---|
| 277 | |
|---|
| 278 | context = { |
|---|
| 279 | 'rr':request_obj, |
|---|
| 280 | 'pagename':pagename, |
|---|
| 281 | 'new': new, |
|---|
| 282 | 'doc_form': doc_upload_form, |
|---|
| 283 | 'show_approve': show_approve, |
|---|
| 284 | 'approve_message': approve_message, |
|---|
| 285 | 'approve_level': approve_level, |
|---|
| 286 | } |
|---|
| 287 | if show_email: |
|---|
| 288 | context['email_options'] = email_options |
|---|
| 289 | context['email_message'] = email_message |
|---|
| 290 | return render_to_response('vouchers/ReimbursementRequest_review.html', context, context_instance=RequestContext(http_request), ) |
|---|
| 291 | |
|---|
| 292 | @user_passes_test(lambda u: u.has_perm('vouchers.generate_vouchers')) |
|---|
| 293 | def generate_vouchers(http_request, *args): |
|---|
| 294 | unprocessed = True |
|---|
| 295 | if 'unprocessed' in http_request.REQUEST: |
|---|
| 296 | if http_request.REQUEST['unprocessed'].upper() == 'TRUE': |
|---|
| 297 | unprocessed = True |
|---|
| 298 | else: |
|---|
| 299 | unprocessed = False |
|---|
| 300 | mark = True |
|---|
| 301 | if 'mark' in http_request.REQUEST: |
|---|
| 302 | if http_request.REQUEST['mark'].upper() == 'TRUE': |
|---|
| 303 | mark = True |
|---|
| 304 | else: |
|---|
| 305 | mark = False |
|---|
| 306 | |
|---|
| 307 | lst = vouchers.models.Voucher.objects.all() |
|---|
| 308 | if unprocessed: |
|---|
| 309 | lst = lst.filter(processed=False) |
|---|
| 310 | |
|---|
| 311 | total = decimal.Decimal('0.00') |
|---|
| 312 | for voucher in lst: |
|---|
| 313 | total = total + voucher.amount |
|---|
| 314 | |
|---|
| 315 | context = { |
|---|
| 316 | 'vouchers': lst, |
|---|
| 317 | 'total': total, |
|---|
| 318 | 'MEDIA_ROOT': settings.MEDIA_ROOT, |
|---|
| 319 | } |
|---|
| 320 | response = render_to_response( |
|---|
| 321 | 'vouchers/vouchers.tex', |
|---|
| 322 | context, context_instance=RequestContext(http_request), |
|---|
| 323 | mimetype=settings.LATEX_MIMETYPE, |
|---|
| 324 | ) |
|---|
| 325 | |
|---|
| 326 | # Send mail |
|---|
| 327 | tmpl = get_template('vouchers/emails/vouchers_tex.txt') |
|---|
| 328 | ctx = Context({ |
|---|
| 329 | 'converter': http_request.user, |
|---|
| 330 | 'vouchers': lst, |
|---|
| 331 | 'mark': mark, |
|---|
| 332 | 'unprocessed': unprocessed, |
|---|
| 333 | }) |
|---|
| 334 | body = tmpl.render(ctx) |
|---|
| 335 | mail_admins( |
|---|
| 336 | 'Voucher rendering: %d by %s' % ( |
|---|
| 337 | len(lst), |
|---|
| 338 | http_request.user, |
|---|
| 339 | ), |
|---|
| 340 | body, |
|---|
| 341 | ) |
|---|
| 342 | |
|---|
| 343 | if mark: |
|---|
| 344 | for voucher in lst: |
|---|
| 345 | voucher.mark_processed() |
|---|
| 346 | |
|---|
| 347 | return response |
|---|
| 348 | |
|---|
| 349 | def get_related_requests_qobj(user, ): |
|---|
| 350 | return Q(submitter=user.username) | Q(check_to_email=user.email) |
|---|
| 351 | |
|---|
| 352 | request_list_orders = ( |
|---|
| 353 | # Name Label Columns |
|---|
| 354 | ('default', 'Default', ()), |
|---|
| 355 | ('id', 'ID', ('id', )), |
|---|
| 356 | ('state', 'Approval Status', ('approval_status', )), |
|---|
| 357 | ('stateamount', 'Approval Status, then amount', ('approval_status', 'amount', )), |
|---|
| 358 | ('stateto', 'Approval Status, then recipient', ('approval_status', 'check_to_first_name', 'check_to_last_name', )), |
|---|
| 359 | ('statesubmit', 'Approval Status, then submitter', ('approval_status', 'submitter', )), |
|---|
| 360 | ('name', 'Request Name', ('name', )), |
|---|
| 361 | ('amount', 'Amount', ('amount', )), |
|---|
| 362 | ('check_to', 'Check Recipient', ('check_to_first_name', 'check_to_last_name', )), |
|---|
| 363 | ('submitter', 'Submitter', ('submitter', )), |
|---|
| 364 | ) |
|---|
| 365 | |
|---|
| 366 | def list_to_keys(lst): |
|---|
| 367 | dct = {} |
|---|
| 368 | for key in lst: |
|---|
| 369 | dct[key] = True |
|---|
| 370 | return dct |
|---|
| 371 | |
|---|
| 372 | @login_required |
|---|
| 373 | def show_requests(http_request, ): |
|---|
| 374 | # BULK ACTIONS |
|---|
| 375 | actions = vouchers.models.BulkRequestAction.filter_can_only( |
|---|
| 376 | vouchers.models.bulk_request_actions, |
|---|
| 377 | http_request.user, |
|---|
| 378 | ) |
|---|
| 379 | apply_action_message = None |
|---|
| 380 | apply_action_errors = [] |
|---|
| 381 | if 'select' in http_request.REQUEST: |
|---|
| 382 | selected_rr_ids = [ int(item) for item in http_request.REQUEST.getlist('select') ] |
|---|
| 383 | else: |
|---|
| 384 | selected_rr_ids = [] |
|---|
| 385 | if "apply-action" in http_request.POST: |
|---|
| 386 | action_name = http_request.POST['action'] |
|---|
| 387 | if action_name == 'none': |
|---|
| 388 | apply_action_message = "No action selected." |
|---|
| 389 | else: |
|---|
| 390 | matching_actions = [ action for action in actions if action.name == action_name] |
|---|
| 391 | if(len(matching_actions) > 0): |
|---|
| 392 | action = matching_actions[0] |
|---|
| 393 | rrs = ReimbursementRequest.objects.filter(pk__in=selected_rr_ids) |
|---|
| 394 | for rr in rrs: |
|---|
| 395 | success, msg = action.do(http_request, rr) |
|---|
| 396 | if not success: |
|---|
| 397 | apply_action_errors.append((rr, msg)) |
|---|
| 398 | apply_action_message = '"%s" applied to %d request(s) (%d errors encountered)' % (action.label, len(rrs), len(apply_action_errors), ) |
|---|
| 399 | else: |
|---|
| 400 | apply_action_message = "Unknown or forbidden action requested." |
|---|
| 401 | |
|---|
| 402 | # PERMISSION-BASED REQUEST FILTERING |
|---|
| 403 | if http_request.user.has_perm('vouchers.can_list'): |
|---|
| 404 | qs = ReimbursementRequest.objects.all() |
|---|
| 405 | useronly = False |
|---|
| 406 | else: |
|---|
| 407 | qs = ReimbursementRequest.objects.filter(get_related_requests_qobj(http_request.user)) |
|---|
| 408 | useronly = True |
|---|
| 409 | |
|---|
| 410 | # SORTING |
|---|
| 411 | if 'order' in http_request.REQUEST: |
|---|
| 412 | order_row = [row for row in request_list_orders if row[0] == http_request.REQUEST['order']] |
|---|
| 413 | if order_row: |
|---|
| 414 | order, label, cols = order_row[0] |
|---|
| 415 | qs = qs.order_by(*cols) |
|---|
| 416 | else: |
|---|
| 417 | raise Http404('Order by constraint not known') |
|---|
| 418 | else: |
|---|
| 419 | order = 'default' |
|---|
| 420 | |
|---|
| 421 | # DISCRETIONARY REQUEST FILTERING |
|---|
| 422 | if 'approval_status' in http_request.REQUEST: |
|---|
| 423 | approval_status = http_request.REQUEST['approval_status'] |
|---|
| 424 | else: |
|---|
| 425 | approval_status = vouchers.models.APPROVAL_STATE_PENDING |
|---|
| 426 | if approval_status == 'all': |
|---|
| 427 | pass |
|---|
| 428 | else: |
|---|
| 429 | try: |
|---|
| 430 | approval_status = int(approval_status) |
|---|
| 431 | except ValueError: |
|---|
| 432 | raise Http404('approval_status poorly formatted') |
|---|
| 433 | state_row = [row for row in vouchers.models.APPROVAL_STATES if row[0] == approval_status] |
|---|
| 434 | if state_row: |
|---|
| 435 | qs = qs.filter(approval_status=approval_status) |
|---|
| 436 | else: |
|---|
| 437 | raise Http404('approval_status not known') |
|---|
| 438 | |
|---|
| 439 | # GENERATE THE REQUEST |
|---|
| 440 | |
|---|
| 441 | context = { |
|---|
| 442 | 'object_list' : qs, |
|---|
| 443 | 'actions' : actions, |
|---|
| 444 | 'selected_ids' : list_to_keys(selected_rr_ids), |
|---|
| 445 | 'action_message': apply_action_message, |
|---|
| 446 | 'action_errors' : apply_action_errors, |
|---|
| 447 | 'useronly': useronly, |
|---|
| 448 | 'order' : order, |
|---|
| 449 | 'orders' : request_list_orders, |
|---|
| 450 | 'approval_status' : approval_status, |
|---|
| 451 | 'approval_states': vouchers.models.APPROVAL_STATES, |
|---|
| 452 | 'pagename': 'list_requests', |
|---|
| 453 | } |
|---|
| 454 | return render_to_response('vouchers/reimbursementrequest_list.html', context, context_instance=RequestContext(http_request), ) |
|---|