Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Default Behavior to Create Model Example #190

Closed
bryanculver opened this issue Oct 17, 2024 · 2 comments
Closed

Change Default Behavior to Create Model Example #190

bryanculver opened this issue Oct 17, 2024 · 2 comments
Assignees

Comments

@bryanculver
Copy link
Member

Provide the user the option to override the initial model name created but the current default behavior skips generating these files which then gets lost when managing drift as well as forces the user to manually create these files, often far adrift from standard.

if "{{ cookiecutter.model_class_name }}" == "None":
files_to_remove = [
"api/__init__.py",
"api/serializers.py",
"api/urls.py",
"api/views.py",
"filters.py",
"forms.py",
"migrations/__init__.py",
"models.py",
"navigation.py",
"tables.py",
"templates/{{ cookiecutter.app_name }}/{{ cookiecutter.model_class_name.lower() }}_retrieve.html",
"tests/fixtures.py",
"tests/test_api_views.py",
"tests/test_filter_{{ cookiecutter.model_class_name.lower() }}.py",
"tests/test_form_{{ cookiecutter.model_class_name.lower() }}.py",
"tests/test_model_{{ cookiecutter.model_class_name.lower() }}.py",
"tests/test_views.py",
"urls.py",
"views.py",
]

To resolve the "missed when drift managed" issue in other Apps, update the .cookiecutter.json file in the repo to have model_class_name be the name of one of the models in the App (ex: "model_class_name": "GoldenConfig" for Golden Config). The value should be left as "None" for any App that does not contain any models.

@gsnider2195
Copy link
Contributor

It looks like cookiecutter doesn't provide us with any advanced prompt manipulation so I propose we set the default model_class_name to {{ cookiecutter.camel_name }}ExampleModel }} and modify the prompt to let the user know to set it to None for no model:

{
    "codeowner_github_usernames": "",
    "full_name": "Network to Code, LLC",
    "email": "[email protected]",
    "github_org": "nautobot",
    "app_name": "my_app",
    "verbose_name": "{{ cookiecutter.app_name.title().replace('_', ' ') }}",
    "app_slug": "{{ cookiecutter.app_name.lower().replace(' ', '-').replace('_', '-') }}",
    "project_slug": "nautobot-app-{{ cookiecutter.app_slug }}",
    "repo_url": "https://github.com/{{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}",
    "base_url": "{{ cookiecutter.app_slug }}",
    "min_nautobot_version": "2.0.0",
    "max_nautobot_version": "2.9999",
    "camel_name": "{{ cookiecutter.app_slug.title().replace(' ', '').replace('-', '') }}",
    "project_short_description": "{{ cookiecutter.verbose_name }}",
    "model_class_name": "{{ cookiecutter.camel_name }}ExampleModel",
    "open_source_license": [
        "Apache-2.0",
        "Not open source"
    ],
    "docs_base_url": "https://docs.nautobot.com",
    "docs_app_url": "{{ cookiecutter.docs_base_url }}/projects/{{ cookiecutter.app_slug }}/en/latest",
    "__prompts__": {
        "model_class_name": "Select the name of your first database model. Set to 'None' if this app will have no models."
    }
}

@smk4664
Copy link
Contributor

smk4664 commented Oct 21, 2024

  • "bgp-models"
    • Contact Marek to review
  • "capacity-metrics"
    • Apps Team
  • "chatops"
    • Contact Stephen Kiely :)
  • "circuit-maintenance"
    • Contact Stephen Corry
  • "data-validation-engine"
    • Contact Steven Weiblinger
  • "dev-example"
    • Apps team
  • "device-lifecycle-mgmt"
    • Contact Przemek and Brad Haas
  • "device-onboarding"
    • Contact Stephen Corry
  • "firewall-models"
    • Apps Team to review and merge
  • "floor-plan"
    • Contact Glenn
  • "golden-config"
    • Contact Ken
  • "netbox-importer"
    • Apps team to review and merge
  • "nornir-app"
    • Contact ??
  • "secrets-providers"
    • Contact core team
  • "ssot"
    • Contact Justin Drew
  • "welcome-wizard"
    • Contact Stephen Kiely :)

@smk4664 smk4664 self-assigned this Oct 22, 2024
@smk4664 smk4664 closed this as completed Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants