def json_add_suggestion(request): if request.method == "POST": text = request.POST.get('addSuggestion', '(someone input invalid text)') sug = Suggestion(text=text) sug.save() return HttpResponseRedirect('/thanks_for_suggestion') return HttpResponse("failure")
def suggest(request): if request.method == 'POST': form = SuggestionForm(request.POST) if form.is_valid(): clean_subject = form.cleaned_data['subject'] clean_message = form.cleaned_data['message'] clean_sender = form.cleaned_data.get('sender', '*****@*****.**') stamp = datetime.now() suggestion = Suggestion( subject = clean_subject, message = clean_message, sender = clean_sender, created = stamp, last_modified = stamp ) suggestion.save() suggestion_email = render_to_string('email/suggestion_made.txt', { 'suggestion': suggestion }) people_to_email = [settings.CSESOC_SUGGEST_LIST] if form.cleaned_data.get('sender'): people_to_email.append(clean_sender) # send an email to the suggestions mailing list send_mail( '[CSESoc Suggestion] %s' % clean_subject, suggestion_email, clean_sender, people_to_email ) return render_to_response('thanks-suggestion.html', context_instance=RequestContext(request)) else: form = SuggestionForm() return render_to_response('suggest.html', context_instance=RequestContext(request, {'form': form}))
def notify_bot_offline(bot, update, args=None): tg_user = update.message.from_user user = User.from_telegram_object(tg_user) reply_to = util.original_reply_id(update) if args: text = " ".join(args) else: text = update.message.text command_no_args = (len(re.findall(r"^/new\s*$", text)) > 0 or text.lower().strip() == "/offline@botlistbot") if command_no_args: update.message.reply_text( util.action_hint( "Please use this command with an argument. For example:\n/offline @mybot" ), reply_to_message_id=reply_to, ) return # `#offline` is already checked by handler try: username = re.match(settings.REGEX_BOT_IN_TEXT, text).groups()[0] if username == "@" + settings.SELF_BOT_NAME: log.info("Ignoring {}".format(text)) return except AttributeError: if args: update.message.reply_text( util.failure( "Sorry, but you didn't send me a bot `@username`."), quote=True, parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply_to, ) else: log.info("Ignoring {}".format(text)) # no bot username, ignore update pass return try: offline_bot = Bot.get( fn.lower(Bot.username)**username.lower(), Bot.approved == True) try: Suggestion.get(action="offline", subject=offline_bot) except Suggestion.DoesNotExist: suggestion = Suggestion( user=user, action="offline", date=datetime.date.today(), subject=offline_bot, ) suggestion.save() update.message.reply_text( util.success( "Thank you! We will review your suggestion and set the bot offline." ), reply_to_message_id=reply_to, ) except Bot.DoesNotExist: update.message.reply_text( util.action_hint("The bot you sent me is not in the @BotList."), reply_to_message_id=reply_to, ) return ConversationHandler.END