Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to load and dump data with superuser access #129

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

KhaledBousrih
Copy link
Collaborator

image

<br>
{% endif %}
{% if use_core_automation %}
<p class="custom-btn" onclick="window.location.href='{{target_admin_view}}';">Go to {{target_admin_view_name}}</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a <a href= here

};
function donwloadDump() {
document.location.href="{% url 'concrete:dump_data' %}?download=true";
alert('Your download will begin soon')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use alert

@@ -26,3 +29,8 @@
name='unsubscribe_notifications_result',
),
]

if settings.ENABLE_DATABASE_DUMP:
urlpatterns.append(re_path(r'dump-data', dump_data, name="dump_data"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url names are not dash cased ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both ways are used in the project.

  • in concrete_datastore.api.v1_1.urls we use the method get_dashed_case_class_name that returns dash-cased names (example: my-model)
  • in concrete_datastore.routes.urls we also use dash-cased names (example service-status-view)
  • in concrete_datastore.concerte.urls we use snake-case names (exemple unsubscribe_notifications_result)

Since the code added is in the module concrete_datastore.concerte.urls I tried to keep the same naming convention of this module.

Should we homogenize the names of all the urls into dash-cased names ?

status=200,
)
except Exception as e:
return JsonResponse(data={'error': str(e)}, status=400)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a log is required here


json_resp = json.loads(resp_value)
return JsonResponse(
data={'result': json_resp, 'objects_count': len(json_resp)},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

results would be better

response = JsonResponse(data={'message': resp_value}, status=200)
except Exception as e:
response = JsonResponse(
data={'error': f'An error has occured: {e}'}, status=400
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be homogeneous with line 166

@@ -70,9 +71,20 @@ class DatamodelServer(APIView, TemplateView):
)

def _get_datamodel_format(self, data_format='yaml'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to a 'datamodel' module

if type(value) == datetime.datetime:
return format_datetime(value)
return str(value)

datamodel_content_json = settings.META_MODEL_DEFINITIONS
if data_format == 'json':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too light about data_format validation

@@ -103,12 +115,14 @@ def get(self, request, *args, **kwargs):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
datamodel_content_json = settings.META_MODEL_DEFINITIONS
context['json_content'] = json.dumps(datamodel_content_json, indent=2)
datamodel_content_json = self._get_datamodel_format(data_format='json')
datamodel_content_yml = self._get_datamodel_format()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specify format here

content = DatamodelYamlToHtml(datamodel_content_json, indent=2)
content = DatamodelYamlToHtml(
settings.META_MODEL_DEFINITIONS, indent=2
)
context['yaml_displayed_content'] = content.render_yaml()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class is named Yaml to Html, but only function "render yaml" is called, a yaml is expected as a result.
So based on the class name "YAML to HTML", but based on parameters and function names "JSON to YAML" ?

@KhaledBousrih KhaledBousrih marked this pull request as draft October 19, 2022 13:28
document.location.href="{% url 'concrete:dump_data' %}?download=true";
alert('Your download will begin soon')
setInterval(()=>{console.log(test)}, 1000)
// hideWaitingDiv();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should delete this line if obsolete, or uncomment ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants