-
Notifications
You must be signed in to change notification settings - Fork 41
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
Sync EveryPolitician UUID to Person model #2331
Sync EveryPolitician UUID to Person model #2331
Conversation
b941251
to
19be09e
Compare
I think it would be good to get this merged ASAP rather than waiting for the EP/DC problems to be resolved. The best way to do this is probably to make the SHA configurable where there's currently a pombola/pombola/core/management/commands/core_sync_everypolitician_uuid.py Lines 18 to 20 in 4ea415a
Then this script will be usable with whatever EveryPolitician data we want to use. |
4ea415a
to
595c611
Compare
We need this so we can sync the EveryPolitician UUID into the local database for use with WriteInPublic.
595c611
to
989f637
Compare
Have extracted the crontab bits out to #2342 so that the code for the management command can be merged now, and then we can add the cronjob once we're happy with the EP data. |
989f637
to
159156d
Compare
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.
I've left a few minor comments inline. The only other thing that occurs to me is that it might helpful if the argument was optional rather than required, and have it default to master
.
# `peoples_assembly` identifier, but this isn't on master because | ||
# South Africa is broken in EveryPolitician at the moment. | ||
# | ||
# TODO: Make this SHA configurable. |
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.
I think these comments can be removed now :)
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.
Oops, yep!
|
||
id_lookup = {} | ||
for popolo_person in south_africa_assembly.persons: | ||
pa_ids = [i for i in popolo_person.identifiers if i['scheme'] == 'peoples_assembly'] |
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.
I think you can use popolo_person.identifier_value('peoples_assembly')
to simplify this: https://github.com/everypolitician/everypolitician-popolo-python/blob/master/popolo_data/base.py#L99 (this isn't documented, sorry)
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.
Ah didn't know about that, thanks, have changed it to use that.
continue | ||
id_lookup[pa_ids[0]['identifier']] = popolo_person.id | ||
|
||
error_msg = u"No EveryPolitician UUID found for {} {} https://www.pa.org.za/person/{}/\n" |
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.
This is partly just "fun with Python's .format
" but, you could make this:
u"No EveryPolitician UUID found for {0.id} {0.name} https://www.pa.org.za/person/{0.slug}/\n"
... and then do error_msg.format(person)
. It's a tiny thing, but it'd make changing the format string later less prone to error.
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.
😮 Wow, didn't know .format
could do that!! You're quite right, that's less error prone. Have switched to using that syntax.
for person in Person.objects.filter(hidden=False): | ||
uuid = id_lookup.get(str(person.id)) | ||
if uuid is None: | ||
if verbose_level > 1: |
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.
I'd probably collapse these two conditions into a single condition - perhaps makes it slightly easier to see that there's only one branch here?
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.
The continue
on the line below is actually in the top level if
statement, then the logging is part of the inner if
statement. I've changed things around in 663e8dc so that it's all at a single level of if
statement to make things hopefully a bit clearer.
|
||
|
||
class Command(BaseCommand): | ||
help = 'Sync EveryPolitician UUID to Person.everypolitician_uuid field' |
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.
"Person.everypolitician_uuid field" - I suspect this is an old comment?
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.
👍
if created: | ||
msg = u"Created new identifier for {}: {}" | ||
else: | ||
msg = u"Existing identifier found for {}: {}" |
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.
It's another very minor thing, but I'd probably make these use {name}: {identifier}
and then .format(name=person.name, identifier=identifier.identifier)
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.
👍
Ah yep, very sensible suggestion! Have done that in e7e2e96. |
@mhl I've addressed your very helpful comments, would you mind re-reviewing this please? |
@chrismytton Looks good 👍 - just one last thing; since this is currently South Africa specific, could you make the filename |
I'm guessing that should have been |
Yep, that's what I meant, sorry :) |
2e63d66
to
744fffd
Compare
Add a management command add EveryPolitician UUIDs to the Person model.
Blocked waiting for EveryPolitician South Africa import to be fixedThis is currently using thesouth-africa-update-peoples-assembly
branch of everypolitician-data, which has the required UUIDs but is also losing some data, so can't be merged in its current state. So before this can be merged we need to fix the problems described in everypolitician/everypolitician-data#42096.To work around this problem I've made the git ref that we use to fetch
countries.json
configurable. This means we can point to the branch that has the data we need for now, then when things are fixed upstream we can use a different ref to point to the fixed data.I've also split the bit that adds a cronjob for this into a separate pull request #2342 so we can hold off merging that until we've got the data in EveryPolitician up-to-date, but we can still merge this in the meantime.
Fixes #2330