{"id":94,"date":"2022-04-27T13:54:02","date_gmt":"2022-04-27T13:54:02","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/?p=94"},"modified":"2022-04-27T14:02:02","modified_gmt":"2022-04-27T14:02:02","slug":"deleting-entries","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/2022\/04\/27\/deleting-entries\/","title":{"rendered":"Deleting Entries"},"content":{"rendered":"\n<p>For those wondering, I was successful in pushing my branch up to GitHub. There were 4 linting issues so it was not that bad. Simple things like adding a new line and removing unused imports.<\/p>\n\n\n\n<p>There was a small change I needed to do when my teammate reviewed my code. I had to change the name of a file from \u2018key.json\u2019 to \u2018credentials.json\u2019. This would have been a 10-second fix but unfortunately, I had an issue with my computer and I lost my local copy of the repo. I needed to figure out how to get access to a remote branch. I followed these steps <a href=\"https:\/\/devconnected.com\/how-to-switch-branch-on-git\/\">https:\/\/devconnected.com\/how-to-switch-branch-on-git\/<\/a> and I was able to select the branch I had been working on and submit the updated push request.<\/p>\n\n\n\n<p>I realized while I was starting to implement the database functions for the skills page, I was typing (just change the applications to skills or to contacts):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">db = firestore.client()\napplications = db.connection('applications')<\/pre>\n\n\n\n<p>This would be repeated many times so I decided to extract it into a function. I called it dbConn(). It takes the collection name and makes the connection to the database and retrieves the desired collection. <\/p>\n\n\n\n<p>My first goal was to get the delete functionality working for the jobs page so I can implement it for the skills page next. My thought process was that I needed to target the job I want to delete. To make sure I get the functionality right, I selected one document from firebase and with its ID I was able to call a function that deletes it. I hard-coded an example like this to make sure it works properly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def deleteJob():\n    dbConn('applications').document('3reZRCDZG98lW').delete()\n    return 'deleted'<\/pre>\n\n\n\n<p>Now to make it work with the template and views. For the template in jobs.html, I added an indexing system that gives each entry in the table their jobID. This will make it so if they push the delete button, it will send that jobID to a new view. This view is<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">'\/jobs\/&lt;jobID&gt;\/delete'<\/pre>\n\n\n\n<p>Now that I passed the jobID, I can call my deleteJob function and then redirect to the jobs page again but this time the entry will not show up on the table because it was successfully deleted.<\/p>\n\n\n\n<p>After that, I started working on implementing the skills page. There were a lot of similar techniques that I used from the jobs\/internship page.<\/p>\n\n\n\n<p>Found a cool trick! You can add more data in the render_template:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">return render_template('skills\/skills.html', skills=skills, jobs=jobs)<\/pre>\n\n\n\n<p>This is how I was able to show all the jobs in the template.<\/p>\n\n\n\n<p>The hardest part was figuring out how to make a drop-down of the positions and then adding that to the list of the application<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{% for n in jobs%}\n   &lt;option&gt;{{n.position}}-{{n.company}}&lt;\/option&gt;\n{%endfor%}\n<\/pre>\n\n\n\n<p>I made a delete modal because I wanted to reuse it for the other pages.<\/p>\n\n\n\n<p>This post from StackOverflow really helped me with the \u2018with\u2019 feature of jinja2.<\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/9404990\/how-to-pass-selected-named-arguments-to-jinja2s-include-context\">https:\/\/stackoverflow.com\/questions\/9404990\/how-to-pass-selected-named-arguments-to-jinja2s-include-context<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{% with val='skills\/'+ skills[n].id + '\/delete' %}\n    {% include 'deleteModal.html'%}\n{% endwith %}<\/pre>\n\n\n\n<p>What&#8217;s happening here is I am including the delete modal but with the &#8216;val&#8217; variable. The variable is string \u2018skills\/&lt;skillID&gt;\/delete\u2019<\/p>\n\n\n\n<p>And in the deleteModal.html file, I have a link that goes to that route when clicked:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;a href={{val}}&gt;&lt;button type=\"button\" class=\"btn btn-danger\"&gt;Delete&lt;\/button&gt;&lt;\/a&gt;<\/pre>\n\n\n\n<p>I did the same for the jobs page.<\/p>\n\n\n\n<p>Found out also, that if you add a job or skill and there is no such collection, the way my code is set up is that it will create it for you with the auto-ID setting. I like this but I am not sure if this will impose potential threats.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For those wondering, I was successful in pushing my branch up to GitHub. There were 4 linting issues so it was not that bad. Simple things like adding a new line and removing unused imports. There was a small change I needed to do when my teammate reviewed my code. I had to change the [&hellip;]<\/p>\n","protected":false},"author":12178,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/users\/12178"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":14,"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":111,"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/posts\/94\/revisions\/111"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/projectacuarioj\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}