Package: core-main-app
This Django reusable app contains the main functionalities for the curator
core project.Pre-requisitesFor automated and manual install, the following software are needed:pythonpipvirtual env (condaorvenv)In addition, for manual setup,gitis needed.InstallationAutomated installation$pipinstallcore_main_appManual installation$gitclonehttps://github.com/usnistgov/core_main_app.git$cdcore_main_app$pythonsetup.py$pipinstallsdist/*.tar.gzConfigurationEdit the setting.py fileAdd the"core_main_app"underINSTALLED_APPSas
such:INSTALLED_APPS=[..."core_main_app",]Edit the urls.py fileAdd thecore_main_appurls to the Django project as such.url(r'^',include("core_main_app.urls")),Internationalization (i18n)Before running the project, don’t forget to compile the translation file at
project level. i18n uses thegettextpackage, so please make sure it is
installed prior to using this command.$pythonmanage.pycompilemessagesEnable SSL connectionPlease follow these steps to configure the connection to any system running over HTTPS (including the local instance).Create a folder for SSL certificates,Copy the certificate in the folder,Runc_rehashon the folder (needs to be done every time a new certificate is added to the folder),Update the SSL_CERTIFICATES_DIR setting to point to the SSL certificate folder previously created.$mkdircerts$cpcdcs.crtcerts/$c_rehashcerts/Enable Redis Server authenticationPlease follow these steps to enable authentication on the redis server.
Depending on the way Redis is started on the machine, the method may differ.You can follow instructions athttps://redis.io/topics/security#authentication-featureto enable authentication:
* Open the file redis.conf (e.g. /usr/local/etc/redis.conf),
* Uncomment the authentication setting (# requirepass foobared),
* It is recommended to replace the default password (foobared) by a strong and long password,
* Restart the Redis Server.You should then update the CDCS settings using a Redis connection URL with the password chosen in the previous steps.BROKER_URL='redis://:<password>@localhost:6379/0'CELERY_RESULT_BACKEND='redis://:<password>@localhost:6379/0'Enable SMTP serverPlease follow these steps to configure the SMTP server:Set these constants in your setting.py file (all these constants are required)EMAIL_HOST='smtp.myserver.com'EMAIL_PORT=587DEFAULT_FROM_EMAIL='TestSite Team <noreply@example.com>'These optional constants can be added in your setting.py according to your SMTP server configurationEMAIL_USE_TLS=TrueEMAIL_HOST_USER='testsite_app'EMAIL_HOST_PASSWORD='mys3cr3tp4ssw0rd'Enable HistoryDjango Simple History allows keeping track of changes made to an object stored in the CDCS database.
First, install and configure the package. See thedjango-simple-historydocumentation.Then, set theDJANGO_SIMPLE_HISTORY_MODELSsetting with a list of models to track.
At the moment, this feature is only available for theDatamodel.DJANGO_SIMPLE_HISTORY_MODELS=["Data"]Register models to track by updating project files.
For example inmdcs/mdcs_home/admin.py, add the following lines:fromcore_main_app.utils.admin_site.model_admin_classimportregister_simple_history_modelsfromdjango.confimportsettingsDJANGO_SIMPLE_HISTORY_MODELS=getattr(settings,"DJANGO_SIMPLE_HISTORY_MODELS",None)register_simple_history_models(DJANGO_SIMPLE_HISTORY_MODELS)DocumentationDocumentation has been generated using Sphinx. To generate a local version of
the docs, please clone the repository and run:$cddocs/$makehtmlOr, directly using Sphinx:$cddocs/$sphinx-build-bhtml.../dist/_docsDevelopmentDevelopment versionA development version of this package is available, containing tests and formatting
dependencies. To automatically install the development version, run:$pipinstall.[develop]The development dependencies are located inrequirements.dev.txtand can be installed
manually using:$pipinstall-rrequirements.dev.txtCode formattingTo ensure consistent formatting across the codebase, the development team is usingblack. When contributing to this package, install black
as part of the development packages and runblack /path/to/core_main_appbefore
submitting the contribution.TestsTo play the test suite created for this package, download the git repository, install the
development dependencies and run:$pythonruntests.pySending emailTo test the email being sent, console backend will print the email instead of sending the real email.
By default, the console backend writes to stdoutTo specify this backend, add the following in your settings:EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'JSON SupportCDCS 2.6 adds the ability to work directly with JSON documents. A Template can now either be
an XML Schema or a JSON schema. Uploaded data, in XML or JSON format, will be validated by a template in
the corresponding format, by the appropriate validator.This addition has been implemented as an option and needs to be enabled to make the features appear in the system.
The following settings have been added with the implementation of JSON support and need to be set properly to enable the
feature.ENABLE_JSON_SCHEMA_SUPPORT=TrueBACKWARD_COMPATIBILITY_DATA_XML_CONTENT=FalseALLOW_MULTIPLE_SCHEMAS=True# only required for registriesTo enable JSON support in the CDCS,ENABLE_JSON_SCHEMA_SUPPORTshould be set toTrue. For the registry projects,
which are limited to a single XML Schema by default, the settingALLOW_MULTIPLE_SCHEMASshould also be set toTrue.
Before CDCS 2.6, some fields of the database contained direct references to the XML format. In particular, the property
to read the content of an XML data was calledxml_content. When adding support for new formats, these fields have
been renamed to not be tied to a specific format, thusData.xml_contentwas renamedData.content. The change also
impacted REST APIs, and data upload would need to set acontentfield, and responses would return acontentfield. For users that are not ready to migrate their scripts to the new configuration yet, a setting has been added to
continue acceptingxml_contentinstead ofcontentin the REST API. It is recommended to setBACKWARD_COMPATIBILITY_DATA_XML_CONTENTtoFalsewhen ready to make the move to JSON Support and start usingData.content.