def test_regional_road_is_detected(self):
        report = Report(
            point=dict_to_point({
                "x": '149776',
                "y": '170005'
            }),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertTrue(report.address_regional)

        report = Report(
            point=dict_to_point({
                "x": '149776',
                "y": '170805'
            }),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertFalse(report.address_regional)
    def testReportResponsibleAssignment(self):
        """Test the assignment of a responsible when creating a report"""
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description="Just a test",
            postalcode=1000,
            address="my address",
            point=dict_to_point({"x": "149776", "y": "170105"}),
            address_number="6h",
            created_by=self.manager_etterbeek,
        )
        new_report.save()
        # when created by pro report is under responsibility of etterbeek, not bxl
        self.assertEquals(new_report.responsible_entity, self.etterbeek)

        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description="Just a test",
            postalcode=1000,
            address="my address",
            point=dict_to_point({"x": "149776", "y": "170105"}),
            address_number="6h",
            citizen=self.citizen,
        )
        new_report.save()
        # when created by citizen, postalcode used for resonsible
        self.assertEquals(new_report.responsible_entity, self.bxl)
Esempio n. 3
0
    def testReportResponsibleAssignment(self):
        '''Test the assignment of a responsible when creating a report'''
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170105'}),
            address_number='6h',
            created_by=self.manager_etterbeek
        )
        new_report.save()
        # when created by pro report is under responsibility of etterbeek, not bxl
        self.assertEquals(new_report.responsible_entity, self.etterbeek)

        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170105'}),
            address_number='6h',
            citizen=self.citizen
        )
        new_report.save()
        # when created by citizen, postalcode used for resonsible
        self.assertEquals(new_report.responsible_entity, self.bxl)
Esempio n. 4
0
    def test_update_priority(self):
        #Test default value of priority set to 1
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170005'}),
            address_number='6h',
            created_by=self.manager
        )
        new_report.save()
        self.assertEquals(new_report.gravity, 0)
        self.assertEquals(new_report.probability, 0)
        self.assertEquals(new_report.get_priority(), 0)
        self.client.login(username='******', password='******')

        #Test update report priority
        self.client.get(
            reverse("report_update_priority", args=[new_report.id]),
            {
                'gravity': '2',
                'probability': '4'
            })
        updated_report = Report.objects.get(id=new_report.id)
        self.assertEquals(updated_report.gravity, 2)
        self.assertEquals(updated_report.probability, 4)
        self.assertEquals(updated_report.get_priority(), 8)
Esempio n. 5
0
    def test_list_entity_manager_reports(self):
        new_report = Report(status=Report.CREATED,
                            secondary_category=self.secondary_category,
                            category=self.category,
                            description='Just a test',
                            postalcode=1000,
                            address='my address',
                            point=dict_to_point({
                                "x": '149776',
                                "y": '170005'
                            }),
                            address_number='6h',
                            citizen=self.citizen)
        new_report.responsible_department = self.group
        new_report.save()

        reports = Report.objects.all()
        self.assertEquals(1,
                          len(reports.entity_responsible(self.entity_manager)))
        self.assertEquals(1, len(reports.responsible(self.entity_manager)))

        new_report.responsible_department = self.group
        new_report.save()

        reports = Report.objects.all()
        self.assertEquals(1, len(reports.responsible(self.entity_manager)))
Esempio n. 6
0
    def test_update_priority(self):
        #Test default value of priority set to 1
        new_report = Report(status=Report.CREATED,
                            secondary_category=self.secondary_category,
                            category=self.category,
                            description='Just a test',
                            postalcode=1000,
                            address='my address',
                            point=dict_to_point({
                                "x": '149776',
                                "y": '170005'
                            }),
                            address_number='6h',
                            created_by=self.manager)
        new_report.save()
        self.assertEquals(new_report.gravity, 0)
        self.assertEquals(new_report.probability, 0)
        self.assertEquals(new_report.get_priority(), 0)
        self.client.login(username='******', password='******')

        #Test update report priority
        self.client.get(
            reverse("report_update_priority", args=[new_report.id]), {
                'gravity': '2',
                'probability': '4'
            })
        updated_report = Report.objects.get(id=new_report.id)
        self.assertEquals(updated_report.gravity, 2)
        self.assertEquals(updated_report.probability, 4)
        self.assertEquals(updated_report.get_priority(), 8)
