def _add_tag(request, question_id):
 tag_name = request.POST.get('tag-name', '').strip()
 if tag_name:
  question = get_object_or_404(Question, pk=question_id)
  try:
   canonical_name = add_existing_tag(tag_name, question.tags)
  except Tag.DoesNotExist:
   if request.user.has_perm('taggit.add_tag'):
    question.tags.add(tag_name)
    canonical_name = tag_name
   else:
    raise
  tag_added.send(sender=Question, question_id=question.id, tag_name=canonical_name)
  return (question, canonical_name)
 return (None, None)

def _add_tag ( request , question_id ) : tag_name = request . POST . get ( 'tag-name' , '' ) . strip ( ) if tag_name : question = get_object_or_404 ( Question , pk = question_id ) try : canonical_name = add_existing_tag ( tag_name , question . tags ) except Tag . DoesNotExist : if request . user . has_perm ( 'taggit.add_tag' ) : question . tags . add ( tag_name ) canonical_name = tag_name else : raise tag_added . send ( sender = Question , question_id = question . id , tag_name = canonical_name ) return ( question , canonical_name ) return ( None , None )
add a named tag to a question .