Add 'enable_photo_add_remove_tag' config
This commit is contained in:
parent
efa930f4a8
commit
f222ae7182
3 changed files with 19 additions and 4 deletions
|
@ -151,6 +151,7 @@ DEFAULT_CONFIGURATION = {
|
||||||
'enable_new_photo': True,
|
'enable_new_photo': True,
|
||||||
'enable_new_tag': True,
|
'enable_new_tag': True,
|
||||||
'enable_new_user': True,
|
'enable_new_user': True,
|
||||||
|
'enable_photo_add_remove_tag': True,
|
||||||
|
|
||||||
'min_tag_name_length': 1,
|
'min_tag_name_length': 1,
|
||||||
'max_tag_name_length': 32,
|
'max_tag_name_length': 32,
|
||||||
|
|
|
@ -438,6 +438,9 @@ class Photo(ObjectBase):
|
||||||
return 'Photo:{id}'.format(id=self.id)
|
return 'Photo:{id}'.format(id=self.id)
|
||||||
|
|
||||||
def add_tag(self, tag, *, commit=True):
|
def add_tag(self, tag, *, commit=True):
|
||||||
|
if not self.photodb.config['enable_photo_add_remove_tag']:
|
||||||
|
raise exceptions.FeatureDisabled('photo.add_tag, photo.remove_tag')
|
||||||
|
|
||||||
tag = self.photodb.get_tag(tag)
|
tag = self.photodb.get_tag(tag)
|
||||||
|
|
||||||
existing = self.has_tag(tag, check_children=False)
|
existing = self.has_tag(tag, check_children=False)
|
||||||
|
@ -707,6 +710,9 @@ class Photo(ObjectBase):
|
||||||
self.photodb.commit()
|
self.photodb.commit()
|
||||||
|
|
||||||
def remove_tag(self, tag, *, commit=True):
|
def remove_tag(self, tag, *, commit=True):
|
||||||
|
if not self.photodb.config['enable_photo_add_remove_tag']:
|
||||||
|
raise exceptions.FeatureDisabled('photo.add_tag, photo.remove_tag')
|
||||||
|
|
||||||
tag = self.photodb.get_tag(tag)
|
tag = self.photodb.get_tag(tag)
|
||||||
|
|
||||||
self.photodb.log.debug('Removing tag {t} from photo {p}'.format(t=repr(tag), p=repr(self)))
|
self.photodb.log.debug('Removing tag {t} from photo {p}'.format(t=repr(tag), p=repr(self)))
|
||||||
|
|
|
@ -671,10 +671,18 @@ def post_photo_add_remove_tag_core(photoid, tagname, add_or_remove):
|
||||||
photo = P_photo(photoid, response_type='json')
|
photo = P_photo(photoid, response_type='json')
|
||||||
tag = P_tag(tagname, response_type='json')
|
tag = P_tag(tagname, response_type='json')
|
||||||
|
|
||||||
if add_or_remove == 'add':
|
try:
|
||||||
photo.add_tag(tag)
|
if add_or_remove == 'add':
|
||||||
elif add_or_remove == 'remove':
|
photo.add_tag(tag)
|
||||||
photo.remove_tag(tag)
|
elif add_or_remove == 'remove':
|
||||||
|
photo.remove_tag(tag)
|
||||||
|
except exceptions.EtiquetteException as e:
|
||||||
|
response = {
|
||||||
|
'error_type': e.error_type,
|
||||||
|
'error_message': e.error_message,
|
||||||
|
}
|
||||||
|
response = jsonify.make_json_response(response, status=400)
|
||||||
|
flask.abort(response)
|
||||||
|
|
||||||
response = {'tagname': tag.name}
|
response = {'tagname': tag.name}
|
||||||
return jsonify.make_json_response(response)
|
return jsonify.make_json_response(response)
|
||||||
|
|
Loading…
Reference in a new issue