{"schemaVersion":1,"contentVersion":"3.4.0","id":"intermediate.17","languages":{"javascript":{"id":"intermediate.17","title":"Checkpoint: rearrange lines in real files","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Move, copy and delete whole lines in each of three real files, with one more change alongside.</p><p><strong>Before this lesson:</strong> Copying and moving lines, and the module's repeats.</p><p>You choose the commands here. dd and p move a line, P puts it above, and yyp copies one so you can change the copy. Each file also has a change that the dot, cgn or Ctrl-v makes quicker. Getting it right matters more than the number of keys.</p><h3>Example</h3><p>Before you finish in Normal mode, check the order of the lines and the changes one at a time.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"Put <code>/orders</code> above <code>/orders/:id</code>, and add a <code>/returns</code> route below <code>/orders</code>, like it, with the <code>Returns</code> page. The admin pages aren't ready, so comment out their three routes. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"jsx","start":"import { Account, AdminOrders, AdminProducts, AdminUsers, Home, NotFound, OrderDetail, Orders, Returns } from \"./pages\";\n\n// React Router tries these in order and uses the first that matches.\nexport const routes = [\n  { path: \"/\", element: <Home /> },\n  { path: \"/orders/:id\", element: <OrderDetail /> },\n  { path: \"/orders\", element: <Orders /> },\n  { path: \"/account\", element: <Account /> },\n  { path: \"/admin/orders\", element: <AdminOrders /> },\n  { path: \"/admin/products\", element: <AdminProducts /> },\n  { path: \"/admin/users\", element: <AdminUsers /> },\n  { path: \"*\", element: <NotFound /> },\n];","startCursor":{"line":2,"ch":0},"paths":[{"keys":["3","j","d","d","p","k","y","y","p","c","i","\"","/returns","<Esc>","f","O","c","i","w","Returns","<Esc>","3","j","^","<C-v>","2","j","I","// ","<Esc>"],"tier":"idiomatic","technique":"linewise","core":["linewise","put:p","visual:<C-v>"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import { Account, AdminOrders, AdminProducts, AdminUsers, Home, NotFound, OrderDetail, Orders, Returns } from \"./pages\";\n\n// React Router tries these in order and uses the first that matches.\nexport const routes = [\n  { path: \"/\", element: <Home /> },\n  { path: \"/orders\", element: <Orders /> },\n  { path: \"/returns\", element: <Returns /> },\n  { path: \"/orders/:id\", element: <OrderDetail /> },\n  { path: \"/account\", element: <Account /> },\n  // { path: \"/admin/orders\", element: <AdminOrders /> },\n  // { path: \"/admin/products\", element: <AdminProducts /> },\n  // { path: \"/admin/users\", element: <AdminUsers /> },\n  { path: \"*\", element: <NotFound /> },\n];","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.17#0","canonicalFingerprint":"1l7xi60"},{"task":"Designers want the badge above the image and the price right under the name. Move them there. The prop is called <code>item</code> now, so rename <code>product</code> everywhere except the <code>product-card</code> class. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"jsx","start":"import { formatPrice } from \"../lib/money\";\n\nexport function CatalogCard({ product, onAdd }) {\n  return (\n    <article className=\"product-card\">\n      <img src={product.imageUrl} alt=\"\" />\n      {product.isNew && <span className=\"badge\">New</span>}\n      <h3>{product.name}</h3>\n      <p className=\"description\">{product.summary}</p>\n      <p className=\"price\">{formatPrice(product.price)}</p>\n      <button onClick={() => onAdd(product)}>Add to cart</button>\n    </article>\n  );\n}","startCursor":{"line":0,"ch":0},"paths":[{"keys":["5","j","d","d","p","3","j","d","d","k","P","/","product","<CR>","c","g","n","item","<Esc>",".",".",".","n","n",".",".","."],"tier":"idiomatic","technique":"linewise","core":["linewise","put:P","motion:gn"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import { formatPrice } from \"../lib/money\";\n\nexport function CatalogCard({ item, onAdd }) {\n  return (\n    <article className=\"product-card\">\n      {item.isNew && <span className=\"badge\">New</span>}\n      <img src={item.imageUrl} alt=\"\" />\n      <h3>{item.name}</h3>\n      <p className=\"price\">{formatPrice(item.price)}</p>\n      <p className=\"description\">{item.summary}</p>\n      <button onClick={() => onAdd(item)}>Add to cart</button>\n    </article>\n  );\n}","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.17#1","canonicalFingerprint":"u71w2j"},{"task":"Put Sale first in the main menu and move Help to the end of the footer. We've stopped selling gift cards and closed the blog, so delete those two links. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"jsx","start":"// Links in the header and the footer, in the order they're shown.\nexport const mainMenu = [\n  { label: \"New in\", href: \"/new\" },\n  { label: \"Clothing\", href: \"/clothing\" },\n  { label: \"Gift cards\", href: \"/gift-cards\" },\n  { label: \"Help\", href: \"/help\" },\n  { label: \"Home\", href: \"/home\" },\n  { label: \"Sale\", href: \"/sale\", highlight: true },\n];\n\nexport const footerMenu = [\n  { label: \"Delivery\", href: \"/delivery\" },\n  { label: \"Returns\", href: \"/returns\" },\n  { label: \"Blog\", href: \"/blog\" },\n  { label: \"Contact us\", href: \"/contact\" },\n];","startCursor":{"line":1,"ch":0},"paths":[{"keys":["6","j","d","d","g","g","j","p","4","j","d","d","7","j","p","2","k","d","d","7","k","."],"tier":"idiomatic","technique":"linewise","core":["linewise","put:p","dot"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"// Links in the header and the footer, in the order they're shown.\nexport const mainMenu = [\n  { label: \"Sale\", href: \"/sale\", highlight: true },\n  { label: \"New in\", href: \"/new\" },\n  { label: \"Clothing\", href: \"/clothing\" },\n  { label: \"Home\", href: \"/home\" },\n];\n\nexport const footerMenu = [\n  { label: \"Delivery\", href: \"/delivery\" },\n  { label: \"Returns\", href: \"/returns\" },\n  { label: \"Contact us\", href: \"/contact\" },\n  { label: \"Help\", href: \"/help\" },\n];","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.17#2","canonicalFingerprint":"1c491ns"}]},"python":{"id":"intermediate.17","title":"Checkpoint: rearrange lines in real files","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Move, copy and delete whole lines in each of three real files, with one more change alongside.</p><p><strong>Before this lesson:</strong> Copying and moving lines, and the module's repeats.</p><p>You choose the commands here. dd and p move a line, P puts it above, and yyp copies one so you can change the copy. Each file also has a change that the dot, cgn or Ctrl-v makes quicker. Getting it right matters more than the number of keys.</p><h3>Example</h3><p>Before you finish in Normal mode, check the order of the lines and the changes one at a time.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"Put <code>orders/</code> above <code>orders/&lt;number&gt;/</code>, and add a <code>returns/</code> path below <code>orders/</code>, like it, with <code>views.returns</code> and the name <code>returns</code>. The admin views aren't ready, so comment out their three paths. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"python","start":"from django.urls import path\n\nfrom . import views\n\n# Django tries these in order and uses the first that matches.\nurlpatterns = [\n    path(\"\", views.home, name=\"home\"),\n    path(\"orders/<number>/\", views.order_detail, name=\"order-detail\"),\n    path(\"orders/\", views.orders, name=\"orders\"),\n    path(\"account/\", views.account, name=\"account\"),\n    path(\"staff/orders/\", views.staff_orders, name=\"staff-orders\"),\n    path(\"staff/products/\", views.staff_products, name=\"staff-products\"),\n    path(\"staff/users/\", views.staff_users, name=\"staff-users\"),\n]","startCursor":{"line":4,"ch":0},"paths":[{"keys":["3","j","d","d","p","k","y","y","p","c","i","\"","returns/","<Esc>","f","o","c","i","w","returns","<Esc>","f","o",".","3","j","^","<C-v>","2","j","I","# ","<Esc>"],"tier":"idiomatic","technique":"linewise","core":["linewise","put:p","visual:<C-v>"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"from django.urls import path\n\nfrom . import views\n\n# Django tries these in order and uses the first that matches.\nurlpatterns = [\n    path(\"\", views.home, name=\"home\"),\n    path(\"orders/\", views.orders, name=\"orders\"),\n    path(\"returns/\", views.returns, name=\"returns\"),\n    path(\"orders/<number>/\", views.order_detail, name=\"order-detail\"),\n    path(\"account/\", views.account, name=\"account\"),\n    # path(\"staff/orders/\", views.staff_orders, name=\"staff-orders\"),\n    # path(\"staff/products/\", views.staff_products, name=\"staff-products\"),\n    # path(\"staff/users/\", views.staff_users, name=\"staff-users\"),\n]","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.17#0","canonicalFingerprint":"1l7xi60"},{"task":"Put the tracking link right under the greeting and the delivery estimate last. The template calls it <code>parcel</code> now, so rename <code>shipment</code> everywhere except the <code>shipment_email</code> function name. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"python","start":"from shop.emails.sending import send_lines\n\n\ndef shipment_email(shipment):\n    lines = [\n        f\"Hi {shipment.order.first_name},\",\n        f\"It should arrive by {shipment.estimate:%A %d %B}.\",\n        f\"Your order {shipment.order.number} is on its way.\",\n        f\"Track it here: {shipment.tracking_url}\",\n        \"Thanks for shopping with Northwind.\",\n    ]\n    send_lines(shipment.order.email, \"Your order is on its way\", lines)","startCursor":{"line":0,"ch":0},"paths":[{"keys":["6","j","d","d","j","p","k","d","d","k","P","/","shipment","<CR>","c","g","n","parcel","<Esc>",".",".",".","n","n",".","."],"tier":"idiomatic","technique":"linewise","core":["linewise","put:p","motion:gn"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"from shop.emails.sending import send_lines\n\n\ndef shipment_email(parcel):\n    lines = [\n        f\"Hi {parcel.order.first_name},\",\n        f\"Track it here: {parcel.tracking_url}\",\n        f\"Your order {parcel.order.number} is on its way.\",\n        f\"It should arrive by {parcel.estimate:%A %d %B}.\",\n        \"Thanks for shopping with Northwind.\",\n    ]\n    send_lines(parcel.order.email, \"Your order is on its way\", lines)","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.17#1","canonicalFingerprint":"u71w2j"},{"task":"Security headers have to come first, so move <code>SecurityMiddleware</code> to the top of the list, and move <code>WhiteNoiseMiddleware</code> right below it. We've dropped the old locale and timing middleware, so delete those two lines. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"python","start":"# Django runs these top to bottom on the way in and bottom to top on the way out.\nMIDDLEWARE = [\n    \"django.contrib.sessions.middleware.SessionMiddleware\",\n    \"django.middleware.security.SecurityMiddleware\",\n    \"shop.middleware.LegacyLocaleMiddleware\",\n    \"django.middleware.common.CommonMiddleware\",\n    \"django.middleware.csrf.CsrfViewMiddleware\",\n    \"django.contrib.auth.middleware.AuthenticationMiddleware\",\n    \"shop.middleware.RequestTimingMiddleware\",\n    \"whitenoise.middleware.WhiteNoiseMiddleware\",\n]","startCursor":{"line":1,"ch":0},"paths":[{"keys":["j","d","d","p","G","k","d","d","g","g","2","j","p","2","j","d","d","3","j","."],"tier":"idiomatic","technique":"linewise","core":["linewise","put:p","dot"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"# Django runs these top to bottom on the way in and bottom to top on the way out.\nMIDDLEWARE = [\n    \"django.middleware.security.SecurityMiddleware\",\n    \"whitenoise.middleware.WhiteNoiseMiddleware\",\n    \"django.contrib.sessions.middleware.SessionMiddleware\",\n    \"django.middleware.common.CommonMiddleware\",\n    \"django.middleware.csrf.CsrfViewMiddleware\",\n    \"django.contrib.auth.middleware.AuthenticationMiddleware\",\n]","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.17#2","canonicalFingerprint":"1c491ns"}]},"text":{"id":"intermediate.17","title":"Checkpoint: rearrange lines in real files","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Move, copy and delete whole lines in each of three real files, with one more change alongside.</p><p><strong>Before this lesson:</strong> Copying and moving lines, and the module's repeats.</p><p>You choose the commands here. dd and p move a line, P puts it above, and yyp copies one so you can change the copy. Each file also has a change that the dot, cgn or Ctrl-v makes quicker. Getting it right matters more than the number of keys.</p><h3>Example</h3><p>Before you finish in Normal mode, check the order of the lines and the changes one at a time.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"Put the setup steps in the order you run them: copy the env file, then <code>npm ci</code>, then <code>npm run dev</code>. Make the four lines under Run it on your laptop a list, each starting with <code>- </code>. Then add <code>npm run test:e2e</code> below <code>npm run test:unit</code>. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"text/plain","start":"# Northwind admin\n\nThe back office for Northwind Outdoor: orders, refunds and stock.\n\n## Run it on your laptop\nnpm ci\nnpm run dev\ncp .env.example .env\nAsk Dana for the Stripe test keys.\n\n## Tests\nnpm run test:unit\nCI runs every test again on each pull request.","startCursor":{"line":2,"ch":0},"paths":[{"keys":["5","j","d","d","2","k","P","<C-v>","3","j","I","- ","<Esc>","6","j","y","y","p","$","c","i","w","e2e","<Esc>"],"tier":"idiomatic","technique":"linewise","core":["linewise","put:P","visual:<C-v>"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"# Northwind admin\n\nThe back office for Northwind Outdoor: orders, refunds and stock.\n\n## Run it on your laptop\n- cp .env.example .env\n- npm ci\n- npm run dev\n- Ask Dana for the Stripe test keys.\n\n## Tests\nnpm run test:unit\nnpm run test:e2e\nCI runs every test again on each pull request.","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.17#0","canonicalFingerprint":"1l7xi60"},{"task":"Pay with a gift card shipped in 4.3, so move it to the top of 4.3.0, and faster search was 4.2, so move it to the end of 4.2.0. Mark the two entries that change the API with <code> (breaking)</code>. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"text/plain","start":"# Changelog\n\n## 4.3.0\n- Saved addresses at checkout\n- Orders API returns prices in cents\n- Faster search on the catalog pages\n\n## 4.2.0\n- Dutch translations for every email\n- Pay with a gift card at checkout\n- Start a return from the order page\n- Products API drops the old size field","startCursor":{"line":0,"ch":0},"paths":[{"keys":["5","j","d","d","G","p","k","A"," (breaking)","<Esc>","6","k",".","4","j","d","d","5","k","P"],"tier":"idiomatic","technique":"linewise","core":["linewise","put:P","dot"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"# Changelog\n\n## 4.3.0\n- Pay with a gift card at checkout\n- Saved addresses at checkout\n- Orders API returns prices in cents (breaking)\n\n## 4.2.0\n- Dutch translations for every email\n- Start a return from the order page\n- Products API drops the old size field (breaking)\n- Faster search on the catalog pages","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.17#1","canonicalFingerprint":"u71w2j"},{"task":"The env file belongs under Local settings, with <code>.env.local</code> below it. We don't use Parcel or Bower any more, so delete their two lines. You can use any commands.","hint":"Move whole lines with dd and p or P, and copy one with yy before you change the copy.","mode":"text/plain","start":"# Dependencies\nnode_modules/\n.env\nbower_components/\n\n# Build output\ndist/\ncoverage/\n.parcel-cache/\n\n# Local settings\n.DS_Store\n.vscode/","startCursor":{"line":0,"ch":0},"paths":[{"keys":["2","j","d","d","G","p","y","y","p","A",".local","<Esc>","?","bo","<CR>","d","d","4","j","."],"tier":"idiomatic","technique":"linewise","core":["linewise","put:p","dot"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"# Dependencies\nnode_modules/\n\n# Build output\ndist/\ncoverage/\n\n# Local settings\n.DS_Store\n.vscode/\n.env\n.env.local","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.17#2","canonicalFingerprint":"1c491ns"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Copying and moving lines, and the module's repeats.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Move, copy and delete whole lines in each of three real files, with one more change alongside.</p><p>You choose the commands here. dd and p move a line, P puts it above, and yyp copies one so you can change the copy. Each file also has a change that the dot, cgn or Ctrl-v makes quicker. Getting it right matters more than the number of keys.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you finish in Normal mode, check the order of the lines and the changes one at a time.</p><p>Try without hints first. Open help if you need it.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Copying and moving lines, and the module's repeats.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Move, copy and delete whole lines in each of three real files, with one more change alongside.</p><p>You choose the commands here. dd and p move a line, P puts it above, and yyp copies one so you can change the copy. Each file also has a change that the dot, cgn or Ctrl-v makes quicker. Getting it right matters more than the number of keys.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you finish in Normal mode, check the order of the lines and the changes one at a time.</p><p>Try without hints first. Open help if you need it.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Copying and moving lines, and the module's repeats.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Move, copy and delete whole lines in each of three real files, with one more change alongside.</p><p>You choose the commands here. dd and p move a line, P puts it above, and yyp copies one so you can change the copy. Each file also has a change that the dot, cgn or Ctrl-v makes quicker. Getting it right matters more than the number of keys.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you finish in Normal mode, check the order of the lines and the changes one at a time.</p><p>Try without hints first. Open help if you need it.</p></div></details>"}}}