Пример #1
0
 def task_post_helper(self, request, task, form_data=None):
     """Special post helper exclusive to ResponseTask"""
     if request.POST.get('proxy') or request.POST.get('save'):
         form = ResponseTaskForm(request.POST, task=task)
         if not form.is_valid():
             messages.error(request, 'Form is invalid')
             return
         action_taken, error_msgs = form.process_form(task, request.user)
         for msg in error_msgs:
             messages.error(request, msg)
         if action_taken and not error_msgs:
             form_data = form.cleaned_data
             if form_data['price'] is not None:
                 # cast from decimal to float, since decimal
                 # is not json serializable
                 form_data['price'] = float(form_data['price'])
             if form_data.get('date_estimate'):
                 # to string for json
                 form_data['date_estimate'] = form_data[
                     'date_estimate'].isoformat()
             if task.scan:
                 task.communication.hidden = False
                 task.communication.create_agency_notifications()
                 task.communication.save()
             task.resolve(request.user, form.cleaned_data)
     return super(ResponseTaskList, self).task_post_helper(request, task)
Пример #2
0
 def task_post_helper(self, request, task):
     """Special post helper exclusive to ResponseTask"""
     # pylint: disable=too-many-branches
     task = super(ResponseTaskList, self).task_post_helper(request, task)
     error_happened = False
     form = ResponseTaskForm(request.POST)
     if not form.is_valid():
         messages.error(request, 'Form is invalid')
         return
     cleaned_data = form.cleaned_data
     status = cleaned_data['status']
     set_foia = cleaned_data['set_foia']
     move = cleaned_data['move']
     tracking_number = cleaned_data['tracking_number']
     date_estimate = cleaned_data['date_estimate']
     price = cleaned_data['price']
     proxy = cleaned_data['proxy']
     # move is executed first, so that the status and tracking
     # operations are applied to the correct FOIA request
     comms = None
     if move:
         try:
             comms = task.move(move)
         except (Http404, ValueError):
             messages.error(request,
                            'No valid destination for moving the request.')
             error_happened = True
     if status:
         try:
             task.set_status(status, set_foia, comms)
         except ValueError:
             messages.error(
                 request,
                 'You tried to set the request to an invalid status.')
             error_happened = True
     if tracking_number:
         try:
             task.set_tracking_id(tracking_number, comms)
         except ValueError:
             messages.error(
                 request,
                 'You tried to set an invalid tracking id. Just use a string of characters.'
             )
             error_happened = True
     if date_estimate:
         try:
             task.set_date_estimate(date_estimate, comms)
         except ValueError:
             messages.error(
                 request,
                 'You tried to set the request to an invalid date.')
             error_happened = True
     if price:
         try:
             task.set_price(price, comms)
         except ValueError:
             messages.error(request,
                            'You tried to set a non-numeric price.')
             error_happened = True
     if proxy:
         task.proxy_reject(comms)
     action_taken = move or status or tracking_number or price or proxy
     if action_taken and not error_happened:
         task.resolve(request.user)