Fix for URL generation in model classes.

This commit is contained in:
Edward Betts 2018-06-04 07:43:40 +01:00
parent 2f5c4d7e79
commit c7ef45d126

View file

@ -155,34 +155,34 @@ class Item(TimeStampedModel):
@property @property
def url(self): def url(self):
return url_for('.view_item', return url_for('view.view_item',
username=self.user.username, username=self.user.username,
hashid=self.hashid) hashid=self.hashid)
def version_url(self, version): def version_url(self, version):
return url_for('.view_item', return url_for('view.view_item',
username=self.user.username, username=self.user.username,
hashid=self.hashid, hashid=self.hashid,
v=version) v=version)
@property @property
def history_url(self): def history_url(self):
return url_for('.history', username=self.user.username, hashid=self.hashid) return url_for('view.history', username=self.user.username, hashid=self.hashid)
@property @property
def external_url(self): def external_url(self):
return url_for('.view_item', return url_for('view.view_item',
username=self.user.username, username=self.user.username,
hashid=self.hashid, hashid=self.hashid,
_external=True) _external=True)
@property @property
def edit_url(self): def edit_url(self):
return url_for('.edit_item', username=self.user.username, hashid=self.hashid) return url_for('view.edit_item', username=self.user.username, hashid=self.hashid)
@property @property
def set_title_url(self): def set_title_url(self):
return url_for('.set_title', username=self.user.username, hashid=self.hashid) return url_for('view.set_title', username=self.user.username, hashid=self.hashid)
def title(self, titles=None): def title(self, titles=None):
if not titles: if not titles:
@ -211,8 +211,9 @@ span: {},start=0,length={}'''.format(self.external_url, title_source_doc.externa
session.commit() session.commit()
@classmethod @classmethod
def from_external(cls, url): def from_external(cls, url, home=None):
home = url_for('.home', _external=True) if home is None:
home = url_for('view.home', _external=True)
if url.startswith(home): if url.startswith(home):
username, _, hashid = url[len(home):].partition('/') username, _, hashid = url[len(home):].partition('/')
else: else: