def update_message_flags(request, user_profile, messages=REQ('messages', validator=check_list(check_int)), operation=REQ('op'), flag=REQ('flag'), all=REQ('all', validator=check_bool, default=False), stream_name=REQ('stream_name', default=None), topic_name=REQ('topic_name', default=None)): request._log_data["extra"] = "[%s %s]" % (operation, flag) stream = None if stream_name is not None: stream = get_stream(stream_name, user_profile.realm) if not stream: raise JsonableError(_('No such stream \'%s\'') % (stream_name, )) if topic_name: topic_exists = UserMessage.objects.filter( user_profile=user_profile, message__recipient__type_id=stream.id, message__recipient__type=Recipient.STREAM, message__subject__iexact=topic_name).exists() if not topic_exists: raise JsonableError(_('No such topic \'%s\'') % (topic_name, )) do_update_message_flags(user_profile, operation, flag, messages, all, stream, topic_name) return json_success({'result': 'success', 'messages': messages, 'msg': ''})
def update_message_flags(request, user_profile, messages=REQ('messages', validator=check_list(check_int)), operation=REQ('op'), flag=REQ('flag'), all=REQ('all', validator=check_bool, default=False)): request._log_data["extra"] = "[%s %s]" % (operation, flag) do_update_message_flags(user_profile, operation, flag, messages, all) return json_success({'result': 'success', 'messages': messages, 'msg': ''})
def handle(self, *args, **options): for email in options["emails"]: try: user_profile = get_user_profile_by_email(email) except UserProfile.DoesNotExist: print "e-mail %s doesn't exist in the system, skipping" % (email,) continue do_update_message_flags(user_profile, "add", "read", None, True) messages = Message.objects.filter(usermessage__user_profile=user_profile).order_by("-id")[:1] if messages: old_pointer = user_profile.pointer new_pointer = messages[0].id user_profile.pointer = new_pointer user_profile.save(update_fields=["pointer"]) print "%s: %d => %d" % (email, old_pointer, new_pointer) else: print "%s has no messages, can't bankrupt!" % (email,)
def handle(self, *args, **options): for email in options['emails']: try: user_profile = get_user_profile_by_email(email) except UserProfile.DoesNotExist: print("e-mail %s doesn't exist in the system, skipping" % (email, )) continue do_update_message_flags(user_profile, "add", "read", None, True) messages = Message.objects.filter( usermessage__user_profile=user_profile).order_by('-id')[:1] if messages: old_pointer = user_profile.pointer new_pointer = messages[0].id user_profile.pointer = new_pointer user_profile.save(update_fields=["pointer"]) print("%s: %d => %d" % (email, old_pointer, new_pointer)) else: print("%s has no messages, can't bankrupt!" % (email, ))
def handle(self, *args, **options): # type: (*Any, **str) -> None realm = self.get_realm(options) for email in options['emails']: try: user_profile = self.get_user(email, realm) except CommandError: print("e-mail %s doesn't exist in the realm %s, skipping" % (email, realm)) continue do_update_message_flags(user_profile, "add", "read", None, True, None, None) messages = Message.objects.filter( usermessage__user_profile=user_profile).order_by('-id')[:1] if messages: old_pointer = user_profile.pointer new_pointer = messages[0].id user_profile.pointer = new_pointer user_profile.save(update_fields=["pointer"]) print("%s: %d => %d" % (email, old_pointer, new_pointer)) else: print("%s has no messages, can't bankrupt!" % (email, ))
def update_message_flags(request, user_profile, messages=REQ('messages', validator=check_list(check_int)), operation=REQ('op'), flag=REQ('flag'), all=REQ('all', validator=check_bool, default=False), stream_name=REQ('stream_name', default=None), topic_name=REQ('topic_name', default=None)): request._log_data["extra"] = "[%s %s]" % (operation, flag) stream = None if stream_name is not None: stream = get_stream(stream_name, user_profile.realm) if not stream: raise JsonableError(_('No such stream \'%s\'') % (stream_name,)) if topic_name: topic_exists = UserMessage.objects.filter(user_profile=user_profile, message__recipient__type_id=stream.id, message__recipient__type=Recipient.STREAM, message__subject__iexact=topic_name).exists() if not topic_exists: raise JsonableError(_('No such topic \'%s\'') % (topic_name,)) do_update_message_flags(user_profile, operation, flag, messages, all, stream, topic_name) return json_success({'result': 'success', 'messages': messages, 'msg': ''})
def update_message_flags( request: HttpRequest, user_profile: UserProfile, messages: List[int] = REQ(json_validator=check_list(check_int)), operation: str = REQ("op"), flag: str = REQ(), ) -> HttpResponse: count = do_update_message_flags(user_profile, request.client, operation, flag, messages) target_count_str = str(len(messages)) log_data_str = f"[{operation} {flag}/{target_count_str}] actually {count}" request._log_data["extra"] = log_data_str return json_success({"result": "success", "messages": messages, "msg": ""})
def update_message_flags( request: HttpRequest, user_profile: UserProfile, messages: List[int] = REQ(validator=check_list(check_int)), operation: str = REQ('op'), flag: str = REQ() ) -> HttpResponse: count = do_update_message_flags(user_profile, request.client, operation, flag, messages) target_count_str = str(len(messages)) log_data_str = f"[{operation} {flag}/{target_count_str}] actually {count}" request._log_data["extra"] = log_data_str return json_success({'result': 'success', 'messages': messages, 'msg': ''})
def update_message_flags( request: HttpRequest, user_profile: UserProfile, messages: List[int] = REQ(json_validator=check_list(check_int)), operation: str = REQ("op"), flag: str = REQ(), ) -> HttpResponse: request_notes = RequestNotes.get_notes(request) assert request_notes.log_data is not None count = do_update_message_flags(user_profile, operation, flag, messages) target_count_str = str(len(messages)) log_data_str = f"[{operation} {flag}/{target_count_str}] actually {count}" request_notes.log_data["extra"] = log_data_str return json_success(request, data={"messages": messages})
def update_message_flags( request, user_profile, messages=REQ(validator=check_list(check_int)), operation=REQ("op"), flag=REQ(), all=REQ(validator=check_bool, default=False), stream_name=REQ(default=None), topic_name=REQ(default=None), ): # type: (HttpRequest, UserProfile, List[int], text_type, text_type, bool, Optional[text_type], Optional[text_type]) -> HttpResponse if all: target_count_str = "all" else: target_count_str = str(len(messages)) log_data_str = "[%s %s/%s]" % (operation, flag, target_count_str) request._log_data["extra"] = log_data_str stream = None if stream_name is not None: stream = get_stream(stream_name, user_profile.realm) if not stream: raise JsonableError(_("No such stream '%s'") % (stream_name,)) if topic_name: topic_exists = UserMessage.objects.filter( user_profile=user_profile, message__recipient__type_id=stream.id, message__recipient__type=Recipient.STREAM, message__subject__iexact=topic_name, ).exists() if not topic_exists: raise JsonableError(_("No such topic '%s'") % (topic_name,)) count = do_update_message_flags(user_profile, operation, flag, messages, all, stream, topic_name) # If we succeed, update log data str with the actual count for how # many messages were updated. if count != len(messages): log_data_str = "[%s %s/%s] actually %s" % (operation, flag, target_count_str, count) request._log_data["extra"] = log_data_str return json_success({"result": "success", "messages": messages, "msg": ""})
def update_message_flags(request, user_profile, messages=REQ(validator=check_list(check_int)), operation=REQ('op'), flag=REQ(), all=REQ(validator=check_bool, default=False), stream_name=REQ(default=None), topic_name=REQ(default=None)): # type: (HttpRequest, UserProfile, List[int], text_type, text_type, bool, Optional[text_type], Optional[text_type]) -> HttpResponse if all: target_count_str = "all" else: target_count_str = str(len(messages)) log_data_str = "[%s %s/%s]" % (operation, flag, target_count_str) request._log_data["extra"] = log_data_str stream = None if stream_name is not None: stream = get_stream(stream_name, user_profile.realm) if not stream: raise JsonableError(_('No such stream \'%s\'') % (stream_name, )) if topic_name: topic_exists = UserMessage.objects.filter( user_profile=user_profile, message__recipient__type_id=stream.id, message__recipient__type=Recipient.STREAM, message__subject__iexact=topic_name).exists() if not topic_exists: raise JsonableError(_('No such topic \'%s\'') % (topic_name, )) count = do_update_message_flags(user_profile, operation, flag, messages, all, stream, topic_name) # If we succeed, update log data str with the actual count for how # many messages were updated. if count != len(messages): log_data_str = "[%s %s/%s] actually %s" % (operation, flag, target_count_str, count) request._log_data["extra"] = log_data_str return json_success({'result': 'success', 'messages': messages, 'msg': ''})
def update_message_flags(request, user_profile, messages=REQ(validator=check_list(check_int)), operation=REQ('op'), flag=REQ(), all=REQ(validator=check_bool, default=False), stream_name=REQ(default=None), topic_name=REQ(default=None)): if all: target_count_str = "all" else: target_count_str = str(len(messages)) log_data_str = "[%s %s/%s]" % (operation, flag, target_count_str) request._log_data["extra"] = log_data_str stream = None if stream_name is not None: stream = get_stream(stream_name, user_profile.realm) if not stream: raise JsonableError(_('No such stream \'%s\'') % (stream_name,)) if topic_name: topic_exists = UserMessage.objects.filter(user_profile=user_profile, message__recipient__type_id=stream.id, message__recipient__type=Recipient.STREAM, message__subject__iexact=topic_name).exists() if not topic_exists: raise JsonableError(_('No such topic \'%s\'') % (topic_name,)) count = do_update_message_flags(user_profile, operation, flag, messages, all, stream, topic_name) # If we succeed, update log data str with the actual count for how # many messages were updated. if count != len(messages): log_data_str = "[%s %s/%s] actually %s" % (operation, flag, target_count_str, count) request._log_data["extra"] = log_data_str return json_success({'result': 'success', 'messages': messages, 'msg': ''})