Esempio n. 7
0
def verify(request):
    pnt = dict_to_point(request.REQUEST)
    reports_nearby = Report.objects.all().visible().public().near(pnt, 20).related_fields()[0:6]

    if reports_nearby:
        return render_to_response("reports/verify.html", {
            "reports_nearby": reports_nearby
        }, context_instance=RequestContext(request))

    return new(request)
Esempio n. 8
0
def verify(request):
    pnt = dict_to_point(request.REQUEST)
    reports_nearby = Report.objects.all().visible().related_fields()
    reports_nearby = reports_nearby.near(pnt, 20)[0:6]

    if reports_nearby:
        return render_to_response("reports/verify.html",
                                  {"reports_nearby": reports_nearby},
                                  context_instance=RequestContext(request))

    return new(request)
 def test_entity_surface_raise_exception_when_outside(self):
     report = Report(
         point=dict_to_point({"x": '0', "y": '0'}),
         postalcode=1000,
         address='my address',
         address_number='6h',
         secondary_category=self.secondary_category,
         category=self.category,
     )
     with self.assertRaises(Exception):
         report.save()
Esempio n. 10
0
    def test_entity_surface_owner_is_responsible(self):
        report = Report(
            point=dict_to_point({"x": '149776', "y": '170005'}),
            postalcode=1000,
            address='my address',
            address_number='6h',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertEqual(report.responsible_entity, self.commune)
Esempio n. 11
0
def reports_pro_mobile(request):
    pnt = dict_to_point(request.REQUEST)
    reports = Report.objects.filter().distance(pnt).order_by('distance')

    #Max 20 reports
    reports = Report.objects.distance(pnt).order_by('distance')[:30]
    result = []

    for i, report in enumerate(reports):
        result.append(report.to_mobile_JSON())

    return JsonHttpResponse({'status': 'success', 'results': result})
Esempio n. 12
0
    def save(self, commit=True):
        report = super(ReportForm, self).save(commit=False)

        report.point = dict_to_point(self.cleaned_data)
        report.status = Report.CREATED
        # report.address = self.cleaned_data["address"].split(", ")[0]
        # report.address_number = self.cleaned_data["address_number"]

        if commit:
            report.save()

        return report
Esempio n. 13
0
    def save(self, commit=True):
        report = super(ReportForm, self).save(commit=False)

        report.point = dict_to_point(self.cleaned_data)
        report.status = Report.CREATED
        # report.address = self.cleaned_data["address"].split(", ")[0]
        # report.address_number = self.cleaned_data["address_number"]

        if commit:
            report.save()

        return report
Esempio n. 14
0
    def test_list_contractor_manager_reports(self):
        new_report = Report(status=Report.CREATED,
                            secondary_category=self.secondary_category,
                            category=self.category,
                            description='Just a test',
                            postalcode=1000,
                            address='my address',
                            point=dict_to_point({
                                "x": '149776',
                                "y": '170005'
                            }),
                            address_number='6h',
                            citizen=self.citizen)

        new_report.contractor = self.stib
        new_report.responsible_department = self.group
        new_report.save()

        new_report2 = Report(status=Report.CREATED,
                             secondary_category=self.secondary_category,
                             category=self.category,
                             description='Just a test',
                             postalcode=1000,
                             address='my address',
                             point=dict_to_point({
                                 "x": '149776',
                                 "y": '170005.2'
                             }),
                             address_number='6',
                             citizen=self.citizen)
        new_report2.responsible_department = self.group
        new_report2.save()

        reports = Report.objects.all()
        # Entity of contractor has 2 reports
        self.assertEquals(
            2, len(reports.entity_responsible(self.contractor_manager)))
        #contractor is responsible for 2 reports (1 as manager, 1 as contractor)
        self.assertEquals(2, len(reports.responsible(self.contractor_manager)))
Esempio n. 15
0
    def test_regional_road_is_detected_on_border(self):
        report = Report(
            # this point is outside the polygon of 1m
            point=dict_to_point({"x": '149776', "y": '170026'}),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertTrue(report.address_regional)
Esempio n. 16
0
def reports_pro(request):
    pnt = dict_to_point(request.REQUEST)
    reports = Report.objects.filter().distance(pnt).order_by('distance')

    #Max 1 month in the past
    timestamp_from = datetime.now().date() - timedelta(days=31)
    reports = Report.objects.filter(
        Q(created__gte=timestamp_from)).distance(pnt).order_by('distance')[:20]
    result = []

    for i, report in enumerate(reports):
        result.append(report.to_JSON())

    return JsonHttpResponse({'status': 'success', 'results': result})
 def test_entity_surface_raise_exception_when_outside(self):
     report = Report(
         point=dict_to_point({
             "x": '0',
             "y": '0'
         }),
         postalcode=1000,
         address='my address',
         address_number='6h',
         secondary_category=self.secondary_category,
         category=self.category,
     )
     with self.assertRaises(Exception):
         report.save()
Esempio n. 18
0
def near_reports_pro(request):
    pnt = dict_to_point(request.REQUEST)

    #Max 1 month in the past
    timestamp_from = datetime.now().date() - timedelta(days=31)
    reports = Report.objects.filter(Q(created__gte=timestamp_from)).distance(pnt).filter('distance',1000).order_by('distance')

    result = []
    for i,report in enumerate(reports):
        result.append(report.to_object())

    return JsonHttpResponse({
        'status':'success',
        'results':result
    })
Esempio n. 19
0
def reports_pro_mobile(request):
    pnt = dict_to_point(request.REQUEST)
    reports = Report.objects.filter().distance(pnt).order_by('distance')

    #Max 20 reports
    reports = Report.objects.distance(pnt).order_by('distance')[:30]
    result = []

    for i,report in enumerate(reports):
        result.append(report.to_mobile_JSON())

    return JsonHttpResponse({
        'status':'success',
        'results':result
    })
    def test_entity_surface_owner_is_responsible(self):
        report = Report(
            point=dict_to_point({
                "x": '149776',
                "y": '170005'
            }),
            postalcode=1000,
            address='my address',
            address_number='6h',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertEqual(report.responsible_entity, self.commune)
Esempio n. 21
0
 def test_dispatch_citizen(self):
     self.report = Report(
         status=Report.CREATED,
         secondary_category=self.secondary_category,
         category=self.category,
         description='Just a test',
         postalcode=1000,
         address='my address',
         point=dict_to_point({"x": '149776', "y": '170005'}),
         address_number='6h',
         accepted_at=datetime.now()
     )
     self.report.save()
     self.assertEquals(self.report.responsible_entity, self.organisation)
     self.assertEquals(self.report.responsible_department, self.department)
Esempio n. 22
0
    def test_list_contractor_manager_reports(self):
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description="Just a test",
            postalcode=1000,
            address="my address",
            point=dict_to_point({"x": "149776", "y": "170005"}),
            address_number="6h",
            citizen=self.citizen,
        )

        new_report.contractor = self.stib
        new_report.responsible_department = self.group
        new_report.save()

        new_report2 = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description="Just a test",
            postalcode=1000,
            address="my address",
            point=dict_to_point({"x": "149776", "y": "170005.2"}),
            address_number="6",
            citizen=self.citizen,
        )
        new_report2.responsible_department = self.group
        new_report2.save()

        reports = Report.objects.all()
        # Entity of contractor has 2 reports
        self.assertEquals(2, len(reports.entity_responsible(self.contractor_manager)))
        # contractor is responsible for 2 reports (1 as manager, 1 as contractor)
        self.assertEquals(2, len(reports.responsible(self.contractor_manager)))
Esempio n. 23
0
    def test_regional_road_is_detected(self):
        report = Report(
            point=dict_to_point({"x": '149776', "y": '170005'}),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertTrue(report.address_regional)

        report = Report(
            point=dict_to_point({"x": '149776', "y": '170805'}),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertFalse(report.address_regional)
Esempio n. 24
0
 def test_dispatch_citizen(self):
     self.report = Report(status=Report.CREATED,
                          secondary_category=self.secondary_category,
                          category=self.category,
                          description='Just a test',
                          postalcode=1000,
                          address='my address',
                          point=dict_to_point({
                              "x": '149776',
                              "y": '170005'
                          }),
                          address_number='6h',
                          accepted_at=datetime.now())
     self.report.save()
     self.assertEquals(self.report.responsible_entity, self.organisation)
     self.assertEquals(self.report.responsible_department, self.department)
    def test_regional_road_is_detected_on_border(self):
        report = Report(
            # this point is outside the polygon of 1m
            point=dict_to_point({
                "x": '149776',
                "y": '170026'
            }),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertTrue(report.address_regional)
Esempio n. 26
0
    def test_list_agent_reports(self):
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description="Just a test",
            postalcode=1000,
            address="my address",
            point=dict_to_point({"x": "149776", "y": "170005"}),
            address_number="6h",
            citizen=self.citizen,
        )
        new_report.save()

        reports = Report.objects.all()

        # Agent has no report
        self.assertFalse(reports.responsible(self.agent))
Esempio n. 27
0
    def test_list_contractor_reports(self):
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description="Just a test",
            postalcode=1000,
            address="my address",
            point=dict_to_point({"x": "149776", "y": "170005"}),
            address_number="6h",
            citizen=self.citizen,
        )
        new_report.contractor = self.bxl
        new_report.save()

        reports = Report.objects.all()

        # Contractor has reports
        self.assertTrue(reports.entity_responsible(self.contractor))
Esempio n. 28
0
    def test_list_agent_reports(self):
        new_report = Report(status=Report.CREATED,
                            secondary_category=self.secondary_category,
                            category=self.category,
                            description='Just a test',
                            postalcode=1000,
                            address='my address',
                            point=dict_to_point({
                                "x": '149776',
                                "y": '170005'
                            }),
                            address_number='6h',
                            citizen=self.citizen)
        new_report.save()

        reports = Report.objects.all()

        # Agent has no report
        self.assertFalse(reports.responsible(self.agent))
Esempio n. 29
0
    def test_list_contractor_reports(self):
        new_report = Report(status=Report.CREATED,
                            secondary_category=self.secondary_category,
                            category=self.category,
                            description='Just a test',
                            postalcode=1000,
                            address='my address',
                            point=dict_to_point({
                                "x": '149776',
                                "y": '170005'
                            }),
                            address_number='6h',
                            citizen=self.citizen)
        new_report.contractor = self.bxl
        new_report.save()

        reports = Report.objects.all()

        # Contractor has reports
        self.assertTrue(reports.entity_responsible(self.contractor))
Esempio n. 30
0
    def testReportFileType(self):
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170105'}),
            address_number='6h',
            created_by=self.manager_etterbeek
        )
        new_report.save()

        reportFile = ReportFile(file_type=ReportFile.PDF, report=new_report)
        self.assertTrue(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.WORD, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertTrue(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.EXCEL, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertTrue(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.IMAGE, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertTrue(reportFile.is_image())
        self.assertFalse(reportFile.is_document())
Esempio n. 31
0
    def testReportFileType(self):
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description="Just a test",
            postalcode=1000,
            address="my address",
            point=dict_to_point({"x": "149776", "y": "170105"}),
            address_number="6h",
            created_by=self.manager_etterbeek,
        )
        new_report.save()

        reportFile = ReportFile(file_type=ReportFile.PDF, report=new_report)
        self.assertTrue(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.WORD, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertTrue(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.EXCEL, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertTrue(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.IMAGE, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertTrue(reportFile.is_image())
        self.assertFalse(reportFile.is_document())
Esempio n. 32
0
 def test_dispatch_pro(self):
     """
     when a report is created by a agent / manager / entity
     responsible entity is computed based on responsible entity from creator
     """
     self.client.login(username='******', password='******')
     self.report = Report(
         status=Report.CREATED,
         secondary_category=self.secondary_category,
         category=self.category,
         description='Just a test',
         postalcode=1090,
         address='my address',
         point=dict_to_point({"x": '149776', "y": '170005'}),
         address_number='6h',
         created_by=self.manager,
         accepted_at=datetime.now()
     )
     self.report.save()
     self.assertEquals(self.report.responsible_entity, self.organisation)
     self.assertEquals(self.report.responsible_department, self.department)
Esempio n. 33
0
 def test_dispatch_pro(self):
     """
     when a report is created by a agent / manager / entity
     responsible entity is computed based on responsible entity from creator
     """
     self.client.login(username='******', password='******')
     self.report = Report(status=Report.CREATED,
                          secondary_category=self.secondary_category,
                          category=self.category,
                          description='Just a test',
                          postalcode=1090,
                          address='my address',
                          point=dict_to_point({
                              "x": '149776',
                              "y": '170005'
                          }),
                          address_number='6h',
                          created_by=self.manager,
                          accepted_at=datetime.now())
     self.report.save()
     self.assertEquals(self.report.responsible_entity, self.organisation)
     self.assertEquals(self.report.responsible_department, self.department)
Esempio n. 34
0
    def test_list_entity_manager_reports(self):
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description="Just a test",
            postalcode=1000,
            address="my address",
            point=dict_to_point({"x": "149776", "y": "170005"}),
            address_number="6h",
            citizen=self.citizen,
        )
        new_report.responsible_department = self.group
        new_report.save()

        reports = Report.objects.all()
        self.assertEquals(1, len(reports.entity_responsible(self.entity_manager)))
        self.assertEquals(1, len(reports.responsible(self.entity_manager)))

        new_report.responsible_department = self.group
        new_report.save()

        reports = Report.objects.all()
        self.assertEquals(1, len(reports.responsible(self.entity_manager)))
Esempio n. 35
0
    def setUp(self):
        self.client = Client()

        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.organisation = OrganisationEntity.objects.get(pk=14)
        self.organisation2 = OrganisationEntity.objects.get(pk=15)

        self.group = OrganisationEntity(type="D",
                                        name_nl="Werken",
                                        name_fr="Travaux",
                                        phone="090987",
                                        dependency=self.organisation,
                                        email="*****@*****.**")
        self.group.save()

        self.group_mail_config = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.save()

        self.group2 = OrganisationEntity(type="D",
                                         name_nl="Werken2",
                                         name_fr="Travaux2",
                                         phone="090987",
                                         dependency=self.organisation2,
                                         email="*****@*****.**")
        self.group2.save()

        self.group_mail_config2 = GroupMailConfig()
        self.group_mail_config2.group = self.group2
        self.group_mail_config2.save()

        self.manager = FMSUser(is_active=True,
                               telephone="0123456789",
                               last_used_language="fr",
                               password='******',
                               first_name="manager",
                               last_name="manager",
                               email="*****@*****.**",
                               manager=True)
        self.manager.set_password('test')
        self.manager.organisation = self.organisation
        self.manager.save()

        self.manager2 = FMSUser(is_active=True,
                                telephone="0123456789",
                                last_used_language="fr",
                                password='******',
                                first_name="manager2",
                                last_name="manager2",
                                email="*****@*****.**",
                                manager=True)
        self.manager2.set_password('test')
        self.manager2.organisation = self.organisation
        self.manager2.save()

        self.usergroupmembership = UserOrganisationMembership(
            user_id=self.manager.id,
            organisation_id=self.group.id,
            contact_user=True)
        self.usergroupmembership.save()

        self.usergroupmembership = UserOrganisationMembership(
            user_id=self.manager2.id,
            organisation_id=self.group2.id,
            contact_user=True)
        self.usergroupmembership.save()

        self.report = Report(status=Report.CREATED,
                             secondary_category=self.secondary_category,
                             category=self.category,
                             description='Just a test',
                             postalcode=1000,
                             address='my address',
                             point=dict_to_point({
                                 "x": '149776',
                                 "y": '170005'
                             }),
                             address_number='6h',
                             created_by=self.manager,
                             accepted_at=datetime.now())
        self.report.save()
Esempio n. 36
0
    def setUp(self):
        self.client = Client()

        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.organisation = OrganisationEntity.objects.get(pk=14)
        self.organisation2 = OrganisationEntity.objects.get(pk=15)

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.organisation,
            email="*****@*****.**"
            )
        self.group.save()

        self.group_mail_config       = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken2",
            name_fr="Travaux2",
            phone="090987",
            dependency=self.organisation2,
            email="*****@*****.**"
            )
        self.group2.save()

        self.group_mail_config2       = GroupMailConfig()
        self.group_mail_config2.group = self.group2
        self.group_mail_config2.save()

        self.manager = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager",
            last_name="manager",
            email="*****@*****.**",
            manager=True
        )
        self.manager.set_password('test')
        self.manager.organisation = self.organisation
        self.manager.save()

        self.manager2 = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        self.manager2.set_password('test')
        self.manager2.organisation = self.organisation
        self.manager2.save()

        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager.id, organisation_id=self.group.id, contact_user=True)
        self.usergroupmembership.save()

        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager2.id, organisation_id=self.group2.id, contact_user=True)
        self.usergroupmembership.save()

        self.report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170005'}),
            address_number='6h',
            created_by=self.manager,
            accepted_at=datetime.now()
        )
        self.report.save()
