예제 #1
0
    def set_widgets(self):
        """Set all widgets on the tab."""
        contacts = Contact.get_rows()

        for contact in contacts:
            contact_name = contact.name
            contact_email = ' - ' + contact.email if contact.email else ''
            contact_phone = ' - ' + contact.phone if contact.phone else ''

            contact_item = QListWidgetItem(contact_name + contact_email +
                                           contact_phone)

            contact_item.setData(Qt.UserRole, contact)
            self.project_contact_list.addItem(contact_item)

        self.project_contact_list.setSelectionMode(
            QAbstractItemView.ExtendedSelection)

        icon_path = resources_path('images', 'throbber.gif')
        movie = QMovie(icon_path)
        self.throbber_loader.setMovie(movie)
        movie.start()
        self.get_available_organisations()
        self.organisation_box.setFocus()
        self.project_description_text.setTabChangesFocus(True)
    def __init__(self, parent=None):
        """Constructor.

        :param parent: parent - widget to use as parent.
        :type parent: QWidget
        """
        super(ContactWidget, self).__init__(parent)
        # Create model
        self.model = Contact.table_model()
        self.set_widgets()
예제 #3
0
    def test_update_database(self):
        """Test Insert success Database."""
        # save first if not saved
        test_contact = Contact(name='test1',
                               email='*****@*****.**',
                               phone='000000')
        test_contact.save()
        self.assertIsNotNone(test_contact.id)

        # update it
        id = test_contact.id
        updated_name = 'test1_updated'
        test_contact.name = updated_name
        test_contact.save()
        self.assertIsNotNone(test_contact.id)

        # check from database
        contacts = Contact.get_rows(id=test_contact.id)
        self.assertEqual(len(contacts), 1)
        self.assertEqual(contacts[0].id, id)
        self.assertEqual(contacts[0].name, updated_name)

        test_contact.delete()
예제 #4
0
    def test_insert_success_database(self):
        """Test Insert success Database."""
        test_contact = Contact(name='test1',
                               email='*****@*****.**',
                               phone='000000')
        test_contact.save()
        self.assertIsNotNone(test_contact.id)

        test_contact.delete()
예제 #5
0
    def test_delete_row(self):
        """Test Get Rows Contact Database."""
        # create first
        test_contact = Contact(name='test3',
                               email='*****@*****.**',
                               phone='00000')
        test_contact.save()
        self.assertIsNotNone(test_contact.id)

        # get it's id
        id = test_contact.id
        contacts = Contact.get_rows(id=id)
        self.assertEqual(len(contacts), 1)

        # delete object
        test_contact.delete()

        # check it again from database
        contacts = Contact.get_rows(id=id)
        self.assertEqual(len(contacts), 0)
예제 #6
0
    def add_to_contacts(self):
        """Open contacts dialog and add current selected contacts to db."""
        if not self.current_contacts:
            return

        for contact in self.current_contacts:
            contact_from_db = Contact.get_rows(name=contact['name'],
                                               phone=contact['tel'],
                                               email=contact['email'])
            if not contact_from_db:
                new_contact = Contact()
                new_contact.name = contact['name']
                new_contact.email = contact['email']
                new_contact.phone = contact['tel']
                new_contact.save()

        # Open contact dialog
        dialog = CadastaDialog(iface=self.iface,
                               subtitle='Contact',
                               widget=ContactWidget())
        dialog.show()
        dialog.exec_()
    def set_widgets(self):
        """Set all widgets on the tab."""
        self.project = self.parent.project['information']

        self.update_status_label.setText('')

        self.project_name_text.setText(self.project['name'])

        if self.project['urls']:
            self.project_url_text.setText(self.project['urls'][0])
        else:
            self.project_url_text.setText('')

        self.project_desc_text.setText(self.project['description'])

        if self.project['access'] == 'private':
            private_access = True
        else:
            private_access = False
        self.access_checkbox.setChecked(private_access)

        contacts = Contact.get_rows()
        project_contacts = self.project['contacts']

        self.project_contact_list.clear()
        self.project_contact_list.setSelectionMode(
            QAbstractItemView.ExtendedSelection)

        # From local db
        for contact in contacts:
            contact_name = contact.name
            contact_email = ' - ' + contact.email if contact.email else ''
            contact_phone = ' - ' + contact.phone if contact.phone else ''

            contact_item = QListWidgetItem(contact_name + contact_email +
                                           contact_phone)

            contact_item.setData(Qt.UserRole, contact)
            self.project_contact_list.addItem(contact_item)

        # From server
        for index, contact in enumerate(project_contacts):
            contact_name = contact['name']
            contact_email = ' - ' + contact['email'] \
                if 'email' in contact and contact['email'] else ''
            contact_phone = ' - ' + contact['tel'] \
                if 'tel' in contact and contact['tel'] else ''

            contact_box = self.project_contact_list.findItems(
                contact_name + contact_email + contact_phone, Qt.MatchExactly)

            if len(contact_box) > 0:
                contact_box[0].setSelected(True)
            else:
                new_contact = Contact()
                new_contact.name = contact['name']
                new_contact.email = contact['email']
                new_contact.phone = contact['tel']
                new_contact.save()

                selected_item = QListWidgetItem(contact_name + contact_email +
                                                contact_phone)
                selected_item.setData(Qt.UserRole, new_contact)

                self.project_contact_list.addItem(selected_item)

                selected_item.setSelected(True)

        self.project_name_text.setFocus()
        self.project_desc_text.setTabChangesFocus(True)
