-
Notifications
You must be signed in to change notification settings - Fork 17
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
base: master
Are you sure you want to change the base?
Add possibility to load and dump data with superuser access #129
Conversation
KhaledBousrih
commented
Apr 21, 2022
<br> | ||
{% endif %} | ||
{% if use_core_automation %} | ||
<p class="custom-btn" onclick="window.location.href='{{target_admin_view}}';">Go to {{target_admin_view_name}}</p> |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 methodget_dashed_case_class_name
that returns dash-cased names (example:my-model
) - in
concrete_datastore.routes.urls
we also use dash-cased names (exampleservice-status-view
) - in
concrete_datastore.concerte.urls
we use snake-case names (exempleunsubscribe_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) |
There was a problem hiding this comment.
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)}, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'): |
There was a problem hiding this comment.
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': |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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" ?
document.location.href="{% url 'concrete:dump_data' %}?download=true"; | ||
alert('Your download will begin soon') | ||
setInterval(()=>{console.log(test)}, 1000) | ||
// hideWaitingDiv(); |
There was a problem hiding this comment.
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 ?