Esempio n. 37
0
    def setUp(self):
        self.bxl = OrganisationEntity.objects.get(id=4)
        self.manager_bxl = FMSUser(is_active=True,
                                   email="*****@*****.**",
                                   telephone="0123456789",
                                   last_used_language="fr",
                                   manager=True,
                                   organisation=self.bxl)
        self.manager_bxl.set_password('test')
        self.manager_bxl.save()

        self.group = OrganisationEntity(type="D",
                                        name_nl="Werken",
                                        name_fr="Travaux",
                                        phone="090987",
                                        dependency=self.bxl,
                                        email="*****@*****.**")
        self.group.save()

        self.group_mail_config = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.save()

        self.usergroupmembership = UserOrganisationMembership(
            user_id=self.manager_bxl.id,
            organisation_id=self.group.id,
            contact_user=True)
        self.usergroupmembership.save()
        self.citizen = FMSUser(email="*****@*****.**",
                               telephone="0123456789",
                               last_used_language="fr")
        self.citizen.save()

        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.client.login(username=self.manager_bxl.email, password='******')
        self.report = Report(status=Report.CREATED,
                             secondary_category=self.secondary_category,
                             category=self.category,
                             description='Just a test',
                             postalcode=1000,
                             address='my address',
                             point=dict_to_point({
                                 "x": '149776',
                                 "y": '170005'
                             }),
                             address_number='6h',
                             created_by=self.manager_bxl)
        self.report.save()

        self.report.attachments.add(
            ReportComment(text='test comment 1',
                          security_level=ReportComment.PRIVATE))

        self.client.logout()

        self.report.attachments.add(
            ReportComment(text='test comment 2',
                          security_level=ReportComment.PUBLIC))
        self.report.attachments.add(
            ReportComment(text='test comment 3',
                          logical_deleted=True,
                          security_level=ReportComment.PUBLIC))

        self.client = Client()
