Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix markup import error #13

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build
on:
push:
schedule:
# runs a new build everyday
- cron: 0 0 * * *

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '>=1.18.1'
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: '**/requirements/test.txt'
- name: Install dependencies
run: pip install -r requirements/test.txt
- name: Style check
run: |
python -m flake8
- name: Tests
run: |
python -m pytest
35 changes: 35 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Generate Coverage Badge

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: pip install -r requirements/test.txt
- name: Set coverage percentage
run: |
echo "COVERAGE=$(pytest | awk '$1 == "TOTAL" {print $NF+0}')%" >> $GITHUB_ENV
REF=${{ github.ref }}
IFS='/' read -ra PATHS <<< "$REF"
BRANCH_NAME="${PATHS[1]}_${PATHS[2]}"
echo "BRANCH=$(echo ${BRANCH_NAME})" >> $GITHUB_ENV
- name: Generate coverage badge
uses: schneegans/dynamic-badges-action@v1.1.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: bc746d7bfe356b54fbb93b2ea5d0d2a4
filename: flask_datepicker__${{ env.BRANCH }}.json
label: coverage
message: ${{ env.COVERAGE }}
color: green
namedLogo: pytest
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<h1 align='center'> Flask-Datepicker </h1>
<p align='center'>
<a href='https://travis-ci.com/mrf345/flask_datepicker'>
<img src='https://travis-ci.com/mrf345/flask_datepicker.svg?branch=master' />
</a>
<a href='https://github.com/mrf345/flask_datepicker/releases'>
<a href='https://pypi.org/project/Flask-Datepicker/'>
<img src='https://img.shields.io/github/v/tag/mrf345/flask_datepicker' alt='Latest Release' />
</a><br/>
<a href='https://coveralls.io/github/mrf345/flask_datepicker?branch=master'>
<img src='https://coveralls.io/repos/github/mrf345/flask_datepicker/badge.svg?branch=master' alt='Coverage Status' />
</a>
<a href='https://www.python.org/dev/peps/pep-0008/'>
<img src='https://img.shields.io/badge/code%20style-PEP8-orange.svg' alt='Code Style' />
</a>
<a href='https://pypi.org/project/Flask-Datepicker/'>
<img src='https://img.shields.io/pypi/dm/flask_datepicker' alt='Number of downloads' />
</a>
</a>
<a href='https://github.com/mrf345/flask_datepicker/actions/workflows/ci.yml'>
<img src='https://github.com/mrf345/flask_datepicker/actions/workflows/ci.yml/badge.svg'>
</a>
<a href='https://github.com/mrf345/flask_datepicker/actions/workflows/ci.yml'>
<img src='https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/mrf345/bc746d7bfe356b54fbb93b2ea5d0d2a4/raw/flask_datepicker__heads_master.json' alt='Coverage Percentage' />
</a>
<br />
<img src='https://img.shields.io/pypi/pyversions/flask_datepicker' alt='Supported versions' />
<br />
</p>

<h3 align='center'>A Flask extension for jQueryUI DatePicker, it makes adding and customizing multiple date pickers simpler and less time consuming.</h3>

## Install:
Expand Down
2 changes: 1 addition & 1 deletion flask_datepicker/about.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.14'
__version__ = '0.15'
__doc__ = 'A Flask extension for jQueryUI DatePicker.'
__license__ = 'MIT'
__author__ = 'Mohamed Feddad'
Expand Down
35 changes: 15 additions & 20 deletions flask_datepicker/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from flask import Markup, url_for
from random import choice

from flask import url_for
from markupsafe import Markup

from flask_datepicker.constants import THEMES, JS_REMOTE, CSS_REMOTE, WINDOWS
from flask_datepicker.utils import find, cache_output

Expand All @@ -20,7 +22,7 @@ def __init__(self, app=None, local=[], version='1.12.1'):
jQuery UI version to fetch remotely, by default '1.12.1'
'''
self.__app = app
self.__local = local
self._local = local
self.__random_theme = choice(THEMES)
self.__version = version

Expand All @@ -43,7 +45,7 @@ def _inject_vars():
return dict(datepicker=self)

@cache_output
def __resolve_local(self, absolute=False):
def _get_resolved_local(self, absolute=False):
'''Check if static folder is `self.__local` and resolve it.

