Closed jannefleischer closed 3 weeks ago
I think handling the updating is done somewhere here: https://github.com/rdmorganiser/rdmo/blob/065d195043b7ac34a7b6b3180dac69829a3974bc/rdmo/questions/viewsets.py#L120
Though not sure how!
Hi @jannefleischer , the problem is that you cannot set the catalog for a section. You need to set the sections for the catalog.
catalog = client.retrieve_catalog(1)
catalog['sections'] = catalog['sections'] + [{
'section': 8,
'order': 6
}]
client.update_catalog(1, catalog)
Should work. This was changed for RDMO 2.0 (together with the introduction of the pages). The catalogs field in the section response is read_only (for display purposes).
I agree that there should be better error messaging, but right now I don't see how this should be implemented.
The were also multiple bugs with the client, I guess nobody used it to add/update stuff until now.
the client may be updated/generated with the schema from https://github.com/rdmorganiser/rdmo/issues/698 afterwards
@jochenklar: Well, this seem to work for questions, questionsets and pages, though not for sections and pages. I have this snippet:
section_obj = {
"uri_prefix": self.uri_prefix,
"uri_path": section_name_slugged,
"title_en": section_name,
"title_de": section_name
}
section = self.client.list_sections(
**section_obj
)[0]
if len([x for x in self.catalog['sections'] if x['section']==section['id']])>0:
self.display(Markdown('*The Section is already included in the catalog*'))
raise Exception('The Section is already included in the Catalog')
else:
try: ordernumber = (self.catalog['sections'][-1]['order']+1)
except: ordernumber = 1
addendum_section = {'section': section['id'], 'order': ordernumber}
self.display(self.catalog['sections'] + [addendum_section])
oldcatalog = self.catalog.copy()
self.catalog['sections'] = self.catalog['sections'] + [addendum_section]
returnedcatalog = self.client.update_catalog(
self.catalog['id'],
self.catalog
)
if self.debug:
self.display(Markdown('**catalog updated with sections** (ID: ' +str(section['id'])+ ')'))
self.display(section)
self.display(oldcatalog)
self.display(self.catalog)
self.display(returnedcatalog)
raise Exception('debug raise')
catalog updated with sections (ID: 99)
<IPython.core.display.Markdown object>
{'catalogs': [],
'comment': '',
'editors': [],
'id': 99,
'locked': False,
'model': 'questions.section',
'pages': [],
'read_only': False,
'title': 'Allgemein',
'title_de': 'Allgemein',
'title_en': 'Allgemein',
'uri': redacted/instance/questions/ua-ruhr-beratung-allgemein',
'uri_path': 'ua-ruhr-beratung-allgemein',
'uri_prefix': 'redacted/instance',
'warning': False}
{'available': False,
'comment': '',
'editors': [],
'groups': [],
'help': '',
'help_de': '',
'help_en': '',
'id': 17,
'locked': False,
'model': 'questions.catalog',
'order': 0,
'projects_count': 0,
'read_only': False,
'sections': [],
'sites': [],
'title': 'UA-Ruhr-Beratung',
'title_de': 'UA-Ruhr-Beratung',
'title_en': 'UA-Ruhr-Beratung',
'uri': 'redacted/instance/questions/catalog-ua-ruhr-beratung',
'uri_path': 'catalog-ua-ruhr-beratung',
'uri_prefix': 'redacted/instance',
'warning': False}
{'available': False,
'comment': '',
'editors': [],
'groups': [],
'help': '',
'help_de': '',
'help_en': '',
'id': 17,
'locked': False,
'model': 'questions.catalog',
'order': 0,
'projects_count': 0,
'read_only': False,
'sections': [{'order': 1, 'section': 99}],
'sites': [],
'title': 'UA-Ruhr-Beratung',
'title_de': 'UA-Ruhr-Beratung',
'title_en': 'UA-Ruhr-Beratung',
'uri': 'redacted/instance/questions/catalog-ua-ruhr-beratung',
'uri_path': 'catalog-ua-ruhr-beratung',
'uri_prefix': redacted/instance',
'warning': False}
{'available': False,
'comment': '',
'editors': [],
'groups': [],
'help': '',
'help_de': '',
'help_en': '',
'id': 17,
'locked': False,
'model': 'questions.catalog',
'order': 0,
'projects_count': 0,
'read_only': False,
'sections': [],
'sites': [],
'title': 'UA-Ruhr-Beratung',
'title_de': 'UA-Ruhr-Beratung',
'title_en': 'UA-Ruhr-Beratung',
'uri': 'redacted/instance/questions/catalog-ua-ruhr-beratung',
'uri_path': 'catalog-ua-ruhr-beratung',
'uri_prefix': 'redacted/instance',
'warning': False}
This could be because of the bug I fixed in https://github.com/rdmorganiser/rdmo-client/commit/4ba05630eaf123f4cfce5299b414ae2eddca0f2d (and forgot to push). Please try again.
Thank you, that did the job!
Description / Beschreibung
I am trying to create (and constantly updating while processing) new catalogs to my rdmo instance. I am using rdmo-client for this, though I think the issue is with API not the client, so I file this here.
I do have a section created like this (created with rdmo_client, so initial creation does work):
I do have this data dict:
And once I send this with
rdmo_client.update_section(section_dict)
to my rdmo-deployment I retrieve an unchanged catalog json like before (with catalog1
).Expected behaviour / Erwartetes Verhalten
I would expect that
4
(and deals with missing page1
itself), orAt the moment the only thing I can do is guess whats wrong. And I need to compare old json with new json to find out that there is something not successfully updated. I do have the same issues when applying attributes, pages, questions, ...
Or do I do something wrong? How do I update an object? (with the ultimate goal to have a section in two or more catalogs)
Steps to reproduce / Schritte zum Reproduzieren
(see above)
Context / Kontext
References / Verweise
*