Esempio n. 38
0
    def setUp(self):
        self.bxl = OrganisationEntity.objects.get(id=4)
        self.manager_bxl = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl)
        self.manager_bxl.set_password('test')
        self.manager_bxl.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.bxl,
            email="*****@*****.**"
            )
        self.group.save()

        self.group_mail_config       = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.save()

        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager_bxl.id, organisation_id=self.group.id, contact_user=True)
        self.usergroupmembership.save()
        self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr")
        self.citizen.save()

        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.client.login(username=self.manager_bxl.email, password='******')
        self.report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170005'}),
            address_number='6h',
            created_by=self.manager_bxl
        )
        self.report.save()

        self.report.attachments.add(ReportComment(
            text='test comment 1',
            security_level=ReportComment.PRIVATE
        ))

        self.client.logout()

        self.report.attachments.add(ReportComment(
            text='test comment 2',
            security_level=ReportComment.PUBLIC
        ))
        self.report.attachments.add(ReportComment(
            text='test comment 3',
            logical_deleted=True,
            security_level=ReportComment.PUBLIC
        ))

        self.client = Client()
Esempio n. 39
0
def new(request):
    pnt = dict_to_point(request.REQUEST)
    ReportFileFormSet = inlineformset_factory(Report,
                                              ReportFile,
                                              form=ReportFileForm,
                                              extra=0)
    report = None
    if request.method == "POST":
        report_form = ProReportForm(request.POST,
                                    request.FILES,
                                    prefix='report')
        comment_form = ReportCommentForm(request.POST,
                                         request.FILES,
                                         prefix='comment')

        fingerprint = RequestFingerprint(request)

        # this checks update is_valid too
        if report_form.is_valid() and (
                not request.POST["comment-text"]
                or comment_form.is_valid()) and not fingerprint.is_duplicate():
            # this saves the update as part of the report.
            report = report_form.save(commit=False)

            # Use `hack_multi_file` instead of ``request.FILES``.
            file_formset = ReportFileFormSet(
                request.POST,
                hack_multi_file(request),
                instance=report,
                prefix='files',
                queryset=ReportFile.objects.none())

            if file_formset.is_valid():
                user = FMSUser.objects.get(pk=request.user.id)

                fingerprint.save()

                report.forceAutoDispatching = False
                report.save()

                if report_form.cleaned_data['subscription']:
                    report.subscribe_author()

                if request.POST["comment-text"]:
                    comment = comment_form.save(commit=False)
                    comment.report = report
                    comment.created_by = user
                    # Used for comment post_save signal:
                    comment.is_new_report = True
                    comment.save()

                files = file_formset.save(commit=False)

                for report_file in files:
                    report_file.created_by = user
                    # Used for file post_save signal:
                    report_file.is_new_report = True
                    report_file.save()

                report.forceAutoDispatching = True
                report.save()

                messages.add_message(request,
                                     messages.SUCCESS,
                                     _("Newly created report successfull"),
                                     extra_tags="new_report")
                return HttpResponseRedirect(report.get_absolute_url_pro())
            else:
                report = None

    else:
        report_form = ProReportForm(initial={
            'x': request.REQUEST.get('x'),
            'y': request.REQUEST.get('y')
        },
                                    prefix='report')

    file_formset = ReportFileFormSet(prefix='files',
                                     queryset=ReportFile.objects.none())
    comment_form = ReportCommentForm(prefix='comment')

    return render_to_response("pro/reports/new.html", {
        "report":
        report,
        "all_zipcodes":
        ZipCode.objects.all(),
        "category_classes":
        ReportMainCategoryClass.objects.prefetch_related('categories').all(),
        "report_form":
        report_form,
        "pnt":
        pnt,
        "file_formset":
        file_formset,
        "comment_form":
        comment_form,
        "isNewIncident":
        True
    },
                              context_instance=RequestContext(request))
