Skip to content

Commit

Permalink
Merge pull request #303 from Ilhasoft/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
johncordeiro committed Nov 9, 2019
2 parents eeb1f8d + d222588 commit 1a46b30
Show file tree
Hide file tree
Showing 139 changed files with 12,059 additions and 6,852 deletions.
4 changes: 3 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[flake8]
max-line-length = 119
ignore = E501,W503,E203
exclude =
./env
migrations
./manage.py
./manage.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,6 @@ staticfiles/

# OS
.DS_Store

#Pycharm
.idea/
13 changes: 9 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ verify_ssl = true
name = "pypi"

[packages]
django = "==2.1.5"
dj-database-url = "==0.5.0"
python-decouple = "==3.1"
djangorestframework = "==3.9.0"
django = "==2.1.11"
djangorestframework = "==3.9.1"
django-filter = "==2.0.0"
django-cors-headers = "==2.4.0"
requests = "==2.20.1"
coreapi = "==2.3.3"
whitenoise = "==4.1.2"
pytz = "==2018.7"
drf-yasg = "*"
gunicorn = "*"
gevent = "*"
packaging = "*"
django-environ = "*"
boto3 = "*"

[dev-packages]
"flake8" = "*"
coverage = "*"
ipython = "*"
autopep8 = "*"
black = "==19.3b0"

[requires]
python_version = "3.6"
379 changes: 291 additions & 88 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python manage.py migrate && python manage.py fill_db_using_fake_data && gunicorn bothub.wsgi -b 0.0.0.0:\$PORT --log-file -
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<p align="center">
<img src="https://user-images.githubusercontent.com/5360835/65427083-1af35900-de01-11e9-86ef-59f1eee79a68.png" width="230" height="70" alt="Bothub" />
</p>

# Bothub

