Rename get_one(...) -> get_or_404(...)

This commit is contained in:
Pedro Ferreira 2020-05-27 13:51:06 +02:00
parent abe7ea7ce1
commit 5fc728d2b1
6 changed files with 15 additions and 15 deletions

View File

@ -30,7 +30,7 @@ class RHDeleteAgent(RHAdminBase):
"""Deletes a LiveSync agent"""
def _process_args(self):
self.agent = LiveSyncAgent.get_one(request.view_args['agent_id'])
self.agent = LiveSyncAgent.get_or_404(request.view_args['agent_id'])
def _process(self):
db.session.delete(self.agent)
@ -66,7 +66,7 @@ class RHEditAgent(RHAdminBase):
"""Edits a LiveSync agent"""
def _process_args(self):
self.agent = LiveSyncAgent.get_one(request.view_args['agent_id'])
self.agent = LiveSyncAgent.get_or_404(request.view_args['agent_id'])
if self.agent.backend is None:
flash(_('Cannot edit an agent that is not loaded'), 'error')
return redirect(url_for('plugins.details', plugin='livesync'))

View File

@ -43,15 +43,15 @@ def obj_deref(ref):
"""Returns the object identified by `ref`"""
from indico_livesync.models.queue import EntryType
if ref['type'] == EntryType.category:
return Category.get_one(ref['category_id'])
return Category.get_or_404(ref['category_id'])
elif ref['type'] == EntryType.event:
return Event.get_one(ref['event_id'])
return Event.get_or_404(ref['event_id'])
elif ref['type'] == EntryType.session:
return Session.get_one(ref['session_id'])
return Session.get_or_404(ref['session_id'])
elif ref['type'] == EntryType.contribution:
return Contribution.get_one(ref['contrib_id'])
return Contribution.get_or_404(ref['contrib_id'])
elif ref['type'] == EntryType.subcontribution:
return SubContribution.get_one(ref['subcontrib_id'])
return SubContribution.get_or_404(ref['subcontrib_id'])
else:
raise ValueError('Unexpected object type: {}'.format(ref['type']))

View File

@ -44,7 +44,7 @@ class ReportBase(Serializer):
@property
def event(self):
return Event.get_one(self.event_id, is_deleted=False)
return Event.get_or_404(self.event_id, is_deleted=False)
@classmethod
def get(cls, *args, **kwargs):
@ -139,7 +139,7 @@ class ReportMaterial(ReportBase):
__public__ = ['material']
def _build_report(self):
event = Event.get_one(self.params['event_id'], is_deleted=False)
event = Event.get_or_404(self.params['event_id'], is_deleted=False)
new_material = get_nested_attached_items(event)
self.material = {'tree': [self._format_data(new_material)]}

View File

@ -12,7 +12,7 @@ from setuptools import find_packages, setup
setup(
name='indico-plugin-piwik',
version='2.2',
version='2.3-dev',
description='Piwik integration for global and event-specific statistics in Indico',
url='https://github.com/indico/indico-plugins',
license='MIT',
@ -22,7 +22,7 @@ setup(
zip_safe=False,
include_package_data=True,
install_requires=[
'indico>=2.2.dev0'
'indico>=2.3.dev0'
],
classifiers=[
'Environment :: Plugins',

View File

@ -24,10 +24,10 @@ class RHSearch(RH):
def _process_args(self):
if 'confId' in request.view_args:
self.obj = Event.get_one(request.view_args['confId'], is_deleted=False)
self.obj = Event.get_or_404(request.view_args['confId'], is_deleted=False)
self.obj_type = 'event'
elif 'category_id' in request.view_args:
self.obj = Category.get_one(request.view_args['category_id'], is_deleted=False)
self.obj = Category.get_or_404(request.view_args['category_id'], is_deleted=False)
self.obj_type = 'category' if not self.obj.is_root else None
else:
self.obj = Category.get_root()

View File

@ -12,7 +12,7 @@ from setuptools import find_packages, setup
setup(
name='indico-plugin-search',
version='2.2',
version='2.3-dev',
description='Framework for searching content in Indico',
url='https://github.com/indico/indico-plugins',
license='MIT',
@ -22,7 +22,7 @@ setup(
zip_safe=False,
include_package_data=True,
install_requires=[
'indico>=2.2.dev0'
'indico>=2.3.dev0'
],
classifiers=[
'Environment :: Plugins',