Esempio n. 40
0
def new(request):
    pnt = dict_to_point(request.REQUEST)
    ReportFileFormSet = inlineformset_factory(Report, ReportFile, form=ReportFileForm, extra=0)
    report = None
    if request.method == "POST":
        report_form = ProReportForm(request.POST, request.FILES, prefix='report')
        comment_form = ReportCommentForm(request.POST, request.FILES, prefix='comment')

        fingerprint = RequestFingerprint(request)

        # this checks update is_valid too
        if report_form.is_valid() and (not request.POST["comment-text"] or comment_form.is_valid()) and not fingerprint.is_duplicate():
            # this saves the update as part of the report.
            report = report_form.save(commit=False)

            # Use `hack_multi_file` instead of ``request.FILES``.
            file_formset = ReportFileFormSet(request.POST, hack_multi_file(request), instance=report, prefix='files', queryset=ReportFile.objects.none())

            if file_formset.is_valid():
                user = FMSUser.objects.get(pk=request.user.id)

                fingerprint.save()

                report.save()

                if report_form.cleaned_data['subscription']:
                    report.subscribe_author()

                if request.POST["comment-text"]:
                    comment = comment_form.save(commit=False)
                    comment.report = report
                    comment.created_by = user
                    # Used for comment post_save signal:
                    comment.is_new_report = True
                    comment.save()

                files = file_formset.save(commit=False)

                for report_file in files:
                    report_file.created_by = user
                    # Used for file post_save signal:
                    report_file.is_new_report = True
                    report_file.save()

                messages.add_message(request, messages.SUCCESS, _("Newly created report successfull"), extra_tags="new_report")
                return HttpResponseRedirect(report.get_absolute_url_pro())
            else:
                report = None

    else:
        report_form = ProReportForm(initial={
            'x': request.REQUEST.get('x'),
            'y': request.REQUEST.get('y')
        }, prefix='report')

    file_formset = ReportFileFormSet(prefix='files', queryset=ReportFile.objects.none())
    comment_form = ReportCommentForm(prefix='comment')

    return render_to_response("pro/reports/new.html", {
        "report": report,
        "all_zipcodes": ZipCode.objects.all(),
        "category_classes": ReportMainCategoryClass.objects.prefetch_related('categories').all(),
        "report_form": report_form,
        "pnt": pnt,
        "file_formset": file_formset,
        "comment_form": comment_form,
    }, context_instance=RequestContext(request))