Returns
Expand All @@ -53,7 +55,7 @@ def __resolve_local(self, absolute=False):
'''
folder = self.__app.static_folder
folder_name = os.path.basename(folder)
local = self.__local or []
local = self._local or []
resolved_local = []

for link in local:
Expand All @@ -75,11 +77,11 @@ def __resolve_local(self, absolute=False):

@property
def __resolved_local_abs(self):
return self.__resolve_local(absolute=True)
return self._get_resolved_local(absolute=True)

@property
def __resolved_local_rel(self):
return self.__resolve_local()
return self._get_resolved_local()

def loader(self, theme=None, random_remember=False, version='1.12.1'):
'''Load jQuery UI assets and customize them, if wanted.
Expand All @@ -98,7 +100,7 @@ def loader(self, theme=None, random_remember=False, version='1.12.1'):
str
Safe HTML content to load jQuery UI assets.
'''
links = self.__local or []
links = self._local or []
version = version or self.__version
theme = theme or (self.__random_theme if random_remember else choice(THEMES))
files_not_exist = not all(os.path.isfile(f) for f in self.__resolved_local_abs)
Expand All @@ -112,7 +114,7 @@ def loader(self, theme=None, random_remember=False, version='1.12.1'):
'<script src="%s"></script>' % js]))

def picker(self, id='.datepicker', dateFormat='yy-mm-dd',
maxDate='', minDate='', btnsId='.btnId',changeMonth=False,changeYear=False):
maxDate='', minDate='', btnsId='.btnId', changeMonth=False, changeYear=False):
'''Assign a datepicker to a specific HTML element.

Parameters
Expand All @@ -137,17 +139,10 @@ def picker(self, id='.datepicker', dateFormat='yy-mm-dd',
str
Safe HTML content to initiate and assign a new datepicker.
'''
if changeMonth:
month="true"
else:
month="false"

if changeYear:
year="true"
else:
year="false"

month = "true" if changeMonth else "false"
year = "true" if changeYear else "false"
date_limits = []

for d in [maxDate, minDate]:
ss = d.split('-') if len(d.split('-')) == 3 else []
date_limits.append('new Date("%s","%s","%s")' % (
Expand All @@ -161,8 +156,8 @@ def picker(self, id='.datepicker', dateFormat='yy-mm-dd',
'$("%s").each(function () {' % id,
'var toF = this; $(this).datepicker({',
'dateFormat: "%s",' % dateFormat,
'changeYear: %s,'%year,
'changeMonth: %s,'%month,
'changeYear: %s,' % year,
'changeMonth: %s,' % month,
'maxDate: %s,' % date_limits[0],
'minDate: %s});' % date_limits[1],
'if (EL.length > 0) { $(EL[0]).click(',
Expand Down
3 changes: 2 additions & 1 deletion requirements/main.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Flask
Flask-Bootstrap
Flask-Bootstrap
MarkupSafe
1 change: 0 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ pytest
pytest-runner
pytest-cov
coverage
python-coveralls
flake8
31 changes: 17 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from setuptools import setup


supported_versions = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
basedir = path.abspath(path.dirname(__file__))
long_description = ''
requirements = []
test_requirements = []
requirements_path = path.join(basedir, 'requirements')


Expand All @@ -15,14 +15,21 @@
with open(path.join(basedir, 'README.md')) as f:
long_description += f.read()

with open(path.join(requirements_path, 'main.txt')) as f:
requirements += [line for line in f.read().split('\n') if line]
test_requirements += requirements
if path.isdir(requirements_path):
with open(path.join(requirements_path, 'main.txt')) as f:
requirements += [line for line in f.read().split('\n') if line]
else:
requires_path = path.join(
path.join(basedir, "Flask_Datepicker.egg-info"), "requires.txt"
)

with open(path.join(requirements_path, 'test.txt')) as f:
test_requirements += [
line for line in f.read().split('\n')
if line and not line.startswith('-r')]
with open(requires_path) as f:
requirements += [line for line in f.read().split("\n") if line]


supported_python_classifiers = [
"Programming Language :: Python :: {0}".format(v) for v in supported_versions
]


setup(
Expand All @@ -42,14 +49,10 @@
include_package_data=True,
platforms='any',
install_requires=requirements,
setup_requires=test_requirements,
setup_requires=requirements,
keywords=['flask', 'extension', 'date', 'picker', 'jquery-ui', 'datepicker'],
classifiers=[
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
*supported_python_classifiers,
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
Expand Down
23 changes: 10 additions & 13 deletions tests/integration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from pytest import fixture
import pytest

from flask_datepicker import datepicker
from .setup import app
from .setup import app, extension
from .mockers import mock_static


@fixture
@pytest.fixture
def client():
app.config['TESTING'] = True
app.config['STATIC_FOLDER'] = 'static'
Expand Down Expand Up @@ -52,18 +51,16 @@ def test_picker_min_max_dates(client):

def test_loader_local_links(client):
local_links = [mock_static('css'), mock_static('js')]
html = datepicker(app, local=local_links).loader()
extension._local = local_links
extension._get_resolved_local.__dict__.clear()
html = extension.loader()

for link in local_links:
assert link in html


def test_loader_local_links_win_false(client):
try:
datepicker(app, local=['200', '200']).loader()
except Exception as e:
assert type(e) == globals().get('FileNotFoundError', IOError)


if __name__ == '__main__':
app.run(port=8080, debug=False)
with pytest.raises(Exception) as e:
extension._local = ['200', '200']
extension.loader()
assert type(e) is globals().get('FileNotFoundError', IOError)
2 changes: 1 addition & 1 deletion tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .mockers import mock_template

app = Flask(__name__)
eng = datepicker(app, local=[])
extension = datepicker(app, local=[])


@app.route('/loader')
Expand Down
Loading