예제 #8
0
    def test_get_rows_database(self):
        """Test Get Rows Contact Database."""
        # create first
        test_contact = Contact(name='test2',
                               email='*****@*****.**',
                               phone='0000')
        test_contact.save()
        test_contact_2 = Contact(name='test2',
                                 email='*****@*****.**',
                                 phone='0000')
        test_contact_2.save()
        self.assertIsNotNone(test_contact.id)

        # get the row
        contacts = Contact.get_rows()
        self.assertGreater(len(contacts), 1)

        test_contact.delete()
        test_contact_2.delete()
예제 #9
0
 def test_insert_fail_database(self):
     """Test Insert Fail Database."""
     contact = Contact()
     contact.save()
     self.assertIsNone(contact.id)
예제 #10
0
    def save_project_basic_information(
            information,
            vlayers=None,
            relationship_layer_id=None,
            party_layer_id=None):
        """Save project basic information.

        :param information: basic information that will be saved
        :type information: dict

        :param vlayers: list of Spatial vector layers
        :type vlayers: list of QgsVectorLayer

        :param relationship_layer_id: Id for relationship layer
        :type relationship_layer_id: str

        :param party_layer_id: Id for party layer
        :type party_layer_id: str
        """
        organization_slug = information['organization']['slug']
        project_slug = information['slug']

        # Save new contacts to db
        if 'contacts' in information:
            project_contacts = information['contacts']

            for contact in project_contacts:

                phone = None
                email = None

                try:
                    phone = contact['tel']
                except KeyError:
                    pass

                try:
                    email = contact['email']
                except KeyError:
                    pass

                contact_from_db = Contact.get_rows(
                    name=contact['name'],
                    phone=phone,
                    email=email
                )

                if not contact_from_db:
                    new_contact = Contact()
                    new_contact.name = contact['name']
                    new_contact.email = contact['email']
                    new_contact.phone = contact['tel']
                    new_contact.save()

        filename = get_path_data(
            organization_slug=organization_slug,
            project_slug=project_slug)

        filename = os.path.join(
            filename,
            'information.json'
        )

        if relationship_layer_id:
            information['relationship_layer_id'] = relationship_layer_id

        if party_layer_id:
            information['party_layer_id'] = party_layer_id

        if vlayers:
            information['layers'] = []
            for layer in vlayers:
                layer_type = ''
                if layer.geometryType() == QGis.Point:
                    layer_type = 'Point'
                elif layer.geometryType() == QGis.Polygon:
                    layer_type = 'Polygon'
                elif layer.geometryType() == QGis.Line:
                    layer_type = 'Line'
                information['layers'].append(
                    {
                        'id': layer.id(),
                        'type': layer_type
                    }
                )

        file_ = open(filename, 'w')
        file_.write(json.dumps(information, sort_keys=True))
        file_.close()