Black/add assets to package/update pyproject.toml
This commit is contained in:
parent
05c153dc77
commit
af8380070a
|
@ -1,4 +1,4 @@
|
||||||
include README.rst
|
include README.rst
|
||||||
include LICENSE.txt
|
include LICENSE.txt
|
||||||
include requirements.txt
|
include requirements.txt
|
||||||
recursive-include ckanext/googleanalytics *.html *.js
|
recursive-include ckanext/googleanalytics *.html *.js *.json *.css *.yml *.mo
|
||||||
|
|
|
@ -22,19 +22,17 @@ DATASET_EDIT_REGEX = re.compile("/dataset/edit/([a-z0-9-_]+)")
|
||||||
|
|
||||||
|
|
||||||
def get_commands():
|
def get_commands():
|
||||||
return [
|
return [googleanalytics]
|
||||||
googleanalytics
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
@click.group(short_help=u"GoogleAnalytics commands")
|
@click.group(short_help=u"GoogleAnalytics commands")
|
||||||
def googleanalytics():
|
def googleanalytics():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@googleanalytics.command()
|
@googleanalytics.command()
|
||||||
def init():
|
def init():
|
||||||
"""Initialise the local stats database tables
|
"""Initialise the local stats database tables"""
|
||||||
"""
|
|
||||||
model.Session.remove()
|
model.Session.remove()
|
||||||
model.Session.configure(bind=model.meta.engine)
|
model.Session.configure(bind=model.meta.engine)
|
||||||
dbutil.init_tables()
|
dbutil.init_tables()
|
||||||
|
@ -75,9 +73,11 @@ def _resource_url_tag():
|
||||||
|
|
||||||
|
|
||||||
def _recent_view_days():
|
def _recent_view_days():
|
||||||
return tk.asint(tk.config.get(
|
return tk.asint(
|
||||||
"googleanalytics.recent_view_days", DEFAULT_RECENT_VIEW_DAYS
|
tk.config.get(
|
||||||
))
|
"googleanalytics.recent_view_days", DEFAULT_RECENT_VIEW_DAYS
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -253,8 +253,7 @@ def get_ga_data_new(service, profile_id, start_date=None, end_date=None):
|
||||||
|
|
||||||
|
|
||||||
def save_ga_data(packages_data):
|
def save_ga_data(packages_data):
|
||||||
"""Save tuples of packages_data to the database
|
"""Save tuples of packages_data to the database"""
|
||||||
"""
|
|
||||||
for identifier, visits in list(packages_data.items()):
|
for identifier, visits in list(packages_data.items()):
|
||||||
recently = visits.get("recent", 0)
|
recently = visits.get("recent", 0)
|
||||||
ever = visits.get("ever", 0)
|
ever = visits.get("ever", 0)
|
||||||
|
@ -287,10 +286,13 @@ def save_ga_data(packages_data):
|
||||||
|
|
||||||
|
|
||||||
def ga_query(
|
def ga_query(
|
||||||
service, profile_id, query_filter=None, from_date=None, metrics=None,
|
service,
|
||||||
|
profile_id,
|
||||||
|
query_filter=None,
|
||||||
|
from_date=None,
|
||||||
|
metrics=None,
|
||||||
):
|
):
|
||||||
"""Execute a query against Google Analytics
|
"""Execute a query against Google Analytics"""
|
||||||
"""
|
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
to_date = now.strftime("%Y-%m-%d")
|
to_date = now.strftime("%Y-%m-%d")
|
||||||
if isinstance(from_date, datetime.date):
|
if isinstance(from_date, datetime.date):
|
||||||
|
|
|
@ -23,8 +23,7 @@ DATASET_EDIT_REGEX = re.compile("/dataset/edit/([a-z0-9-_]+)")
|
||||||
|
|
||||||
|
|
||||||
class InitDB(CkanCommand):
|
class InitDB(CkanCommand):
|
||||||
"""Initialise the local stats database tables
|
"""Initialise the local stats database tables"""
|
||||||
"""
|
|
||||||
|
|
||||||
summary = __doc__.split("\n")[0]
|
summary = __doc__.split("\n")[0]
|
||||||
usage = __doc__
|
usage = __doc__
|
||||||
|
@ -65,9 +64,11 @@ class LoadAnalytics(CkanCommand):
|
||||||
self.resource_url_tag = self.CONFIG.get(
|
self.resource_url_tag = self.CONFIG.get(
|
||||||
"googleanalytics_resource_prefix", DEFAULT_RESOURCE_URL_TAG
|
"googleanalytics_resource_prefix", DEFAULT_RESOURCE_URL_TAG
|
||||||
)
|
)
|
||||||
self.recent_view_days = asint(self.CONFIG.get(
|
self.recent_view_days = asint(
|
||||||
"googleanalytics.recent_view_days", DEFAULT_RECENT_VIEW_DAYS
|
self.CONFIG.get(
|
||||||
))
|
"googleanalytics.recent_view_days", DEFAULT_RECENT_VIEW_DAYS
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# funny dance we need to do to make sure we've got a
|
# funny dance we need to do to make sure we've got a
|
||||||
# configured session
|
# configured session
|
||||||
|
@ -267,8 +268,7 @@ class LoadAnalytics(CkanCommand):
|
||||||
log.info("Saved %s records from google" % len(packages_data))
|
log.info("Saved %s records from google" % len(packages_data))
|
||||||
|
|
||||||
def save_ga_data(self, packages_data):
|
def save_ga_data(self, packages_data):
|
||||||
"""Save tuples of packages_data to the database
|
"""Save tuples of packages_data to the database"""
|
||||||
"""
|
|
||||||
for identifier, visits in list(packages_data.items()):
|
for identifier, visits in list(packages_data.items()):
|
||||||
recently = visits.get("recent", 0)
|
recently = visits.get("recent", 0)
|
||||||
ever = visits.get("ever", 0)
|
ever = visits.get("ever", 0)
|
||||||
|
@ -309,8 +309,7 @@ class LoadAnalytics(CkanCommand):
|
||||||
metrics=None,
|
metrics=None,
|
||||||
sort=None,
|
sort=None,
|
||||||
):
|
):
|
||||||
"""Execute a query against Google Analytics
|
"""Execute a query against Google Analytics"""
|
||||||
"""
|
|
||||||
if not to_date:
|
if not to_date:
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
to_date = now.strftime("%Y-%m-%d")
|
to_date = now.strftime("%Y-%m-%d")
|
||||||
|
|
|
@ -15,6 +15,7 @@ from ckan.controllers.api import ApiController
|
||||||
|
|
||||||
from ckan.exceptions import CkanVersionException
|
from ckan.exceptions import CkanVersionException
|
||||||
import ckan.plugins.toolkit as tk
|
import ckan.plugins.toolkit as tk
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tk.requires_ckan_version("2.9")
|
tk.requires_ckan_version("2.9")
|
||||||
except CkanVersionException:
|
except CkanVersionException:
|
||||||
|
|
|
@ -47,7 +47,9 @@ class AnalyticsPostThread(threading.Thread):
|
||||||
log.debug("Sending API event to Google Analytics: " + data)
|
log.debug("Sending API event to Google Analytics: " + data)
|
||||||
# send analytics
|
# send analytics
|
||||||
res = requests.post(
|
res = requests.post(
|
||||||
"http://www.google-analytics.com/collect", data, timeout=10,
|
"http://www.google-analytics.com/collect",
|
||||||
|
data,
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
# signals to queue job is done
|
# signals to queue job is done
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import ckan.plugins as plugins
|
||||||
from ckanext.googleanalytics.views import ga
|
from ckanext.googleanalytics.views import ga
|
||||||
from ckanext.googleanalytics.cli import get_commands
|
from ckanext.googleanalytics.cli import get_commands
|
||||||
|
|
||||||
|
|
||||||
class GAMixinPlugin(plugins.SingletonPlugin):
|
class GAMixinPlugin(plugins.SingletonPlugin):
|
||||||
plugins.implements(plugins.IBlueprint)
|
plugins.implements(plugins.IBlueprint)
|
||||||
plugins.implements(plugins.IClick)
|
plugins.implements(plugins.IClick)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import ckan.views.resource as resource
|
||||||
|
|
||||||
from ckan.common import g
|
from ckan.common import g
|
||||||
|
|
||||||
CONFIG_HANDLER_PATH = 'googleanalytics.download_handler'
|
CONFIG_HANDLER_PATH = "googleanalytics.download_handler"
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
ga = Blueprint("google_analytics", "google_analytics")
|
ga = Blueprint("google_analytics", "google_analytics")
|
||||||
|
@ -40,7 +40,9 @@ def action(logic_function, ver=api.API_MAX_VERSION):
|
||||||
|
|
||||||
|
|
||||||
ga.add_url_rule(
|
ga.add_url_rule(
|
||||||
"/api/action/<logic_function>", methods=["GET", "POST"], view_func=action,
|
"/api/action/<logic_function>",
|
||||||
|
methods=["GET", "POST"],
|
||||||
|
view_func=action,
|
||||||
)
|
)
|
||||||
ga.add_url_rule(
|
ga.add_url_rule(
|
||||||
u"/<int(min=3, max={0}):ver>/action/<logic_function>".format(
|
u"/<int(min=3, max={0}):ver>/action/<logic_function>".format(
|
||||||
|
@ -57,11 +59,9 @@ def download(id, resource_id, filename=None, package_type="dataset"):
|
||||||
handler = import_string(handler_path, silent=True)
|
handler = import_string(handler_path, silent=True)
|
||||||
else:
|
else:
|
||||||
handler = None
|
handler = None
|
||||||
log.warning((
|
log.warning(("Missing {} config option.").format(CONFIG_HANDLER_PATH))
|
||||||
'Missing {} config option.'
|
|
||||||
).format(CONFIG_HANDLER_PATH))
|
|
||||||
if not handler:
|
if not handler:
|
||||||
log.debug('Use default CKAN callback for resource.download')
|
log.debug("Use default CKAN callback for resource.download")
|
||||||
handler = resource.download
|
handler = resource.download
|
||||||
_post_analytics(
|
_post_analytics(
|
||||||
g.user,
|
g.user,
|
||||||
|
@ -71,8 +71,11 @@ def download(id, resource_id, filename=None, package_type="dataset"):
|
||||||
resource_id,
|
resource_id,
|
||||||
)
|
)
|
||||||
return handler(
|
return handler(
|
||||||
package_type=package_type, id=id,
|
package_type=package_type,
|
||||||
resource_id=resource_id, filename=filename)
|
id=id,
|
||||||
|
resource_id=resource_id,
|
||||||
|
filename=filename,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ga.add_url_rule(
|
ga.add_url_rule(
|
||||||
|
|
|
@ -1,3 +1,63 @@
|
||||||
[tool.black]
|
[tool.black]
|
||||||
line-length = 79
|
line-length = 79
|
||||||
include = '\.py$'
|
|
||||||
|
[tool.towncrier]
|
||||||
|
issue_format = ""
|
||||||
|
directory = "changes"
|
||||||
|
package = "ckanext.googleanalytics"
|
||||||
|
package_dir = "ckanext"
|
||||||
|
filename = "CHANGELOG.rst"
|
||||||
|
name = "ckanext-googleanalytics"
|
||||||
|
|
||||||
|
[tool.pyright]
|
||||||
|
pythonVersion = "3.8"
|
||||||
|
include = ["ckanext/googleanalytics"]
|
||||||
|
exclude = [
|
||||||
|
"**/test*",
|
||||||
|
"**/migration",
|
||||||
|
]
|
||||||
|
ignore = [
|
||||||
|
"ckan"
|
||||||
|
]
|
||||||
|
strict = []
|
||||||
|
|
||||||
|
strictParameterNoneValue = true # type must be Optional if default value is None
|
||||||
|
|
||||||
|
reportFunctionMemberAccess = true # non-standard member accesses for functions
|
||||||
|
reportMissingImports = true
|
||||||
|
reportMissingModuleSource = true
|
||||||
|
reportMissingTypeStubs = false
|
||||||
|
reportImportCycles = false
|
||||||
|
reportUnusedImport = false
|
||||||
|
reportUnusedClass = true
|
||||||
|
reportUnusedFunction = true
|
||||||
|
reportUnusedVariable = false
|
||||||
|
reportDuplicateImport = true
|
||||||
|
reportOptionalSubscript = true
|
||||||
|
reportOptionalMemberAccess = true
|
||||||
|
reportOptionalCall = true
|
||||||
|
reportOptionalIterable = true
|
||||||
|
reportOptionalContextManager = true
|
||||||
|
reportOptionalOperand = true
|
||||||
|
reportTypedDictNotRequiredAccess = false # We are using Context in a way that conflicts with this check
|
||||||
|
reportConstantRedefinition = false
|
||||||
|
reportIncompatibleMethodOverride = false
|
||||||
|
reportIncompatibleVariableOverride = true
|
||||||
|
reportOverlappingOverload = true
|
||||||
|
reportUntypedFunctionDecorator = false
|
||||||
|
reportUnknownParameterType = false # it creates a lot of noise
|
||||||
|
reportUnknownArgumentType = false
|
||||||
|
reportUnknownLambdaType = false
|
||||||
|
reportMissingTypeArgument = true
|
||||||
|
reportInvalidTypeVarUse = true
|
||||||
|
reportCallInDefaultInitializer = true
|
||||||
|
reportUnknownVariableType = false
|
||||||
|
reportUntypedBaseClass = false # ignore it because we are relying on untyped CKAN
|
||||||
|
reportUnnecessaryIsInstance = true
|
||||||
|
reportUnnecessaryCast = true
|
||||||
|
reportUnnecessaryComparison = true
|
||||||
|
reportAssertAlwaysTrue = true
|
||||||
|
reportSelfClsParameterName = true
|
||||||
|
reportUnusedCallResult = false # allow function calls for side-effect only (like logic.check_acces)
|
||||||
|
|
||||||
|
useLibraryCodeForTypes = true
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ import os
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
HERE = os.path.dirname(__file__)
|
HERE = os.path.dirname(__file__)
|
||||||
|
|
||||||
version = "2.0.4"
|
version = "2.0.5"
|
||||||
|
|
||||||
extras_require = {}
|
extras_require = {}
|
||||||
_extras_groups = [
|
_extras_groups = [
|
||||||
|
|
Loading…
Reference in New Issue