This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from "vue"; | |
import Vuex from "vuex"; | |
import _ from "lodash"; | |
Vue.use(Vuex); | |
let API_URL = "http://localhost:8000/api"; | |
export default new Vuex.Store({ | |
state: { | |
status: false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="vue"> | |
<h2>These are some examples of how to do two-way bindings</h2> | |
<child v-model="stuff"></child> | |
{{stuff}} | |
<hr> | |
<selector v-model="selected"></selector> | |
{{selected}} | |
<hr> | |
<multi-sync :first_name.sync="user.first_name" :last_name.sync="user.last_name"></multi-sync> | |
{{user}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/questions/17988939/find-and-update-in-nested-json-object/17991517 | |
// update set key_to_update = value_to_be_set where key = key_to_be_mached | |
// this.searchObjects(json_object,"key", "key_to_be_mached", "key_to_update", "value_to_be_set") | |
searchObjects(obj, search_key, search_val, replace_key, replace_value) { | |
var replaceValue = replace_value; | |
var objects = []; | |
for (var key in obj) { | |
if (!obj.hasOwnProperty(key)) continue; | |
if (typeof obj[key] == "object") { | |
objects = objects.concat( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// find "key_name" and set value "value_to_be_set" | |
// replacePropertyValue(json_object, "key_name", "value_to_be_set"); | |
replacePropertyValue(obj, search_key, replace_value) { | |
var replaceValue = replace_value; | |
for (var key in obj) { | |
if (!obj.hasOwnProperty(key)) continue; | |
if (typeof obj[key] == "object") { | |
this.replacePropertyValue( | |
obj[key], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in DRF DestroyModelMixin delete row. Using Same DELETE method I can soft delete object. | |
# ex: URL - DELETE https://<hostnam>/api/v1/books/1/ | |
from rest_framework import mixins, permissions, viewsets | |
from rest_framework.response import Response | |
from rest_framework import status | |
class SlSoftDeleteMixin(mixins.DestroyModelMixin): | |
""" As we are deleting soft""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Count, Max | |
unique_fields = ['field_1', 'field_2'] | |
duplicates = ( | |
MyModel.objects.values(*unique_fields) | |
.order_by() | |
.annotate(max_id=Max('id'), count_id=Count('id')) | |
.filter(count_id__gt=1) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Count, Max | |
unique_fields = ['field_1', 'field_2'] | |
duplicates = ( | |
MyModel.objects.values(*unique_fields) | |
.order_by() | |
.annotate(max_id=Max('id'), count_id=Count('id')) | |
.filter(count_id__gt=1) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DynamicFieldsModelSerializer(serializers.ModelSerializer): | |
def __init__(self, *args, **kwargs): | |
request = kwargs.get('context', {}).get('request', None) | |
exclude = kwargs.pop('exclude', []) | |
exclude_str = request.GET.get('exclude', None) if request else None | |
exclude_str_list = exclude_str.split(',') if exclude_str else [] | |
exclude = list(set(exclude + exclude_str_list)) | |
super(DynamicFieldsModelSerializer, self).__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tables = tabula.read_pdf('https://www.who.int/docs/default-source/coronaviruse/situation-reports/20200715-covid-19-sitrep-177.pdf', pages="all", multiple_tables=True) | |
countries = [] | |
for data_frame in tables: | |
data_dicts = data_frame.T.to_dict().values() | |
for data_item in data_dicts: | |
for key in data_item: | |
if 'Country' in key: # if key is 'Reporting Country/Territory/Area' | |
country = find(who_name=data_item[key]) # if Country Exists in the List | |
if country: | |
confirmed = data_item.get('Total confirmed', None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url = "https://globalhealth5050.org/covid19/sex-disaggregated-data-tracker/" | |
html_content = requests.get(url).text | |
soup = BeautifulSoup(html_content, "lxml") | |
table_rows = soup.find("table", attrs={"id": "table_1"}).find("tbody").find_all("tr") | |
for row in table_rows: | |
cells = row.find_all("td") | |
country_code = cells[0].get_text() | |
country = find(country_code=country_code) | |
date = cells[3].get_text() | |
cases_percentage_male = cells[5].get_text() |