Skip to content

Commit

Permalink
Update master branch from develop (#253)
Browse files Browse the repository at this point in the history
* Fix import resources

* initiated login

* Change button to pushbutton

* change password using password field

* Use PyQt from qgis package

* Change variables, try login without mixin

* fixing login api

* Add logger handler from inasafe

* Update network mixin

* cleand code : add comment

* clean code : change naming convention

* Remove pyc files from source

* Ignore pycharm dir

* Add network mixin test

* Fix things :
- Fix tests
- Restructure project file

* Update header

* Change to QgsNetworkAccessManager

* Add travis

- Add travis
- Update tests

* Clean up code

* Fix translation test

* Change travis gitter webhooks

* Clean up code

* Add travis badge

* added options ui 

* added options ui

* fix test case

* save authtoken

* fix code style

* update docstring (#26)

* Update readme. Removed readme.txt. Removed resources.qrc. Remove pb_tool.cfg

* Add class to fetch organizations

* - Update docstring
- Use MagicMock for testing
- Rename variables

* Update docstring

* Update docstring

* save setting to QSetting

* update docstring

* save setting to QSetting

* update docstring and create setting test

* update docstring

* update docstring

* update checking url instance

* update setting test

* update docstring

* update setting key

* Check pep8 (#31)

* Add cadasta to menu bar

* update test cadasta login dialog

* update test cadasta login dialog

* change naming function

* update test case of cadasta login dialog

* added fetch projects api

* added fetch projects api

* update docstring

* update docstring

* fix test pep8

* added cadasta dialog parent class

* fix typo

* fixing bug init style on parent

* fixing bug init style on parent

* update docstring

* remove custom style for dialog

* added download data wizard

* added download data wizard

* added magicmock to test

* clean code for pep8

* update translation framework

* update translation framework

* fix bug plugin isn't translated in qgis

* fixing fixed layout

* use the testing framework from QGIS

* Add landscape file.

* Initial project creation

* Attribute selection

* Change to stacked widget

* Add project creation step 3

* Update step 2 project creation

* Get geojson layer

* change download project using wizard

* Fix tests

* Update tests

* Update tests

* Progress bar to view progress percentage in step 3

* Set button connection in init to avoid duplicated connection

* update base wizard layout

* clean code for translation

* Deactivate organisation button when loading

* Get canvas extent

* Add geojson library

* Revert "Add geojson library"

This reverts commit 758bd55.

* Export extent to geojson using qgis api

* Reset attributes in step02 if layer is changed in step01

* move login as wizard stacked widget

* added logo to wizard

* add resources to resources folder

* Fix tests

* Update project layer geojson path

* Fix ui layout

* Change QComboBox to QgsMapLayerComboBox in step1

* move plugin under vector menu

* move plugin under vector menu

* put cadasta

* change metadata

* Use QgsFieldComboBox, update step 3

* Clean up codes

* Fix pythonic names in wizard

* Add unit test for url validation

* Fix travis

* update layout

* clean code

* clean code

* Add landscape status in readme and small fix.

* Add token to network request if available

* Upload project and locations

* Using json post request instead

* Enable/disable menu that requires authentication

* Clean up code

* added contact dialog

* added contact database

* move login as widget

* added contact dialog

* clean code

* fix test case

* clean code

* clean code

* fix contact bug and validation of contact

* fix contact bug and validation of contact

* clean code

* Add contact multiple selection list

Formatting variables

* clean code

* Create wizard dialog class

* Fix docstring

* Project basic information update (#67)

* Add parties when creating project

* Update doctstring

* Update format string

* Upload relationship attribute when creating a project (#70)

* Add relationship attribute to cadasta

* Add ApiConnect class

* added helper

* use message class for building helper

* clean code

* Filter organization againts project permission (#73)

* Filter organization againts project permission

* Add test case

* Bug fix on project creation (#74)

* fix delete contact, multiple delete contact

* clean code

* Fix create project if there is no location

* Update locations data

* Update add new location

* Clean up code

* Clean up code

* update UX

* update UX

* update UX

* added release script

* added release script

* update release script

* fix No Field translation

* rolling back qgis.PyQt to PyQt4

* Set QGIS minimum version to 2.14 (#93)

* Fix project creation: (#94)

- Fix validation check if no location type is provided
- Remove attribute dropdown

* parsing properties incoming geojson

* parsing properties incoming geojson

* clean code

* fix bug

* save and get basic information (#97)

* save and get basic information

* add signal for selected layer. turn off update when no basic information provided

* clean code

* check enabled of update project based on project permission

* add checking enabled of update in download project

* allow update after create

* added icons

* distinct layer by type

* fix travis

* Update update wizard (#102)

* Download project and the attributes

* Get downloaded projects to update wizard

* Update project and spatial information

* Try to update relationship attribute from csv

* Save attribute to non geometry layer, will save to file if qgis exited

* Download parties to non geometry layer

* Update parties

* Fix tests and pep8

* added license

* added license

* change about

* questionnaire

* added get questionnaire api

* updated UI for questionnaire

* update questionnaire

* implement update questionnaire in create project

* remove questionnaire in update project

* clean code

* revert download project to be able to download all project

* fix bugs

* clean code

* allow parties and relationship

* change metada version

* fix questionnaire bug

* Fix update project is greyed (#110)

* Fix update project is greyed

* Fix pep8

* Get rel and party id from basic information (#111)

* Fix test (#112)

* Show party attributes from questionnaire (#113)

* Fix pep8

* Fix download relationship and party attributes

* Fix update for different layer type

* Fix project creation

* fix pep error

* fix questionnaire updated before upload location

* Fix party attributes are not downloaded

* Download and parse attributes into qgsfield table

* Fix update from attributes

* Update relationship attributes

* Update project creation

* update questionnaire

* update questionnaire (2)

* Fix no module qgsmaplayercombobox

* Fix project creation with questionnaire

* Fix questionnaire attributes

* Bugs fixing (#140)

* Make url not required

* Fix projects order

* Fix close button in about dialog

* Fix skewed cadasta icon

* Fix title size

* Fix pep8

* update error message detail (#141)

* added requirement checker on submit (#143)

* Fixes (#142)

* Fix typos

* Make primary buttons bigger

* Rename options to user settings

* Update ui

* Fix on windows

* Fix missing icon in windows

* Fix pep8

* Fix function not called

* Fixes (#153)

* Remove attributes column after download

* Update contact after download project

* Fix project creation

* Update project update

* Add contacts when download project

* Do not show downloaded project in list available projects (#155)

* Do not show downloaded project in list available projects

* Fix pep8

* make questionnaire included everytime (#157)

* make download project automatically (#156)

* make download project automatically

* update error message

* fix failed test

* Change no field to ---- no field ---- (#161)

* Grey out downloaded project (#160)

* Add project details and add contacts button (#159)

* Add project details and add contacts button

* Fix header

* Tidy up header

* pep8

* Remove contacts menu

* add advanced for questionnaire (#158)

* add advanced for questionnaire

* change questionnaire layout

* Add about dialog (#162)

* Add checkbox to see all public project (#163)

* Add checkbox to see all public project

* pep8

* Fix key error

* Get downloaded project automatically in update menu (#164)

* Get downloaded project automatically in update menu

* Fix test

* Fix error when updating a project (#171)

* Fix wording (#183)

* Make log panel grey (#182)

* Change add button to link (#181)

* Fixes (#187)

* Fix save token issue

* Fix tests

* Change default domain to platform-staging-api

* Remove credential in test

* Pep8

* Get orgs automatically (#188)

* Get orgs automatically

* Fix #146: Update text error

* Fix test

* Fix tab order

* Fix empty strings translated to None (#184)

* Fix black strings translated to None

* Update json dumps

* Pep8

* Fix bugs (#192)

* fix DateTime fields are not included

* Fix org dropdown width

* Fix test

* Fix dropdown org view in windows (#193)

* Update Travis build status image

* Support paginated responses (#154)

* Support paginated responses

* Merge branch 'develop' into support-pagination

* Update init to pass in URL

* Bugfixes (#199)

* Normalize URL format

* Handle first page of GeoJSON data

* Expect paginated responses

* Import cleanup

* Fix tests

* Fixup

* Handle paginated response

* Fix if no results in data json (#207)

* Handle custom attributes in update location (#210)

* Handle custom attributes in update existing location

* Update add new location with custom attribute

* text changes to user settings

* Add support for non english project (#213)

* Upload project with non roman names

* Update non english name project

* Make clear button always active (#228)

* Make clear button always active

* Fix pep8

* For public projects, only download location layer (#230)

* Fix scroll to view error messages on log when submitting data (#231)

* Fix unchecking public project still loads public project (#229)

* Fix columns that have been joined should not be uploaded (#233)

* Remove failed messages when button clear is clicked (#234)

* Add link to help on JSON format from Advanced (#240)

* Auto close windows when completed (#241)

* Remove index from questionnaire (#244)

* Fix login another account (#245)

* Move help link to questionnaire dialog (#246)

* Fix if custom attributes added in questionnaire (#247)

* Add json hightlighter (#248)

* Clean up questionnaire (#249)

* Activate close button in download project dialog (#250)

* Fix download private project (#252)

* Set username and password input disabled (#255)

* Fix pep8
  • Loading branch information
dimasciput authored and cchristelis committed Aug 29, 2017
1 parent c6d6f02 commit 756421f
Show file tree
Hide file tree
Showing 18 changed files with 500 additions and 195 deletions.
3 changes: 2 additions & 1 deletion cadasta/api/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class Login(BaseApi):

post_data = QByteArray()
post_data = None

def __init__(self, domain, username, password, on_finished=None):
"""Constructor.
Expand All @@ -38,6 +38,7 @@ def __init__(self, domain, username, password, on_finished=None):
:type on_finished: Function
"""
super(Login, self).__init__(domain + '/api/v1/account/login/?')
self.post_data = QByteArray()
self.post_data.append("username=%s&" % username)
self.post_data.append("password=%s" % password)

Expand Down
10 changes: 7 additions & 3 deletions cadasta/gui/tools/helper/content/cadasta_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ def content():
message = m.Message()

message.add(m.Paragraph(tr(
'You can find updated documentation and suggested workflows on our main '
'documentation pages: <a href="https://docs.cadasta.org/en/11-qgis-plugin.html">QGIS chapter</a>. (requires internet access to view)')))
'You can find updated documentation and suggested workflows '
'on our main '
'documentation pages: <a href="https://docs.cadasta.org/en/'
'11-qgis-plugin.html">QGIS chapter</a>. (requires internet '
'access to view)')))
message.add(m.Paragraph(tr(
'There are three windows that will help you '
'to manage your project\'s data.')))
Expand All @@ -64,6 +67,7 @@ def content():
message.add(bullets)

message.add(m.Paragraph(tr(
'Use the <b>User Settings</b> window to log in to your account and get started!'
'Use the <b>User Settings</b> window to log in to your account '
'and get started!'
'')))
return message
83 changes: 83 additions & 0 deletions cadasta/gui/tools/helper/content/options_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# coding=utf-8
"""Help for options."""

from cadasta.utilities.i18n import tr
from extras import messaging as m
from extras.messaging import styles

INFO_STYLE = styles.INFO_STYLE

__author__ = 'Irwan Fathurrahman <[email protected]>'
__date__ = '03/01/17'


def options_help():
"""Help message for Options.
:returns: A message object containing helpful information.
:rtype: messaging.message.Message
"""
message = m.Message()
message.add(heading())
message.add(content())
return message


def heading():
"""Helper method that returns just the header.
This method was added so that the text could be reused in the
other contexts.
:returns: A heading object.
:rtype: safe.messaging.heading.Heading
"""
message = m.Heading(tr('Options Help'), **INFO_STYLE)
return message


def content():
"""Helper method that returns just the content.
This method was added so that the text could be reused in the
other contexts.
:returns: A message object without brand element.
:rtype: safe.messaging.message.Message
"""

message = m.Message()

message.add(m.Paragraph(tr(
'Options will help you redefine url of Cadasta that is used as '
'source. And also it create a credential to be used on submit '
'new or updated projects.')))

message.add(m.Paragraph(tr(
'There are 3 input that all of that are required.')))

bullets = m.BulletedList()
bullets.add(m.Text(
m.ImportantText(tr('Cadasta URL')),

tr('- overwrite current url as cadasta source.'
'default is https://platform-staging-api.cadasta.org/')
))
bullets.add(m.Text(
m.ImportantText(tr('Cadasta Username')),
tr('- username that will be used for other request, e.g: create '
'project')
))
bullets.add(m.Text(
m.ImportantText(tr('Cadasta Password'))

))
message.add(bullets)

message.add(m.Paragraph(tr(
'Fill out the form with your username and password. Click \'Connect\' '
'button '
'to login. If that is successful click the \'Save\' button to save '
'the settings.')))
message.add(m.ImportantText(tr('Note that your password is not saved.')))
return message
71 changes: 69 additions & 2 deletions cadasta/gui/tools/utilities/edit_text_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
import logging
from qgis.PyQt.QtCore import pyqtSignal
from qgis.PyQt.QtGui import (
QDialog,
QDialog
)
from PyQt4.QtCore import QUrl, QRegExp, Qt
from PyQt4.QtGui import (
QDesktopServices,
QColor,
QTextCharFormat,
QFont,
QSyntaxHighlighter
)
from cadasta.utilities.resources import get_ui_class

Expand Down Expand Up @@ -56,11 +64,19 @@ def __init__(self, parent=None, iface=None, text=""):
QDialog.__init__(self, parent)
self.setupUi(self)
self.setWindowTitle('Cadasta Questionnaire')
self.highlighter = Highlighter(self.edit_text.document())
self.show()
self.edit_text.setText(text)
self.edit_text.setPlainText(text)
self.ok_button.clicked.connect(
self.close_edit_text_dialog
)
self.data_schema_help.mousePressEvent = self.show_advanced_help

def show_advanced_help(self, event):
"""Show advanced help
"""
QDesktopServices().openUrl(
QUrl("https://cadasta.github.io/api-docs/#questionnaires"))

def close_edit_text_dialog(self):
"""Function that call when ok button is clicked.
Expand All @@ -75,3 +91,54 @@ def get_text(self):
:rtype: str
"""
return self.edit_text.toPlainText()


class Highlighter(QSyntaxHighlighter):
def __init__(self, parent=None):
super(Highlighter, self).__init__(parent)

self.highlighting_rules = []

value_format = QTextCharFormat()
value_format.setForeground(Qt.darkRed)
self.highlighting_rules.append((
QRegExp("\\btrue\\b|\\bnull\\b|\\bfalse\\b|\\b[0-9]+\\b"),
value_format
))

quotation_format = QTextCharFormat()
quotation_format.setForeground(Qt.darkGreen)
self.highlighting_rules.append((QRegExp("\".*\""),
quotation_format))

self.comment_start_expression = QRegExp("/\\*")
self.comment_end_expression = QRegExp("\\*/")

def highlightBlock(self, text):
for pattern, highlight_format in self.highlighting_rules:
expression = QRegExp(pattern)
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, highlight_format)
index = expression.indexIn(text, index + length)

self.setCurrentBlockState(0)

start_index = 0
if self.previousBlockState() != 1:
start_index = self.comment_start_expression.indexIn(text)

while start_index >= 0:
end_index = self.comment_end_expression.indexIn(text, start_index)

if end_index == -1:
self.setCurrentBlockState(1)
comment_length = len(text) - start_index
else:
comment_length = end_index - start_index + \
self.comment_end_expression.matchedLength()

start_index = self.comment_start_expression.indexIn(
text,
start_index + comment_length)
96 changes: 72 additions & 24 deletions cadasta/gui/tools/utilities/questionnaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,22 @@ def generate_new_questionnaire(
for field in current_layer.fields():
field_name = field.name()
if field_name != 'id':
if field_name not in attributes_in_questionnaire:
if field_name not in mapped_fields:
try:
# check location attributes in question group
location_attributes["questions"].append(
{
"index": index,
"name": field_name,
"label": field_name,
"type": mapping_type[
field.typeName().lower()
],
"required": False,
"constraint": 'null',
"default": 'null',
"hint": 'null',
"relevant": 'null',
}
)
except KeyError:
pass
index += 1
if field_name not in mapped_fields:
try:
# check location attributes in question group
location_attributes["questions"].append(
{
"name": field_name,
"label": field_name,
"type": mapping_type[
field.typeName().lower()
],
"required": False
}
)
except KeyError:
pass
index += 1

# insert into questionnaire
index = -1
Expand All @@ -171,15 +165,69 @@ def generate_new_questionnaire(
break

if index == -1:
location_attributes['index'] = 1
questionnaire['question_groups'].append(
location_attributes)
else:
location_attributes['index'] = index
questionnaire['question_groups'][index] = location_attributes

return json.dumps(questionnaire, indent=4)

def add_index(self, question_object, index):
"""Add index to question.
:param question_object: object to be added index
:type question_object: dict
:param index: current index
:type index: int
:return: latest index
:rtype: int
"""
if 'index' not in question_object:
question_object['index'] = index
else:
if question_object['index'] - index != 1:
question_object['index'] = index + 1
index += 1
return index

def validate_questionnaire(self, questionnaire):
"""Validate and fix questionnaire file.
:param questionnaire: questionnaire string
:type questionnaire: str
:return: validated questionnaire
:rtype: str
"""
questionnaire_obj = json.loads(questionnaire)
index = 1
for question in questionnaire_obj['questions']:
index = self.add_index(question, index)

if 'options' in question:
option_index = 1
for option in question['options']:
option_index = self.add_index(option, option_index)

index = 1
for question_group in questionnaire_obj['question_groups']:
index = self.add_index(question_group, index)

if 'questions' in question_group:
question_index = 1
for question in question_group['questions']:
question_index = self.add_index(question, question_index)
if 'hint' not in question:
question['hint'] = 'null'
if 'default' not in question:
question['default'] = 'null'
if 'relevant' not in question:
question['relevant'] = 'null'

return json.dumps(questionnaire_obj)

def update_questionnaire(
self, organization_slug, project_slug, questionnaire):
"""Update questionnaire of selected project.
Expand Down
Loading

0 comments on commit 756421f

Please sign in to comment.