-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from fako/development
Development
- Loading branch information
Showing
45 changed files
with
722 additions
and
292 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .individual import Individual | ||
from .collective import Collective | ||
from .growth import Growth | ||
from .community import Community | ||
from .community import Community, CommunityCollectionDocumentMixin |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
from django.db.models.query import Q | ||
|
||
from core.processors.base import QuerySetProcessor | ||
from datagrowth.datatypes import DocumentPostgres | ||
|
||
|
||
class FilterProcessor(QuerySetProcessor): | ||
|
||
def get_query_filter_for_postgres(self, criteria): | ||
query_filter = Q() | ||
for key, values in criteria.items(): | ||
for value in values: | ||
query_filter |= Q(**{"properties__{}".format(key): value}) | ||
return query_filter | ||
|
||
def get_query_filter_for_non_postgres(self, criteria): | ||
query_filter = Q() | ||
for key, values in criteria.items(): | ||
for value in values: | ||
query_filter |= Q(properties__contains='{}": "{}'.format(key, value)) | ||
return query_filter | ||
|
||
def filter(self, query_set): | ||
criteria = { | ||
key: self.config.get(key).split("|") for key in self.config.select_keys | ||
if self.config.get(key, None) | ||
} | ||
query_filter = Q() | ||
for key, values in criteria.items(): | ||
for value in values: | ||
query_filter |= Q(properties__contains='{}": "{}'.format(key, value)) | ||
query_filter = self.get_query_filter_for_postgres(criteria) if issubclass(query_set.model, DocumentPostgres) \ | ||
else self.get_query_filter_for_non_postgres(criteria) | ||
return query_set.filter(query_filter) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from datagrowth.resources.http.admin import HttpResourceAdmin | ||
from datagrowth.resources.shell.admin import ShellResourceAdmin | ||
|
||
from datagrowth.datatypes.documents.admin import DataStorageAdmin | ||
from datagrowth.datatypes.annotations.admin import AnnotationAdmin | ||
from datagrowth.datatypes.documents.admin import DataStorageAdmin, DocumentAdmin |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
|
||
|
||
class AnnotationAdmin(admin.ModelAdmin): | ||
list_display = ("reference", "name", "annotation", "user", "created_at", "modified_at") | ||
search_fields = ("reference", "string",) |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,22 @@ | ||
import os | ||
|
||
from django.core.serializers import serialize | ||
|
||
from datagrowth.management.base import DatasetCommand | ||
from datagrowth.utils import ibatch, get_dumps_path | ||
from datagrowth.utils import get_dumps_path, object_to_disk, queryset_to_disk | ||
|
||
|
||
class Command(DatasetCommand): | ||
""" | ||
Dumps a dataset by signature | ||
""" | ||
|
||
@staticmethod | ||
def queryset_to_disk(queryset, json_file, batch_size=100): | ||
count = queryset.all().count() | ||
batch_iterator = ibatch(queryset.iterator(), batch_size=batch_size, progress_bar=True, total=count) | ||
for batch in batch_iterator: | ||
batch_data = serialize("json", batch, use_natural_foreign_keys=True) | ||
json_file.writelines([batch_data + "\n"]) | ||
|
||
@staticmethod | ||
def object_to_disk(object, json_file): | ||
setattr(object, "current_growth", None) # resets dataset | ||
batch_data = serialize("json", [object], use_natural_foreign_keys=True) | ||
json_file.write(batch_data + "\n") | ||
|
||
def handle_dataset(self, dataset, *args, **options): | ||
setattr(dataset, "current_growth", None) # resets the dataset | ||
destination = get_dumps_path(dataset) | ||
if not os.path.exists(destination): | ||
os.makedirs(destination) | ||
file_name = os.path.join(destination, "{}.json".format(dataset.signature)) | ||
file_name = os.path.join(destination, "{}.{}.json".format(dataset.signature, dataset.id)) | ||
with open(file_name, "w") as json_file: | ||
self.object_to_disk(dataset, json_file) | ||
self.queryset_to_disk(dataset.growth_set, json_file) | ||
self.queryset_to_disk(dataset.collections, json_file) | ||
self.queryset_to_disk(dataset.documents, json_file) | ||
object_to_disk(dataset, json_file) | ||
queryset_to_disk(dataset.growth_set, json_file) | ||
queryset_to_disk(dataset.collections, json_file) | ||
queryset_to_disk(dataset.documents, json_file) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
|
||
from django.core.management.base import LabelCommand | ||
from django.apps import apps | ||
|
||
from datagrowth.utils import get_dumps_path, queryset_to_disk | ||
|
||
|
||
class Command(LabelCommand): | ||
""" | ||
Dumps all objects from a Resource to file | ||
""" | ||
|
||
def handle_label(self, label, **options): | ||
Resource = apps.get_model(label) | ||
destination = get_dumps_path(Resource) | ||
if not os.path.exists(destination): | ||
os.makedirs(destination) | ||
resource_name = Resource.get_name() | ||
file_path = os.path.join(destination, "{}.dump.json".format(resource_name)) | ||
with open(file_path, "w") as dump_file: | ||
queryset_to_disk(Resource.objects, dump_file) |
Oops, something went wrong.