def add_suggestions(payload): body = request.get_json() suggestion = body.get('suggestion', None) category = body.get('category', None) new_sug = Suggestion(suggestion=suggestion, category=category) new_sug.insert() all_suggestions = Suggestion.query.all() formatted_sugg = [sug.format() for sug in all_suggestions] return jsonify({'success': True, 'all_suggestion': formatted_sugg})
def test_edit_get_objet(self): view = EditSuggestionView() request = RequestFactory() view.request = request self.moxx.StubOutWithMock(views, 'get_client_ip') views.get_client_ip(request).AndReturn(self.ip) self.moxx.StubOutWithMock(Box, 'get_unread') Box.get_unread(self.ip).AndReturn(Suggestion(ip_address=self.ip)) self.moxx.ReplayAll() view.get_object() self.moxx.VerifyAll()
def send_anime_recommendation(anime_lst, anime_id, comment, username, curr_list): anime_by_id = next(item for item in anime_lst['results'] if item['mal_id'] == anime_id) suggestion = Suggestion(list_id=curr_list.id, anime_id=anime_id, anime_title=anime_by_id['title'], mal_url=anime_by_id['url'], comment=comment or 'No comment from suggester.', username=username) db.session.add(suggestion) db.session.commit()
def delete_suggestion(self, args, user): messages = [] search = '' if len(args) <= 1: raise Exception( 'Suggestion delte syntax\n```css\n.d suggestion delete "NAME"```' ) if len(args) > 1: search = ' '.join(args[1:]) suggestion = Suggestion().find(search) if not suggestion: return [f'_"{search}"_ was not found. No changes made.'] else: search = str(suggestion.text) suggestion.archived = True self.save(suggestion, user) messages.append(f'***{search}*** removed') return messages
def handle_suggestion_response(result, current_asset_id, asset_metas): for asset_meta in asset_metas: asset_id = asset_meta.asset_id # skip if it is the same id as the classified image if current_asset_id == asset_id: continue cropped_id = asset_meta.cropped_id path = fetch_cropped_path(asset_id, cropped_id) if asset_id not in result.suggestions: result.suggestions[asset_id] = Suggestion([Frame(cropped_id, asset_meta.faiss_idx, path)]) else: contains = False for frame in result.suggestions[asset_id].frames: if frame.frame_id == cropped_id: contains = True break if not contains: result.suggestions[asset_id].frames += [Frame(cropped_id, asset_meta.faiss_idx, path)]
def name(self, args): """Display and create a new Suggestion by name Parameters ---------- args : list(str) List of strings with subcommands Returns ------- list(str) - the response messages string array """ messages = [] if len(args) < 2: raise Exception('syntax: ```css\n.d suggest "SUGGESTION TEXT"```') suggestion = Suggestion().create_new(name=self.user.name, text=' '.join(args[1:])) messages.append(suggestion.get_string(self.user)) return messages
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
def test_suggestion_clean_raise(self): Suggestion.objects.create(ip_address=self.ip) mod = Suggestion(ip_address=self.ip) self.assertRaises(ValidationError, mod.clean)
def test_suggestion_property(self): mod = Suggestion(ip_address=self.ip, message='x'*90) self.assertTrue(mod.message_start, 'x'*80)
def test_suggestion_unicode(self): mod = Suggestion(ip_address=self.ip) self.assertTrue(self.ip in '%s' % mod)