def get(self, request, *args, **kwargs): channel_data = self.get_channel_data(*args, **kwargs) chcoll_data: Optional[ChannelCollectionModel] = \ ChannelCollectionManager.get_chcoll_child_channel(channel_data.model.id) root_oid = get_root_oid(request) channel_name = channel_data.model.get_channel_name(root_oid) msgdata_1d = MessageStatsDataProcessor.get_user_channel_messages(channel_data.model, hours_within=24) msgdata_7d = MessageStatsDataProcessor.get_user_channel_messages(channel_data.model, hours_within=168) member_info = InfoProcessor.get_member_info(channel_data.model) return render_template( self.request, _("Channel Info - {}").format(channel_name), "info/channel/main.html", { "channel_name": channel_name, "channel_data": channel_data.model, "chcoll_data": chcoll_data, "user_message_data1d": msgdata_1d, "user_message_data7d": msgdata_7d, "member_info": member_info, "manageable": bool(ProfileManager.get_user_profiles(channel_data.model.id, root_oid)), "bot_usage_7d": BotFeatureUsageDataManager.get_channel_usage(channel_data.model.id, hours_within=168), "bot_usage_all": BotFeatureUsageDataManager.get_channel_usage(channel_data.model.id) }, nav_param=kwargs)
def get(self, request, *args, **kwargs): # `kwargs` will be used as `nav_param` so extract channel_oid from `kwargs` instead of creating param. channel_oid_str = kwargs.get("channel_oid", "") channel_oid = safe_cast(channel_oid_str, ObjectId) u_profs = ProfileManager.get_user_profiles(channel_oid, get_root_oid(request)) if u_profs: return render_template( self.request, _("Channel Management - {}").format(channel_oid), "account/channel/manage.html", { "user_profiles": u_profs, "perm_sum": sorted(ProfileManager.get_permissions(u_profs), key=lambda x: x.code), "channel_oid": channel_oid }, nav_param=kwargs) else: c_prof = ChannelManager.get_channel_oid(channel_oid) if c_prof: messages.info( request, _("You are redirected to the channel info page " "because you don't have any connections linked to the channel."), extra_tags="info" ) return redirect(reverse("info.channel", kwargs={"channel_oid": channel_oid})) else: return WebsiteErrorView.website_error( request, WebsiteError.PROFILE_LINK_NOT_FOUND, {"channel_oid": channel_oid_str})
def get(self, request, **kwargs): profile_result = get_profile_data(kwargs) if not profile_result.ok: return WebsiteErrorView.website_error( request, WebsiteError.PROFILE_NOT_FOUND, {"profile_oid": profile_result.oid_org}) root_oid = get_root_oid(request) profile_model = profile_result.model channel_model = ChannelManager.get_channel_oid( profile_model.channel_oid) permissions = ProfileManager.get_user_permissions( channel_model.id, root_oid) # noinspection PyTypeChecker return render_template( request, _("Profile Info - {}").format(profile_model.name), "info/profile.html", { "profile_data": profile_model, "profile_controls": ProfileHelper.get_user_profile_controls( channel_model, profile_model.id, root_oid, permissions), "perm_cats": list(ProfilePermission), "is_default": profile_model.id == channel_model.config.default_profile_oid }, nav_param=kwargs)
def get(self, request, *args, **kwargs): keyword = request.GET.get("w", "") channel_list = [] if keyword: channel_list = IdentitySearcher.search_channel(keyword, get_root_oid(request)) return render_template( self.request, _("Channel Info Search"), "info/channel/search.html", {"channel_list": channel_list, "keyword": keyword}, nav_param=kwargs)
def get(self, request, *args, **kwargs): config = RootUserManager.get_config_root_oid(get_root_oid(request)) return render_template( self.request, _("Account Settings"), "account/settings.html", { "locale_list": sorted(locales, key=lambda item: item.description), "lang_list": sorted(languages, key=lambda item: item.code), "current_config": config })
def get(self, request, *args, **kwargs): response = render_template(request, _("Logout"), "account/logout.html") response.delete_cookie(keys.Cookies.USER_TOKEN) try: del request.session[keys.Session.USER_ROOT_ID] request.session.modified = True except KeyError: pass return response
def get(self, request, *args, **kwargs): channel_data = self.get_channel_data(*args, **kwargs) hours_within = safe_cast(request.GET.get("hours_within"), int) incl_unav = safe_cast(request.GET.get("incl_unav"), bool) period_count = safe_cast(request.GET.get("period"), int) or Website.Message.DefaultPeriodCount if period_count <= 0: messages.warning(request, _("Period count cannot be less than or equal to 0.")) period_count = Website.Message.DefaultPeriodCount # Get starting timestamp dt_start = self.get_timestamp( request, "start", msg_parse_failed=_("Failed to parse the starting timestamp. Received: {}"), msg_out_of_range=_("Start time out of range.") ) # Get ending timestamp dt_end = self.get_timestamp( request, "end", msg_parse_failed=_("Failed to parse the ending timestamp. Received: {}"), msg_out_of_range=_("End time out of range.") ) # Check starting and ending timestamp if dt_start and dt_end and dt_start > dt_end: dt_start = None dt_end = None messages.warning( request, _("Invalid timestamp: Ending time is before the starting time.")) channel_name = channel_data.model.get_channel_name(get_root_oid(request)) pkg = get_msg_stats_data_package( channel_data.model, get_current_timezone(), incl_unav, hours_within=hours_within, start=dt_start, end=dt_end, period_count=period_count) hours_within = pkg[KEY_MSG_INTV_FLOW].hr_range or hours_within msg_count = pkg[KEY_MSG_USER_CHANNEL].msg_count ctxt = { "channel_name": channel_name, "channel_data": channel_data.model, "hr_range": hours_within, "dt_start": dt_start.replace(tzinfo=None).isoformat() if dt_start else "", "dt_end": dt_end.replace(tzinfo=None).isoformat() if dt_end else "", "message_frequency": (hours_within * 3600) / msg_count if msg_count > 0 else 0, "incl_unav": incl_unav, "period_count": period_count } ctxt.update(pkg) return render_template( self.request, _("Channel Message Stats - {}").format(channel_name), "info/msgstats/main.html", ctxt, nav_param=kwargs)
def get(self, request, *args, **kwargs): context = {"target_range_mi": ExtraService.Maskfinder.TargetRangeMi} zip_code = request.GET.get("zip") if zip_code: context["zip_code"] = zip_code context["results"] = get_results( zip_code, ExtraService.Maskfinder.TargetRangeMi) return render_template(self.request, _("Maskfinder (US Only)"), "services/maskfinder/main.html", context)
def get(self, request, page_id, *args, **kwargs): page_content = ExtraContentManager.get_content(page_id) d = {"page_id": page_id} if page_content: title = page_content.title if page_content.title != ExtraContentManager.DefaultTitle else page_id return render_template(request, _("Extra Content - {}").format(title), "exctnt.html", { "content": page_content.content_html, "expiry": page_content.expires_on }, nav_param=d) else: return WebsiteErrorView.website_error(request, WebsiteError.EXTRA_CONTENT_NOT_FOUND, d, nav_param=d)
def get(self, request, *args, **kwargs): channel_result = self.get_channel_data(*args, **kwargs) permissions = ProfileManager.get_user_permissions(channel_result.model.id, get_root_oid(request)) can_ced_profile = ProfilePermission.PRF_CED in permissions return render_template( self.request, _("List Profile"), "account/channel/prof/list.html", { "prof_entry": ProfileHelper.get_channel_profiles(channel_result.model.id), "perm_cats": list(ProfilePermission), "can_ced_profile": can_ced_profile, "channel_oid": channel_result.model.id }, nav_param=kwargs)
def get(self, request, *args, **kwargs): root_oid = get_root_oid(request) channel_data = self.get_channel_data(*args, **kwargs) profiles = ProfileManager.get_user_profiles(channel_data.model.id, root_oid) max_perm_lv = ProfileManager.get_highest_permission_level(profiles) return render_template( self.request, _("Create Profile"), "account/channel/prof/create.html", { "channel_oid": channel_data.model.id, "max_perm_lv": max_perm_lv, "perm_cats_controllable": ProfilePermissionDefault.get_overridden_permissions(max_perm_lv), "perm_cats": list(ProfilePermission), "value_color": ColorFactory.DEFAULT.color_hex }, nav_param=kwargs)
def get(self, request, *args, **kwargs): profile_result = get_profile_data(kwargs) if not profile_result.ok: return WebsiteErrorView.website_error( request, WebsiteError.PROFILE_NOT_FOUND, {"profile_oid": profile_result.oid_org}) profile_model = profile_result.model return render_template( self.request, _("Edit Profile"), "account/channel/prof/edit.html", { "value_color": profile_model.color.color_hex, "value_name": profile_model.name }, nav_param=kwargs)
def get(self, request, *args, **kwargs): root_oid = get_root_oid(request) access_ok = [] access_no = [] for channel_conn in ProfileManager.get_user_channel_profiles(root_oid, accessbible_only=False): if channel_conn.channel_data.bot_accessible: access_ok.append(channel_conn) else: access_no.append(channel_conn) return render_template( self.request, _("Channel List"), "account/channel/list.html", { "conn_access_ok": access_ok, "conn_access_no": access_no, "bot_cmd_info_code": cmd_id.main_cmd_code })
def get(self, request, *args, **kwargs): u_data = RootUserManager.get_root_data_api_token( self.request.COOKIES[keys.Cookies.USER_TOKEN]) excde_list = ExecodeManager.get_queued_execodes(u_data.model.id) return render_template( self.request, _("Account Home"), "account/main.html", { "root_data": u_data.model, "api_user_data": u_data.model_api, "execode_list": excde_list, "onplat_user_data_list": u_data.model_onplat_list, "reg_time_str": t_delta_str(now_utc_aware() - u_data.model.id.generation_time) })
def get(self, request, *args, **kwargs): root_oid = get_root_oid(request) channel_data = self.get_channel_data(*args, **kwargs) channel_oid = channel_data.model.id attach_member = ProfileManager.can_control_profile_member( ProfileManager.get_user_permissions(channel_oid, root_oid)) member_list = {} if attach_member: member_list = IdentitySearcher.get_batch_user_name( ProfileManager.get_channel_member_oids(channel_oid, available_only=True), channel_data.model) member_list = sorted(member_list.items(), key=lambda item: item[1]) return render_template( self.request, _("Attach Profile"), "account/channel/prof/attach.html", { "channel_oid": channel_oid, "attachable_profiles": ProfileManager.get_attachable_profiles(channel_data.model.get_oid(), root_oid), "member_list": member_list }, nav_param=kwargs)
def get(self, request, *args, **kwargs): # `kwargs` will be used as `nav_param` so extract chcoll_oid from `kwargs` instead of creating param. # `chcoll_oid` may be misformatted. # If so, `safe_cast` will yield `None` while the original parameter needs to be kept for the case of not found. chcoll_oid_str = kwargs.get("chcoll_oid", "") chcoll_oid = safe_cast(chcoll_oid_str, ObjectId) chcoll_data: Optional[ ChannelCollectionModel] = ChannelCollectionManager.get_chcoll_oid( chcoll_oid) if not chcoll_data: return WebsiteErrorView.website_error( request, WebsiteError.CHANNEL_COLLECTION_NOT_FOUND, {"chcoll_oid": chcoll_oid_str}, nav_param=kwargs) msgdata_1d = MessageStatsDataProcessor.get_user_chcoll_messages( chcoll_data, hours_within=24) msgdata_7d = MessageStatsDataProcessor.get_user_chcoll_messages( chcoll_data, hours_within=168) return render_template( self.request, _("Channel Collection Info - {}").format(chcoll_oid), "info/chcoll/main.html", { "chcoll_data": chcoll_data, "chcoll_cch_data": InfoProcessor.collate_child_channel_data( get_root_oid(request), chcoll_data.child_channel_oids), "user_message_data1d": msgdata_1d, "user_message_data7d": msgdata_7d }, nav_param=kwargs)
def get(self, request, *args, **kwargs): channel_data = self.get_channel_data(*args, **kwargs) # Check if the user is in the channel root_oid = get_root_oid(request) profs = ProfileManager.get_user_profiles(channel_data.model.id, root_oid) if not profs or profs == ChannelProfileConnectionModel.ProfileOids.none_obj( ): return WebsiteErrorView.website_error( request, WebsiteError.NOT_IN_THE_CHANNEL, {"channel_oid": channel_data.oid_org}, nav_param=kwargs) # Process the necessary data channel_name = channel_data.model.get_channel_name(root_oid) limit = get_limit(request.GET, Website.RecentActivity.MaxMessageCount) ctxt = { "channel_name": channel_name, "channel_data": channel_data.model, "recent_msg_limit": limit or "", "recent_msg_limit_max": Website.RecentActivity.MaxMessageCount, "recent_msg_data": MessageStatsDataProcessor.get_recent_messages( channel_data.model, limit) } return render_template(self.request, _("Recent Messages - {}").format(channel_name), "info/recent/message.html", ctxt, nav_param=kwargs)
def get(self, request, *args, **kwargs): channel_data = self.get_channel_data(*args, **kwargs) hours_within = safe_cast(request.GET.get("hours_within"), int) # channel_members = ProfileManager.get_channel_members(channel_oid) # Reserved for per member analysis channel_name = channel_data.model.get_channel_name( get_root_oid(request)) pkg = get_bot_stats_data_package(channel_data.model, hours_within, get_current_timezone()) ctxt = { "channel_name": channel_name, "channel_data": channel_data.model, "hr_range": hours_within or pkg[KEY_HR_FLOW].hr_range } ctxt.update(pkg) return render_template(self.request, _("Bot Usage Stats - {}").format(channel_name), "info/botstats/main.html", ctxt, nav_param=kwargs)
def get(self, request, *args, **kwargs): return render_template( self.request, _("Short URL Service"), "services/shorturl/main.html", {"records": ShortUrlDataManager.get_user_record(get_root_oid(request))})
def get(self, request, *args, **kwargs): return render_template(request, _("Login"), "account/login.html")
def get(self, request, *args, **kwargs): return render_template( self.request, _("Channel Register"), "account/channel/register.html", {"register_cooldown": ExecodeManager.ChannelRegisterExecodeCooldownSeconds})
def get(self, request, *args, **kwargs): return render_template( request, _("Integrate User Data"), "account/integrate.html", { "cmd_code": cmd_uintg.main_cmd_code, "excde_type_code": Execode.INTEGRATE_USER_DATA.code })