Skip to content
Snippets Groups Projects
Commit 349899f0aa5b authored by Laurent Peuch's avatar Laurent Peuch
Browse files

fix: reintroduce lost NoDuplicateHook lost while losing 1.9.1 code

Apparently this code was lost by being (maybe) pushed on hg.logilab.fr and
never pushed to our new forge.
parent a9162738593e
No related branches found
No related tags found
No related merge requests found
from cubicweb import ValidationError
from cubicweb.predicates import is_instance
from cubicweb.sobjects.notification import ContentAddedView
......@@ -1,8 +2,9 @@
from cubicweb.predicates import is_instance
from cubicweb.sobjects.notification import ContentAddedView
from cubicweb.server.hook import Hook
class LinkAddedView(ContentAddedView):
"""get notified from new links"""
__select__ = is_instance('Link')
content_attr = 'description'
......@@ -3,6 +5,26 @@
class LinkAddedView(ContentAddedView):
"""get notified from new links"""
__select__ = is_instance('Link')
content_attr = 'description'
class NoDuplicateHook(Hook):
""" Before adding/updating a link, check that the URL is not already in the
database.
"""
__regid__ = "link_no_duplicate_hook"
__select_ = Hook.__select__ & is_instance("Link")
events = ("before_add_entity", "before_update_entity")
def __call__(self):
try:
new_url = self.entity.cw_edited["url"]
except KeyError:
return
if self._cw.find("Link", url=new_url):
msg = self._cw._("This URL is already existing")
raise ValidationError(self.entity.eid, {"url": msg})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment