prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  ATMO should pre-click my single SSH key
  Would save me thousands of milliseconds every time I launch a cluster ;)
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `atmo/clusters/views.py`
  Content:
  ```
  1 # This Source Code Form is subject to the terms of the Mozilla Public
  2 # License, v. 2.0. If a copy of the MPL was not distributed with this
  3 # file, you can obtain one at http://mozilla.org/MPL/2.0/.
  4 from django.contrib import messages
  5 from django.contrib.auth.decorators import login_required
  6 from django.shortcuts import redirect, render
  7 from django.utils.safestring import mark_safe
  8 
  9 from allauth.account.utils import user_display
  10 
  11 from .forms import NewClusterForm
  12 from .models import Cluster
  13 from ..decorators import view_permission_required, delete_permission_required
  14 
  15 
  16 @login_required
  17 def new_cluster(request):
  18     if request.user.created_sshkeys.count() == 0:
  19         messages.error(
  20             request,
  21             mark_safe(
  22                 '<h4>No SSH keys associated to you.</h4>'
  23                 'Please upload one below to be able to launch a cluster.'
  24                 'This is one-time step.'
  25             )
  26         )
  27         return redirect('keys-new')
  28     initial = {
  29         'identifier': '{}-telemetry-analysis'.format(user_display(request.user)),
  30         'size': 1,
  31     }
  32     form = NewClusterForm(
  33         request.user,
  34         initial=initial,
  35     )
  36     if request.method == 'POST':
  37         form = NewClusterForm(
  38             request.user,
  39             data=request.POST,
  40             files=request.FILES,
  41             initial=initial,
  42         )
  43         if form.is_valid():
  44             cluster = form.save()  # this will also magically spawn the cluster for us
  45             return redirect(cluster)
  46     context = {
  47         'form': form,
  48     }
  49     return render(request, 'atmo/clusters/new.html', context)
  50 
  51 
  52 @login_required
  53 @delete_permission_required(Cluster)
  54 def terminate_cluster(request, id):
  55     cluster = Cluster.objects.get(id=id)
  56     if not cluster.is_active:
  57         return redirect(cluster)
  58 
  59     if request.method == 'POST':
  60         cluster.deactivate()
  61         return redirect(cluster)
  62 
  63     context = {
  64         'cluster': cluster,
  65     }
  66     return render(request, 'atmo/clusters/terminate.html', context=context)
  67 
  68 
  69 @login_required
  70 @view_permission_required(Cluster)
  71 def detail_cluster(request, id):
  72     cluster = Cluster.objects.get(id=id)
  73     context = {
  74         'cluster': cluster,
  75     }
  76     return render(request, 'atmo/clusters/detail.html', context=context)
  77
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/atmo/clusters/views.py b/atmo/clusters/views.py
  --- a/atmo/clusters/views.py
  +++ b/atmo/clusters/views.py
  @@ -15,7 +15,13 @@
   
   @login_required
   def new_cluster(request):
  -    if request.user.created_sshkeys.count() == 0:
  +    initial = {
  +        'identifier': '{}-telemetry-analysis'.format(user_display(request.user)),
  +        'size': 1,
  +    }
  +    ssh_key_count = request.user.created_sshkeys.count()
  +
  +    if ssh_key_count == 0:
           messages.error(
               request,
               mark_safe(
  @@ -25,10 +31,10 @@
               )
           )
           return redirect('keys-new')
  -    initial = {
  -        'identifier': '{}-telemetry-analysis'.format(user_display(request.user)),
  -        'size': 1,
  -    }
  +    elif ssh_key_count == 1:
  +        # If only 1 ssh key, make it pre-selected.
  +        initial['ssh_key'] = request.user.created_sshkeys.values('pk')[0]['pk']
  +
       form = NewClusterForm(
           request.user,
           initial=initial,
  
verification_info: {"golden_diff": "diff --git a/atmo/clusters/views.py b/atmo/clusters/views.py\n--- a/atmo/clusters/views.py\n+++ b/atmo/clusters/views.py\n@@ -15,7 +15,13 @@\n \n @login_required\n def new_cluster(request):\n-    if request.user.created_sshkeys.count() == 0:\n+    initial = {\n+        'identifier': '{}-telemetry-analysis'.format(user_display(request.user)),\n+        'size': 1,\n+    }\n+    ssh_key_count = request.user.created_sshkeys.count()\n+\n+    if ssh_key_count == 0:\n         messages.error(\n             request,\n             mark_safe(\n@@ -25,10 +31,10 @@\n             )\n         )\n         return redirect('keys-new')\n-    initial = {\n-        'identifier': '{}-telemetry-analysis'.format(user_display(request.user)),\n-        'size': 1,\n-    }\n+    elif ssh_key_count == 1:\n+        # If only 1 ssh key, make it pre-selected.\n+        initial['ssh_key'] = request.user.created_sshkeys.values('pk')[0]['pk']\n+\n     form = NewClusterForm(\n         request.user,\n         initial=initial,\n", "issue": "ATMO should pre-click my single SSH key\nWould save me thousands of milliseconds every time I launch a cluster ;)\n", "before_files": [{"content": "# This Source Code Form is subject to the terms of the Mozilla Public\n# License, v. 2.0. If a copy of the MPL was not distributed with this\n# file, you can obtain one at http://mozilla.org/MPL/2.0/.\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required\nfrom django.shortcuts import redirect, render\nfrom django.utils.safestring import mark_safe\n\nfrom allauth.account.utils import user_display\n\nfrom .forms import NewClusterForm\nfrom .models import Cluster\nfrom ..decorators import view_permission_required, delete_permission_required\n\n\n@login_required\ndef new_cluster(request):\n    if request.user.created_sshkeys.count() == 0:\n        messages.error(\n            request,\n            mark_safe(\n                '<h4>No SSH keys associated to you.</h4>'\n                'Please upload one below to be able to launch a cluster.'\n                'This is one-time step.'\n            )\n        )\n        return redirect('keys-new')\n    initial = {\n        'identifier': '{}-telemetry-analysis'.format(user_display(request.user)),\n        'size': 1,\n    }\n    form = NewClusterForm(\n        request.user,\n        initial=initial,\n    )\n    if request.method == 'POST':\n        form = NewClusterForm(\n            request.user,\n            data=request.POST,\n            files=request.FILES,\n            initial=initial,\n        )\n        if form.is_valid():\n            cluster = form.save()  # this will also magically spawn the cluster for us\n            return redirect(cluster)\n    context = {\n        'form': form,\n    }\n    return render(request, 'atmo/clusters/new.html', context)\n\n\n@login_required\n@delete_permission_required(Cluster)\ndef terminate_cluster(request, id):\n    cluster = Cluster.objects.get(id=id)\n    if not cluster.is_active:\n        return redirect(cluster)\n\n    if request.method == 'POST':\n        cluster.deactivate()\n        return redirect(cluster)\n\n    context = {\n        'cluster': cluster,\n    }\n    return render(request, 'atmo/clusters/terminate.html', context=context)\n\n\n@login_required\n@view_permission_required(Cluster)\ndef detail_cluster(request, id):\n    cluster = Cluster.objects.get(id=id)\n    context = {\n        'cluster': cluster,\n    }\n    return render(request, 'atmo/clusters/detail.html', context=context)\n", "path": "atmo/clusters/views.py"}], "after_files": [{"content": "# This Source Code Form is subject to the terms of the Mozilla Public\n# License, v. 2.0. If a copy of the MPL was not distributed with this\n# file, you can obtain one at http://mozilla.org/MPL/2.0/.\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required\nfrom django.shortcuts import redirect, render\nfrom django.utils.safestring import mark_safe\n\nfrom allauth.account.utils import user_display\n\nfrom .forms import NewClusterForm\nfrom .models import Cluster\nfrom ..decorators import view_permission_required, delete_permission_required\n\n\n@login_required\ndef new_cluster(request):\n    initial = {\n        'identifier': '{}-telemetry-analysis'.format(user_display(request.user)),\n        'size': 1,\n    }\n    ssh_key_count = request.user.created_sshkeys.count()\n\n    if ssh_key_count == 0:\n        messages.error(\n            request,\n            mark_safe(\n                '<h4>No SSH keys associated to you.</h4>'\n                'Please upload one below to be able to launch a cluster.'\n                'This is one-time step.'\n            )\n        )\n        return redirect('keys-new')\n    elif ssh_key_count == 1:\n        # If only 1 ssh key, make it pre-selected.\n        initial['ssh_key'] = request.user.created_sshkeys.values('pk')[0]['pk']\n\n    form = NewClusterForm(\n        request.user,\n        initial=initial,\n    )\n    if request.method == 'POST':\n        form = NewClusterForm(\n            request.user,\n            data=request.POST,\n            files=request.FILES,\n            initial=initial,\n        )\n        if form.is_valid():\n            cluster = form.save()  # this will also magically spawn the cluster for us\n            return redirect(cluster)\n    context = {\n        'form': form,\n    }\n    return render(request, 'atmo/clusters/new.html', context)\n\n\n@login_required\n@delete_permission_required(Cluster)\ndef terminate_cluster(request, id):\n    cluster = Cluster.objects.get(id=id)\n    if not cluster.is_active:\n        return redirect(cluster)\n\n    if request.method == 'POST':\n        cluster.deactivate()\n        return redirect(cluster)\n\n    context = {\n        'cluster': cluster,\n    }\n    return render(request, 'atmo/clusters/terminate.html', context=context)\n\n\n@login_required\n@view_permission_required(Cluster)\ndef detail_cluster(request, id):\n    cluster = Cluster.objects.get(id=id)\n    context = {\n        'cluster': cluster,\n    }\n    return render(request, 'atmo/clusters/detail.html', context=context)\n", "path": "atmo/clusters/views.py"}]}