Beispiel #1
0
    def done(self, form_list, form_dict, **kwargs):
        # Just a small thing, but you could save a lot of typing by
        # just using a dict literal below. That is, instead of the empty
        #
        # data = {}
        #
        # just include all the known data points directly in the original
        # initialization:
        # data = {
        #     'status': 'moderation',
        #     'title': ...
        #     ...
        # }
        #
        # At least I find it a lot more readable.
        # You can still put in the optional data using the data[key] = value syntax.
        #
        data = {}
        data["status"] = "moderation"
        data["title"] = form_dict["basic_info"].cleaned_data["title"]
        data["description"] = form_dict["basic_info"].cleaned_data["description"]
        data["service_code"] = form_dict["category"].cleaned_data["service_code"]
        data["service_name"] = Service.objects.get(service_code=data["service_code"]).service_name
        latitude = form_dict["closest"].cleaned_data["latitude"]
        longitude = form_dict["closest"].cleaned_data["longitude"]
        data["location"] = GEOSGeometry('SRID=4326;POINT(' + str(longitude) + ' ' + str(latitude) + ')')
        data["address_string"] = reverse_geocode(latitude, longitude)

        data["first_name"] = form_dict["contact"].cleaned_data["first_name"]
        data["last_name"] = form_dict["contact"].cleaned_data["last_name"]
        data["email"] = form_dict["contact"].cleaned_data["email"]
        data["phone"] = form_dict["contact"].cleaned_data["phone"]

        service_object_id = form_dict["closest"].cleaned_data["service_object_id"]
        if service_object_id:
            data["service_object_id"] = service_object_id
            data["service_object_type"] = "http://www.hel.fi/servicemap/v2"

        form_id = form_dict["closest"].cleaned_data["form_id"]

        new_feedback = Feedback(**data)

        fixing_time = calc_fixing_time(data["service_code"])
        waiting_time = timedelta(milliseconds=fixing_time)
        if waiting_time.total_seconds() >= 0:
            new_feedback.expected_datetime = new_feedback.requested_datetime + waiting_time

        new_feedback.save()

        # Attach media urls to the feedback
        files = MediaFile.objects.filter(form_id=form_id)
        if files:
            attach_files_to_feedback(self.request, new_feedback, files)

        return render(self.request, 'feedback_form/done.html', {'form_data': [form.cleaned_data for form in form_list],
                                                                'waiting_time': waiting_time})
Beispiel #2
0
    def done(self, form_list, form_dict, **kwargs):
        data = {
            "status": "moderation",
            "title": form_dict["basic_info"].cleaned_data["title"],
            "description": form_dict["basic_info"].cleaned_data["description"],
            "service_code": form_dict["category"].cleaned_data["service_code"],
            "first_name": form_dict["contact"].cleaned_data["first_name"],
            "last_name": form_dict["contact"].cleaned_data["last_name"],
            "email": form_dict["contact"].cleaned_data["email"],
            "phone": form_dict["contact"].cleaned_data["phone"]
        }

        data["service_name"] = Service.objects.get(service_code=data["service_code"]).service_name

        latitude = form_dict["closest"].cleaned_data["latitude"]
        longitude = form_dict["closest"].cleaned_data["longitude"]
        data["location"] = GEOSGeometry('SRID=4326;POINT(' + str(longitude) + ' ' + str(latitude) + ')')
        data["address_string"] = reverse_geocode(latitude, longitude)

        service_object_id = form_dict["closest"].cleaned_data["service_object_id"]
        if service_object_id:
            data["service_object_id"] = service_object_id
            data["service_object_type"] = "http://www.hel.fi/servicemap/v2"

        form_id = form_dict["closest"].cleaned_data["form_id"]

        new_feedback = Feedback(**data)

        fixing_time = calc_fixing_time(data["service_code"])
        waiting_time = timedelta(milliseconds=fixing_time)
        if waiting_time.total_seconds() >= 0:
            new_feedback.expected_datetime = new_feedback.requested_datetime + waiting_time

        new_feedback.save()

        # Attach media urls to the feedback
        files = MediaFile.objects.filter(form_id=form_id)
        if files:
            attach_files_to_feedback(self.request, new_feedback, files)

        return render(self.request, 'feedback_form/done.html', {'form_data': [form.cleaned_data for form in form_list],
                                                                'waiting_time': waiting_time})
Beispiel #3
0
    def post(self, request, format=None):
        # TODO: (for future releases) add API key rules
        serializer = FeedbackDetailSerializer(data=request.data)
        if serializer.is_valid(raise_exception=True):
            new_feedback = serializer.save()

            # save files in the same manner as it's done in feedback form
            if request.FILES:
                for filename, file in request.FILES.items():
                    save_file_to_db(file, new_feedback.service_request_id)
                files = MediaFile.objects.filter(form_id=new_feedback.service_request_id)
                if files:
                    attach_files_to_feedback(request, new_feedback, files)

            response_data = {
                'service_request_id': new_feedback.service_request_id,
                'service_notice': ''
            }
            return Response(response_data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)