def learn(request, key='', verb='is', value='', also='', tag='', **kwargs): """Add a factoid record to the database.""" factoid, created = Factoid.objects.get_or_create( fact=normalize_factoid_key(key)) if factoid.protected: raise(exceptions.PermissionDenied, 'That factoid is protected!') elif also or created: if tag: tag = tag.strip().strip('<>') factext, created = FactoidResponse.objects.get_or_create( fact=factoid, verb=verb, text=value, tag=tag, created_by=request.nick) if request.addressed: if created: return render_quick_reply(request, "ack.irc") return render_quick_reply(request, "already.irc") else: num_responses = FactoidResponse.objects.filter(fact=factoid, verb=verb, text=value, tag=tag).count() if num_responses: return render_quick_reply(request, "already.irc") # If we got this far, it's worth trying to see if this is just a # factoid with 'is' or 'are' in the key. try: return trigger(request, key=request.message.split(':')[-1].strip()) except Http404, OverflowError: # FIXME: This should be an edit conflict exception raise(exceptions.PermissionDenied, 'That factoid already exists!')
def learn(request, key='', verb='is', value='', also='', tag='', **kwargs): """Add a factoid record to the database.""" factoid, created = Factoid.objects.get_or_create( fact=normalize_factoid_key(key)) if factoid.protected: raise (exceptions.PermissionDenied, 'That factoid is protected!') elif also or created: if tag: tag = tag.strip().strip('<>') factext, created = FactoidResponse.objects.get_or_create( fact=factoid, verb=verb, text=value, tag=tag, created_by=request.nick) if request.addressed: if created: return render_quick_reply(request, "ack.irc") return render_quick_reply(request, "already.irc") else: num_responses = FactoidResponse.objects.filter(fact=factoid, verb=verb, text=value, tag=tag).count() if num_responses: return render_quick_reply(request, "already.irc") # If we got this far, it's worth trying to see if this is just a # factoid with 'is' or 'are' in the key. try: return trigger(request, key=request.message.split(':')[-1].strip()) except Http404, OverflowError: # FIXME: This should be an edit conflict exception raise (exceptions.PermissionDenied, 'That factoid already exists!')
def undelete(request, key='', pattern='.', re_flags='', **kwargs): factoid = get_object_or_404(Factoid, fact__iexact=normalize_factoid_key(key)) undeleted = factoid.undelete_response(pattern, re_flags, request.nick) if not undeleted: return render_error(request, 'No deleted response found for %s' % key) return render_quick_reply(request, "ack.irc")
def delete(request, key='', pattern='.', re_flags='', **kwargs): factoid = get_object_or_404(Factoid, fact__iexact=normalize_factoid_key(key)) deleted = factoid.delete_response(pattern, re_flags, request.nick) if not deleted: return render_error( request, 'No response in %s contained your pattern' % key) return render_quick_reply(request, "ack.irc")
def delete(request, key='', pattern='.', re_flags='', **kwargs): factoid = get_object_or_404(Factoid, fact__iexact=normalize_factoid_key(key)) deleted = factoid.delete_response(pattern, re_flags, request.nick) if not deleted: return render_error(request, 'No response in %s contained your pattern' % key) return render_quick_reply(request, "ack.irc")
def unlock(request, key='', **kwargs): factoid = get_object_or_404(Factoid, fact__iexact=normalize_factoid_key(key)) factoid.protected = False factoid.save() return render_quick_reply(request, "ack.irc")
def lock(request, key='', **kwargs): factoid, created = Factoid.objects.get_or_create(fact=normalize_factoid_key(key)) factoid.protected = True factoid.save() return render_quick_reply(request, "ack.irc")
def unedit(request, key='', pattern='.', re_flags='', **kwargs): factoid = get_object_or_404(Factoid, fact__iexact=normalize_factoid_key(key)) factoid.unedit_response(pattern, re_flags, request.nick) return render_quick_reply(request, "ack.irc")
def lock(request, key='', **kwargs): factoid, created = Factoid.objects.get_or_create( fact=normalize_factoid_key(key)) factoid.protected = True factoid.save() return render_quick_reply(request, "ack.irc")