def run(self, request, **kwargs): try: user, cookie, key, planet_id = self.router(request) response = self.execute(request, user, **kwargs) session = Session() session.add( PageView( page=self.name, full_request=request.get_full_path(), username=user.name, session=key, planet_id=user.planet.id if user.planet else None, hostname=request.META['REMOTE_ADDR'], )) session.commit() if cookie is not None: response.set_cookie(SESSION_KEY, cookie, expires=request.session.expire) if planet_id is False: response.delete_cookie(PLANET_KEY) elif planet_id is not True: response.set_cookie(PLANET_KEY, planet_id, expires=datetime.now() + timedelta(days=65)) return response except UserError, e: return self.login_page(request, str(e))
def run(self, message): m = self.match(message, self.commandre) if m is None: if self.match(message, self.helpre) is not None: self.help(message) return command = m.group(2) try: route, subcommand, user, params = self.router(message, command) route(message, user, params) session = Session() session.add( Command( command_prefix=message.get_prefix(), command=self.name, subcommand=subcommand, command_parameters=self.hide_passwords( self.name, message.get_msg()[len(m.group(1)) + 1:].strip()), nick=message.get_nick(), username="" if user is True else user.name, hostname=message.get_hostmask(), target=message.get_chan() if message.in_chan() else message.get_nick(), )) session.commit() session.close() except PNickParseError: message.alert(self.PParseError) except UserError: message.alert(self.AccessError) except PrefError: message.alert(self.PrefError) except ChanParseError, e: message.alert(self.ChanError % e)