Skip to content

Commit

Permalink
Merge branch 'main' into whatsapp-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed May 11, 2023
2 parents d41b5b6 + f43465c commit e6f95f1
Show file tree
Hide file tree
Showing 277 changed files with 9,538 additions and 8,311 deletions.
32 changes: 15 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ repos:
hooks:
- id: check-pre-commit-ci-config
- repo: https://github.com/peterdemin/pip-compile-multi
rev: v2.6.2
rev: v2.6.3
hooks:
- id: pip-compile-multi-verify
files: ^requirements/.*\.(in|txt)$
- repo: https://github.com/pypa/pip-audit
rev: v2.4.15
rev: v2.5.5
hooks:
- id: pip-audit
args: [
'--no-deps',
'--fix',
'--skip-editable',
'-r',
'requirements/base.txt',
'-r',
Expand All @@ -35,6 +35,12 @@ repos:
'PYSEC-2022-42969', # https://github.com/pytest-dev/pytest/issues/10392
]
files: ^requirements/.*\.txt$
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.265
hooks:
- id: ruff
args: ['--fix', '--exit-non-zero-on-fix']
# Extra args, only after removing flake8 and yesqa: '--extend-select', 'RUF100'
- repo: https://github.com/lucasmbrown/mirrors-autoflake
rev: v1.3
hooks:
Expand All @@ -48,7 +54,7 @@ repos:
'--remove-duplicate-keys',
]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.4.0
hooks:
- id: pyupgrade
args:
Expand Down Expand Up @@ -81,7 +87,7 @@ repos:
additional_dependencies:
- tomli
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
# Mypy is temporarily disabled until the SQLAlchemy 2.0 migration is complete
Expand All @@ -105,7 +111,7 @@ repos:
- id: flake8
additional_dependencies: *flake8deps
- repo: https://github.com/PyCQA/pylint
rev: v2.16.4
rev: v3.0.0a6
hooks:
- id: pylint
args: [
Expand All @@ -115,16 +121,15 @@ repos:
'--ignore-paths=tests,migrations',
]
additional_dependencies:
- pylint-pytest
- tomli
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
rev: 1.7.5
hooks:
- id: bandit
language_version: python3
args: ['-c', 'pyproject.toml']
additional_dependencies:
- toml
- 'bandit[toml]'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down Expand Up @@ -160,19 +165,12 @@ repos:
- id: trailing-whitespace
args: ['--markdown-linebreak-ext=md']
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.6
rev: v3.0.0-alpha.9-for-vscode
hooks:
- id: prettier
args:
['--single-quote', '--trailing-comma', 'es5', '--end-of-line', 'lf']
exclude: funnel/templates/js/
- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.19.16
hooks:
- id: djlint-jinja
files: \.html\.(jinja2|j2)$
- id: djlint-handlebars
files: \.html\.(mustache|hb)$
- repo: https://github.com/ducminh-phan/reformat-gherkin
rev: v3.0.1
hooks:
Expand Down
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ all:
@echo
@echo "For development:"
@echo " make install-dev # For first time setup and after dependency upgrades"
@echo " make deps # Scan for dependency upgrades (and test afterwards!)"
@echo " make deps-noup # Rebuild for dependency changes, but skip upgrades"
@echo " make deps # Scan for dependency upgrades (remember to test!)"
@echo " make deps-python # Scan for Python dependency upgrades"
@echo " make deps-npm # Scan for NPM dependency upgrades"
@echo
Expand All @@ -23,7 +24,7 @@ all:

babelpy:
ZXCVBN_DIR=`python -c "import zxcvbn; import pathlib; print(pathlib.Path(zxcvbn.__file__).parent, end='')"`
pybabel extract -F babel.cfg -k _ -k __ -k ngettext -o funnel/translations/messages.pot . ${ZXCVBN_DIR}
pybabel extract -F babel.cfg -k _ -k __ -k _n -k __n -k gettext -k ngettext -o funnel/translations/messages.pot funnel ${ZXCVBN_DIR}
pybabel update -N -i funnel/translations/messages.pot -d funnel/translations
pybabel compile -f -d funnel/translations

Expand All @@ -33,8 +34,8 @@ babeljs: baseframe_dir = $(flask baseframe_translations_path)

