def save_comment(request, unit):
 unit.commented_by = request.user
 unit.commented_on = timezone.now().replace(microsecond=0)
 language = request.translation_project.language
 form = unit_comment_form_factory(language)(request.POST, instance=unit, request=request)
 if form.is_valid():
  form.save()
  user = request.user
  directory = unit.store.parent
  ctx = {'unit': unit, 'language': language, 'cantranslate': check_user_permission(user, 'translate', directory), 'cansuggest': check_user_permission(user, 'suggest', directory)}
  t = loader.get_template('editor/units/xhr_comment.html')
  return JsonResponse({'comment': t.render(context=ctx, request=request)})
 return JsonResponseBadRequest({'msg': _('Comment submission failed.')})

def save_comment ( request , unit ) : unit . commented_by = request . user unit . commented_on = timezone . now ( ) . replace ( microsecond = 0 ) language = request . translation_project . language form = unit_comment_form_factory ( language ) ( request . POST , instance = unit , request = request ) if form . is_valid ( ) : form . save ( ) user = request . user directory = unit . store . parent ctx = { 'unit' : unit , 'language' : language , 'cantranslate' : check_user_permission ( user , 'translate' , directory ) , 'cansuggest' : check_user_permission ( user , 'suggest' , directory ) } t = loader . get_template ( 'editor/units/xhr_comment.html' ) return JsonResponse ( { 'comment' : t . render ( context = ctx , request = request ) } ) return JsonResponseBadRequest ( { 'msg' : _ ( 'Comment submission failed.' ) } )
stores a new comment for the given unit .