def test_geoip(self): session = Session() db_file_path = get_fixture("GeoIPCountryCSV.zip") self.assertTrue(geoip.update(session, db_file_path)) self.assertEqual(10, session.query(geoip.models.GeoIP).count()) self.assertEqual("AU", geoip.find_country(session, 16777217)) self.assertEqual("AU", geoip.find_country(session, net.int2ip(16777217))) self.assertIsNone(geoip.find_country(session, 1000))
def test_geoip(self): session = Session() db_file_path = get_fixture("GeoIPCountryCSV.zip") self.assertTrue(geoip.update(session, db_file_path)) self.assertEqual(10, session.query(geoip.models.GeoIP).count()) self.assertEqual("AU", geoip.find_country_code(session, 16777217)) self.assertEqual("AU", geoip.find_country_code(session, net.int2ip(16777217))) self.assertIsNone(geoip.find_country_code(session, 1000))
def index(): """ Show the home view which is mostly a dashboard type view so we are calculating metrics for various areas TODO remove the 2nd download query once we fix not having a source_id, or at least make sure its not actually a problem :return: Mostly metric data and newest releases :rtype: dict """ session = Session() downloads = session.query(Download).filter(Download.source_id > 0).all() provider_totals = stats.count_totals(downloads, lambda v: v.source.source_name).items() section_totals = stats.count_totals(downloads, lambda v: v.section.section_name).items() provider_type_totals = stats.provider_type_counter(downloads).items() newest = Session.query(Download).order_by(Download.entity_id.desc()).limit(25).all() return dict( newest=newest, provider_totals=provider_totals, section_totals=section_totals, provider_type_totals=provider_type_totals, )
def index(): """ Show the home view which is mostly a dashboard type view so we are calculating metrics for various areas TODO remove the 2nd download query once we fix not having a source_id, or at least make sure its not actually a problem :return: Mostly metric data and newest releases :rtype: dict """ session = Session() downloads = session.query(Download).filter(Download.source_id > 0).all() provider_totals = stats.count_totals( downloads, lambda v: v.source.source_name).items() section_totals = stats.count_totals( downloads, lambda v: v.section.section_name).items() provider_type_totals = stats.provider_type_counter(downloads).items() newest = Session.query(Download).order_by( Download.entity_id.desc()).limit(25).all() return dict(newest=newest, provider_totals=provider_totals, section_totals=section_totals, provider_type_totals=provider_type_totals)
def login_perform(): """ Handle a user login form :return: Redirect the user to the previous page or the home index :rtype: dict """ try: user_name = request.values['user_name'] user_password = request.values['user_password'] except KeyError: pass else: session = Session() user = session.query(User).filter_by(user_name=user_name).first() if not user or not user.password == hashlib.sha1(user_password).hexdigest(): flash("Invalid credentials", "alert") return redirect(url_for(".login")) try: remember = request.values['remember'].lower() == "on" except KeyError: remember = False login_user(user, remember=remember) return redirect(request.args.get("next") or url_for("home.index"))
def login_perform(): """ Handle a user login form :return: Redirect the user to the previous page or the home index :rtype: dict """ try: user_name = request.values['user_name'] user_password = request.values['user_password'] except KeyError: pass else: session = Session() user = session.query(User).filter_by(user_name=user_name).first() if not user or not user.password == hashlib.sha1( user_password).hexdigest(): flash("Invalid credentials", "alert") return redirect(url_for(".login")) try: remember = request.values['remember'].lower() == "on" except KeyError: remember = False login_user(user, remember=remember) return redirect(request.args.get("next") or url_for("home.index"))