babeljs:
@mkdir -p $(target_dir)
ls $(source_dir) | grep -E '[[:lower:]]{2}_[[:upper:]]{2}' | xargs -I % sh -c 'mkdir -p $(target_dir)/% && ./node_modules/.bin/po2json --format=jed --pretty $(source_dir)/%/LC_MESSAGES/messages.po $(target_dir)/%/messages.json'
ls $(baseframe_dir) | grep -E '[[:lower:]]{2}_[[:upper:]]{2}' | xargs -I % sh -c './node_modules/.bin/po2json --format=jed --pretty $(baseframe_dir)/%/LC_MESSAGES/baseframe.po $(target_dir)/%/baseframe.json'
ls $(source_dir) | grep -E '[[:lower:]]{2}_[[:upper:]]{2}' | xargs -I % sh -c 'mkdir -p $(target_dir)/% && ./node_modules/.bin/po2json --format=jed --pretty --domain=messages $(source_dir)/%/LC_MESSAGES/messages.po $(target_dir)/%/messages.json'
ls $(baseframe_dir) | grep -E '[[:lower:]]{2}_[[:upper:]]{2}' | xargs -I % sh -c './node_modules/.bin/po2json --format=jed --pretty --domain=baseframe $(baseframe_dir)/%/LC_MESSAGES/baseframe.po $(target_dir)/%/baseframe.json'
./node_modules/.bin/prettier --write $(target_dir)/**/**.json

babel: babelpy babeljs
Expand Down Expand Up @@ -78,6 +79,8 @@ deps-python-verify:
deps-npm:
npm update

deps-noup: deps-python-noup

deps: deps-python deps-npm

install-npm:
Expand All @@ -87,16 +90,16 @@ install-npm-ci:
npm clean-install

install-python-pip:
pip install --upgrade pip setuptools
pip install --upgrade pip

install-python-dev: install-python-pip deps-editable
pip install -r requirements/dev.txt
pip install --use-pep517 -r requirements/dev.txt

install-python-test: install-python-pip deps-editable
pip install -r requirements/test.txt
pip install --use-pep517 -r requirements/test.txt

install-python: install-python-pip deps-editable
pip install -r requirements/base.txt
pip install --use-pep517 -r requirements/base.txt

install-dev: deps-editable install-python-dev install-npm assets