[![Build Status](https://travis-ci.org/Ilhasoft/bothub-engine.svg?branch=master)](https://travis-ci.org/Ilhasoft/bothub-engine) [![Coverage Status](https://coveralls.io/repos/github/Ilhasoft/bothub-engine/badge.svg?branch=master)](https://coveralls.io/github/Ilhasoft/bothub-engine?branch=master) [![Python Version](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/) [![License GPL-3.0](https://img.shields.io/badge/license-%20GPL--3.0-yellow.svg)](https://github.com/Ilhasoft/bothub-engine/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/Ilhasoft/bothub-engine.svg?branch=master)](https://travis-ci.org/Ilhasoft/bothub-engine)
[![Coverage Status](https://coveralls.io/repos/github/Ilhasoft/bothub-engine/badge.svg?branch=master)](https://coveralls.io/github/Ilhasoft/bothub-engine?branch=master)
[![Code Climate](https://codeclimate.com/github/Ilhasoft/bothub-engine/badges/gpa.svg)](https://codeclimate.com/github/Ilhasoft/bothub-engine)
[![Python Version](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/)
[![License GPL-3.0](https://img.shields.io/badge/license-%20GPL--3.0-yellow.svg)](https://github.com/Ilhasoft/bothub-engine/blob/master/LICENSE)

## Development

Expand All @@ -24,19 +32,39 @@ Use ```make``` commands to ```check_environment```, ```install_requirements```,
Run ```pipenv run python ./manage.py fill_db_using_fake_data``` to fill database using fake data. This can help you to test [Bothub Webapp](https://github.com/Ilhasoft/bothub-webapp).


### Update Repositories Tests

Run ```pipenv run python ./manage.py update_repository_tests``` update repositories to sort by total tests.


### Migrate all training for aws

Run ```pipenv run python ./manage.py transfer_train_aws``` Migrate all trainings to an aws bucket defined in project settings.


#### Fake users infos:

| nickname | email | password | is superuser |
|---|---|---|---|
| admin | admin@bothub.it | admin | yes |
| douglas | douglas@bothub.it | douglas | no |
| user | user@bothub.it | user | no |


## Production

Docker images available in [Bothub's Docker Hub repository](https://hub.docker.com/r/ilha/bothub/).


# Deployment


## Heroku
Host your own Bothub Engine with [One-Click Deploy] (https://heroku.com/deploy).

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)



## Environment Variables

You can set environment variables in your OS, write on ```.env``` file or pass via Docker config.
Expand All @@ -45,6 +73,7 @@ You can set environment variables in your OS, write on ```.env``` file or pass v
|--|--|--|--|
| SECRET_KEY | ```string```| ```None``` | A secret key for a particular Django installation. This is used to provide cryptographic signing, and should be set to a unique, unpredictable value.
| DEBUG | ```boolean``` | ```False``` | A boolean that turns on/off debug mode.
| BASE_URL | ```string``` | ```http://api.bothub.it``` | URL Base Bothub Engine Backend.
| ALLOWED_HOSTS | ```string``` | ```*``` | A list of strings representing the host/domain names that this Django site can serve.
| DEFAULT_DATABASE | ```string``` | ```sqlite:///db.sqlite3``` | Read [dj-database-url](https://github.com/kennethreitz/dj-database-url) to configure the database connection.
| LANGUAGE_CODE | ```string``` | ```en-us``` | A string representing the language code for this installation.This should be in standard [language ID format](https://docs.djangoproject.com/en/2.0/topics/i18n/#term-language-code).
Expand All @@ -66,3 +95,11 @@ You can set environment variables in your OS, write on ```.env``` file or pass v
| BOTHUB_NLP_BASE_URL | ```string``` | ```http://localhost:2657/``` | The bothub-blp production application URL. Used to proxy requests.
| CHECK_ACCESSIBLE_API_URL | ```string``` | ```http://localhost/api/repositories/``` | URL used by ```bothub.health.check.check_accessible_api``` to make a HTTP request. The response status code must be 200.
| SEND_EMAILS | ```boolean``` | ```True``` | Send emails flag.
| BOTHUB_ENGINE_AWS_S3_BUCKET_NAME | ```string``` | ```None``` |
| BOTHUB_ENGINE_AWS_ACCESS_KEY_ID | ```string``` | ```None``` |
| BOTHUB_ENGINE_AWS_SECRET_ACCESS_KEY | ```string``` | ```None``` |
| BOTHUB_ENGINE_AWS_REGION_NAME | ```string``` | ```None``` |
| BOTHUB_ENGINE_AWS_SEND | ```bool``` | ```False``` |
| BOTHUB_BOT_EMAIL | ```string``` | ```bot_repository@bothub.it``` | Email that the system will automatically create for existing repositories that the owner deleted the account
| BOTHUB_BOT_NAME | ```string``` | ```Bot Repository``` | Name that the system will use to create the account
| BOTHUB_BOT_NICKNAME | ```string``` | ```bot_repository``` | Nickname that the system will use to create the account
22 changes: 22 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Bothub Engine",
"image": "heroku/python",
"repository": "https://github.com/Ilhasoft/bothub-engine/",
"logo": "https://avatars0.githubusercontent.com/u/8379703?s=200&v=4",
"keywords": ["bothub", "ia", "django", "python"],
"website": "https://bothub.it",
"addons": [ "heroku-postgresql" ],
"env": {
"DISABLE_COLLECTSTATIC": "1",
"SECRET_KEY": "SK",
"DEBUG": "1"
},
"environments": {
"test": {
"scripts": {
"test-setup": "python manage.py collectstatic --noinput",
"test": "python manage.py test"
}
}
}
}
2 changes: 1 addition & 1 deletion bothub/api/v1/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class ApiConfig(AppConfig):
name = 'api'
name = "api"
20 changes: 11 additions & 9 deletions bothub/api/v1/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TextField(serializers.CharField):

class PasswordField(serializers.CharField):
def __init__(self, *args, **kwargs):
kwargs.pop('trim_whitespace', None)
kwargs.pop("trim_whitespace", None)
super().__init__(trim_whitespace=False, **kwargs)


Expand All @@ -24,33 +24,35 @@ class EntityText(serializers.CharField):

class EntityValueField(serializers.CharField):
def __init__(self, *args, validators=[], **kwargs):
kwargs.pop('max_length', 0)
kwargs.pop('help_text', '')
kwargs.pop("max_length", 0)
kwargs.pop("help_text", "")

value_field = RepositoryEntity._meta.get_field('value')
value_field = RepositoryEntity._meta.get_field("value")

super().__init__(
*args,
max_length=value_field.max_length,
validators=(validators + value_field.validators),
**kwargs)
**kwargs
)

def to_representation(self, obj):
return obj.value


class LabelValueField(serializers.CharField):
def __init__(self, *args, validators=[], **kwargs):
kwargs.pop('max_length', 0)
kwargs.pop('help_text', '')
kwargs.pop("max_length", 0)
kwargs.pop("help_text", "")

value_field = RepositoryEntityLabel._meta.get_field('value')
value_field = RepositoryEntityLabel._meta.get_field("value")

super().__init__(
*args,
max_length=value_field.max_length,
validators=(validators + value_field.validators),
**kwargs)
**kwargs
)

def to_representation(self, obj):
return obj.value
22 changes: 11 additions & 11 deletions bothub/api/v1/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ class Metadata(SimpleMetadata):
def get_field_info(self, field):
field_info = super().get_field_info(field)
if isinstance(field, ModelMultipleChoiceField):
field_info['choices'] = [
field_info["choices"] = [
{
'value': choice_value,
'display_name': force_text(choice_name, strings_only=True)
"value": choice_value,
"display_name": force_text(choice_name, strings_only=True),
}
for choice_value, choice_name in field.choices.items()
]
if hasattr(field, 'style'):
field_info['style'] = field.style
if hasattr(field, "style"):
field_info["style"] = field.style
return field_info


Metadata.label_lookup[ModelMultipleChoiceField] = 'multiple choice'
Metadata.label_lookup[TextField] = 'text'
Metadata.label_lookup[PasswordField] = 'password'
Metadata.label_lookup[serializers.HiddenField] = 'hidden'
Metadata.label_lookup[NewRepositoryExampleEntitySerializer] = 'entity'
Metadata.label_lookup[EntityText] = 'entity text'
Metadata.label_lookup[ModelMultipleChoiceField] = "multiple choice"
Metadata.label_lookup[TextField] = "text"
Metadata.label_lookup[PasswordField] = "password"
Metadata.label_lookup[serializers.HiddenField] = "hidden"
Metadata.label_lookup[NewRepositoryExampleEntitySerializer] = "entity"
Metadata.label_lookup[EntityText] = "entity text"

0 comments on commit 1a46b30

Please sign in to comment.