{"action":"created","issue":{"url":"https://api.github.com/repos/kizniche/Mycodo/issues/132","repository_url":"https://api.github.com/repos/kizniche/Mycodo","labels_url":"https://api.github.com/repos/kizniche/Mycodo/issues/132/labels{/name}","comments_url":"https://api.github.com/repos/kizniche/Mycodo/issues/132/comments","events_url":"https://api.github.com/repos/kizniche/Mycodo/issues/132/events","html_url":"https://github.com/kizniche/Mycodo/pull/132","id":185299873,"number":132,"title":"Create an application factory for flask #129","user":{"login":"etiology","id":5456095,"avatar_url":"https://avatars.githubusercontent.com/u/5456095?v=3","gravatar_id":"","url":"https://api.github.com/users/etiology","html_url":"https://github.com/etiology","followers_url":"https://api.github.com/users/etiology/followers","following_url":"https://api.github.com/users/etiology/following{/other_user}","gists_url":"https://api.github.com/users/etiology/gists{/gist_id}","starred_url":"https://api.github.com/users/etiology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etiology/subscriptions","organizations_url":"https://api.github.com/users/etiology/orgs","repos_url":"https://api.github.com/users/etiology/repos","events_url":"https://api.github.com/users/etiology/events{/privacy}","received_events_url":"https://api.github.com/users/etiology/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-26T05:22:47Z","updated_at":"2016-10-27T01:03:51Z","closed_at":"2016-10-26T14:09:54Z","pull_request":{"url":"https://api.github.com/repos/kizniche/Mycodo/pulls/132","html_url":"https://github.com/kizniche/Mycodo/pull/132","diff_url":"https://github.com/kizniche/Mycodo/pull/132.diff","patch_url":"https://github.com/kizniche/Mycodo/pull/132.patch"},"body":"Fixes #129 \r\n\r\n#### What does this update do?\r\n\r\nThis update reorganizes the flask UI app into an application factory pattern.  This pattern improves the application setup by separating it from the implementation and by breaking up the application configuration into functional groups.\r\n\r\nApplication setup is now performed via the ```create_app(config=ProdConfig)``` function [which returns a configured flask app](https://github.com/etiology/Mycodo/blob/9d81cfc3d8d1fd889b33c2447f8739e83fda0aea/mycodo/mycodo_flask/app.py#L42-L57).\r\n\r\nRoutes and Extensions are then registered to the app in separate functions:\r\n - [register_extensions](https://github.com/etiology/Mycodo/blob/9d81cfc3d8d1fd889b33c2447f8739e83fda0aea/mycodo/mycodo_flask/app.py#L60-L73)\r\n - [register_blueprints](https://github.com/etiology/Mycodo/blob/9d81cfc3d8d1fd889b33c2447f8739e83fda0aea/mycodo/mycodo_flask/app.py#L76-L79)\r\n\r\n#### Other Modifications\r\n - [New tests](https://github.com/etiology/Mycodo/blob/9d81cfc3d8d1fd889b33c2447f8739e83fda0aea/mycodo/tests/software_tests/test_database/test_create_dbs.py#L1-L62) were added and the [fixtures were updated](https://github.com/etiology/Mycodo/blob/9d81cfc3d8d1fd889b33c2447f8739e83fda0aea/mycodo/tests/software_tests/test_mycodo_flask/conftest.py#L34-L48) to use the new application factory.  \r\n - Updated **Apache wsgi** file to [use the new app factory](https://github.com/etiology/Mycodo/blob/0e60103be1f5b6f079530d3ec38e37b94d2a9787/mycodo_flask.wsgi#L5).\r\n - [create_dbs](https://github.com/etiology/Mycodo/blob/0e60103be1f5b6f079530d3ec38e37b94d2a9787/init_databases.py#L126-L172) was modified to use the same object config that the flask app is using\r\n - Incremented the version number [1](https://github.com/etiology/Mycodo/blob/0e60103be1f5b6f079530d3ec38e37b94d2a9787/README.md#latest-version-4024), [2](https://github.com/etiology/Mycodo/blob/0e60103be1f5b6f079530d3ec38e37b94d2a9787/mycodo/config.py#L27)\r\n\r\nFor live testing I've installed this on a clean boot image and created a simple CPU sensor.  I was able to generate graphs and use the nav bar links."},"comment":{"url":"https://api.github.com/repos/kizniche/Mycodo/issues/comments/256519554","html_url":"https://github.com/kizniche/Mycodo/pull/132#issuecomment-256519554","issue_url":"https://api.github.com/repos/kizniche/Mycodo/issues/132","id":256519554,"user":{"login":"etiology","id":5456095,"avatar_url":"https://avatars.githubusercontent.com/u/5456095?v=3","gravatar_id":"","url":"https://api.github.com/users/etiology","html_url":"https://github.com/etiology","followers_url":"https://api.github.com/users/etiology/followers","following_url":"https://api.github.com/users/etiology/following{/other_user}","gists_url":"https://api.github.com/users/etiology/gists{/gist_id}","starred_url":"https://api.github.com/users/etiology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etiology/subscriptions","organizations_url":"https://api.github.com/users/etiology/orgs","repos_url":"https://api.github.com/users/etiology/repos","events_url":"https://api.github.com/users/etiology/events{/privacy}","received_events_url":"https://api.github.com/users/etiology/received_events","type":"User","site_admin":false},"created_at":"2016-10-27T01:03:51Z","updated_at":"2016-10-27T01:03:51Z","body":"Ok so I'm still looking into this but this is what I see:\r\n  - ```IntegrityError```'s on the unique constraints is likely because the database already exists which would occur anytime this is not the first call to create_dbs.\r\n  - Lines that contain ```Creating/verifying None at sqlite:/...``` are coming from the [print statements in this area](https://github.com/kizniche/Mycodo/blob/b8123afbc2840751626b474c48984884f141220a/init_databases.py#L151-L166)\r\n  - ```certificate does NOT include an ID which matches the server name``` I'm not sure about yet but I'll look into it.\r\n \r\n[create_dbs](https://github.com/kizniche/Mycodo/blob/b8123afbc2840751626b474c48984884f141220a/init_databases.py#L126) is getting called when the WSGI [app](https://github.com/kizniche/Mycodo/blob/b8123afbc2840751626b474c48984884f141220a/mycodo/mycodo_flask/app.py#L65) is getting setup.  It shouldn't affect anything [because it doesn't replace the databases or the data in them](http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.MetaData.create_all).  It does mean that the UI now has the ability to build the databases if they are missing instead of crashing and requiring the user to run the init_databases again.\r\n\r\nIt's a bit wordy at the moment due to the print statements and perhaps we should replace them with debug level logging message.  \r\n\r\nWhat are you thoughts/feelings on this?  "}}
{"actor":{"display_login":"etiology"}}