Expand Down
2 changes: 1 addition & 1 deletion babel.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ extensions=jinja2.ext.do,webassets.ext.jinja2.AssetsExtension
[javascript: **/assets/js/**.js]
[javascript: **/static/js/**.js]
encoding = utf-8
extract_messages=gettext,ngettext
extract_messages=_,__,_n,__n,gettext,ngettext
4 changes: 2 additions & 2 deletions devserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
sys.path.insert(0, os.path.dirname(__file__))
os.environ['FLASK_ENV'] = 'development' # Needed for coaster.app.init_app
os.environ.setdefault('FLASK_DEBUG', '1')
debug_mode = not os.environ['FLASK_DEBUG'].lower() in {'0', 'false', 'no'}
debug_mode = os.environ['FLASK_DEBUG'].lower() not in {'0', 'false', 'no'}

from funnel import rq
from funnel.devtest import BackgroundWorker, devtest_app
Expand All @@ -21,7 +21,7 @@
background_rq = None
if os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
# Only start RQ worker within the reloader environment
background_rq = BackgroundWorker(rq.get_worker().work)
background_rq = BackgroundWorker(rq.get_worker().work, mock_transports=True)
background_rq.start()

run_simple(
Expand Down
8 changes: 1 addition & 7 deletions funnel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,11 @@
requires=['funnel'],
ext_requires=[
'pygments',
'toastr',
'jquery.cookie',
'timezone',
'pace',
'jquery-modal',
'select2-material',
'getdevicepixelratio',
'jquery.truncate8',
'funnel-mui',
],
theme='funnel',
asset_modules=('baseframe_private_assets',),
error_handlers=False,
)

Expand Down Expand Up @@ -185,6 +178,7 @@
'moment.js',
'moment-timezone-data.js',
'spectrum.js',
'toastr.js',
'jquery.ui.sortable.touch.js',
),
output='js/fullcalendar.packed.js',
Expand Down
5 changes: 3 additions & 2 deletions funnel/assets/js/account_form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'htmx.org';
import toastr from 'toastr';
import Form from './utils/formhelper';

window.Hasgeek.Accountform = ({
Expand Down Expand Up @@ -37,7 +38,7 @@ window.Hasgeek.Accountform = ({
csrf_token: $('meta[name="csrf-token"]').attr('content'),
}),
}).catch(() => {
window.toastr.error(window.Hasgeek.Config.errorMsg.networkError);
toastr.error(window.Hasgeek.Config.errorMsg.networkError);
});
if (response && response.ok) {
const remoteData = await response.json();
Expand Down Expand Up @@ -82,7 +83,7 @@ window.Hasgeek.Accountform = ({
csrf_token: $('meta[name="csrf-token"]').attr('content'),
}),
}).catch(() => {
window.toastr.error(window.Hasgeek.Config.errorMsg.networkError);
toastr.error(window.Hasgeek.Config.errorMsg.networkError);
});
if (response && response.ok) {
const remoteData = await response.json();
Expand Down
115 changes: 28 additions & 87 deletions funnel/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
/* global jstz, Pace */

import 'jquery-modal';
import 'trunk8';
import jstz from 'jstz';
import 'jquery.cookie';
import Utils from './utils/helper';
import WebShare from './utils/webshare';
import ScrollHelper from './utils/scrollhelper';
import loadLangTranslations from './utils/translations';
import LazyloadImg from './utils/lazyloadimage';
import Form from './utils/formhelper';
import Modal from './utils/modalhelper';
import Analytics from './utils/analytics';
import Tabs from './utils/tabs';
import updateParsleyConfig from './utils/update_parsley_config';
import ReadStatus from './utils/read_status';
import LazyLoadMenu from './utils/lazyloadmenu';

const pace = require('pace-js');

$(() => {
window.Hasgeek.Config.availableLanguages = {
en: 'en_IN',
hi: 'hi_IN',
};
window.Hasgeek.Config.mobileBreakpoint = 768; // this breakpoint switches to desktop UI
window.Hasgeek.Config.ajaxTimeout = 30000;
window.Hasgeek.Config.retryInterval = 10000;
window.Hasgeek.Config.closeModalTimeout = 10000;
window.Hasgeek.Config.refreshInterval = 60000;
window.Hasgeek.Config.notificationRefreshInterval = 300000;
window.Hasgeek.Config.readReceiptTimeout = 5000;
window.Hasgeek.Config.saveEditorContentTimeout = 300;
window.Hasgeek.Config.userAvatarImgSize = {
big: '160',
medium: '80',
small: '48',
};
/* eslint-disable no-console */
console.log(
'Hello, curious geek. Our source is at https://github.com/hasgeek. Why not contribute a patch?'
);

loadLangTranslations();
window.Hasgeek.Config.errorMsg = {
serverError: window.gettext(
Expand All @@ -41,66 +37,20 @@ $(() => {
Utils.collapse();
ScrollHelper.smoothScroll();
Utils.navSearchForm();
Utils.headerMenuDropdown(
'.js-menu-btn',
'.js-account-menu-wrapper',
'.js-account-menu',
window.Hasgeek.Config.accountMenu
);
ScrollHelper.scrollTabs();
Tabs.init();
Utils.truncate();
Utils.showTimeOnCalendar();
Utils.popupBackHandler();
Form.handleModalForm();
if ($('.header__nav-links--updates').length) {
Utils.updateNotificationStatus();
window.setInterval(
Utils.updateNotificationStatus,
window.Hasgeek.Config.notificationRefreshInterval
);
}
Utils.addWebShare();
if (window.Hasgeek.Config.commentSidebarElem) {
Utils.headerMenuDropdown(
'.js-comments-btn',
'.js-comments-wrapper',
'.js-comment-sidebar',
window.Hasgeek.Config.unreadCommentUrl
);
}
Utils.sendNotificationReadStatus();

const intersectionObserverComponents = function intersectionObserverComponents() {
LazyloadImg.init('js-lazyload-img');
};

if (
document.querySelector('.js-lazyload-img') ||
document.querySelector('.js-lazyload-results')
) {
if (
!(
'IntersectionObserver' in global &&
'IntersectionObserverEntry' in global &&
'intersectionRatio' in IntersectionObserverEntry.prototype
)
) {
const polyfill = document.createElement('script');
polyfill.setAttribute('type', 'text/javascript');
polyfill.setAttribute(
'src',
'https://cdn.polyfill.io/v2/polyfill.min.js?features=IntersectionObserver'
);
polyfill.onload = function loadintersectionObserverComponents() {
intersectionObserverComponents();
};
document.head.appendChild(polyfill);
} else {
intersectionObserverComponents();
}
}
Modal.addUsability();
Analytics.init();
WebShare.addWebShare();
ReadStatus.init();
LazyLoadMenu.init();
LazyloadImg.init('js-lazyload-img');
// Request for new CSRF token and update the page every 15 mins
setInterval(Utils.csrfRefresh, 900000);

// Add polyfill
if (!('URLSearchParams' in window)) {
const polyfill = document.createElement('script');
polyfill.setAttribute('type', 'text/javascript');
Expand All @@ -111,21 +61,12 @@ $(() => {
document.head.appendChild(polyfill);
}

// Send click events to Google analytics
$('.mui-btn, a').click(function gaHandler() {
const action = $(this).attr('data-ga') || $(this).attr('title') || $(this).html();
const target = $(this).attr('data-target') || $(this).attr('href') || '';
Analytics.sendToGA('click', action, target);
});
$('.search-form__submit').click(function gaHandler() {
const target = $('.js-search-field').val();
Analytics.sendToGA('search', target, target);
});

// Detect timezone for login
if ($.cookie('timezone') === null) {
$.cookie('timezone', jstz.determine().name(), { path: '/' });
}

updateParsleyConfig();
});

if (
Expand All @@ -137,6 +78,6 @@ if (
) {
$('.pace').addClass('pace-hide');
window.onbeforeunload = function stopPace() {
Pace.stop();
pace.stop();
};
}
Loading

0 comments on commit e6f95f1

Please sign in to comment.