-
Notifications
You must be signed in to change notification settings - Fork 133
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
Support query by date_modified field #2009
Conversation
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.
Looks good. Quick question, why do we need the migration file?
@@ -389,6 +386,7 @@ def get_full_dict(self, load_existing=True): | |||
self.date_created = submission_time() | |||
|
|||
doc[SUBMISSION_TIME] = self.date_created.strftime(MONGO_STRFTIME) | |||
doc[DATE_MODIFIED] = self.date_modified.strftime(MONGO_STRFTIME) |
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.
We do have this check https://github.com/onaio/onadata/pull/2009/files#diff-98ae21dd41854ad6194bdbca52b97c4d2b0231f6d06b3ee5ee73c4c88a135e27R385-R386 for date_created
ensuring it is not null, should we have the same for date_modified
?
It's there so that the JSON is regenerated to enable users to start using the |
5f0907d
to
9056773
Compare
# pylint: skip-file | ||
# Generated by Django 2.2.16 on 2021-02-02 07:48 | ||
|
||
from django.db import migrations | ||
from onadata.apps.logger.models.instance import Instance | ||
|
||
|
||
def regenerate_instance_json(apps, schema_editor): | ||
""" | ||
Regenerate Instance JSON | ||
""" | ||
for inst in Instance.objects.filter(deleted_at__isnull=True): | ||
inst.json = inst.get_full_dict(load_existing=False) | ||
inst.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('logger', '0061_auto_20200713_0814'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(regenerate_instance_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.
We will need a strategy to run this in our production environment, other deployments might be okay.
@@ -388,6 +385,12 @@ def get_full_dict(self, load_existing=True): | |||
if not self.date_created: | |||
self.date_created = submission_time() | |||
|
|||
if not self.date_modified: | |||
doc[DATE_MODIFIED] = "" |
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.
Could we not include the field or use the date_created
value, since that would ideally be the same value on the initial creation of the record? The latter approach is what we did for the DATE_CREATED
field.
a764dd7
to
31638e0
Compare
108d71a
to
c813e1f
Compare
if not self.date_modified: | ||
doc[DATE_MODIFIED] = self.date_created |
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 this be getting, the date format treatment as below or is it handled elsewhere?
doc[DATE_MODIFIED] = self.date_created.strftime(MONGO_STRFTIME)
if not self.date_modified: | ||
doc[DATE_MODIFIED] = self.date_created.strftime( | ||
MONGO_STRFTIME) | ||
else: | ||
doc[DATE_MODIFIED] = self.date_modified.strftime( | ||
MONGO_STRFTIME) | ||
|
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.
Simplify
if not self.date_modified:
self.date_modified= self.date_created
doc[DATE_MODIFIED] = self.date_modified.strftime(
MONGO_STRFTIME)
- Add '_date_modified' header
Retrieve _date_modified value from the actual CSV
Add the _date_modified field to the sample data for the Data endpoint
8f2534b
to
e7f4ef2
Compare
7479bb7
to
c7202b7
Compare
Changes / Features implemented
_date_modified
into the generated Instance JSONcreated
attribute to the data list XML response Instance representationsSteps taken to verify this change does what is intended
Side effects of implementing this change
Closes #2001