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

Feature/fix readme rst #52

Merged
merged 3 commits into from
Feb 9, 2022
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
78 changes: 78 additions & 0 deletions .github/workflows/history.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Create HISTORY.md

on:
pull_request:
branches:
- master
types: [closed]

jobs:
history:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
env:
TOKEN: ${{ secrets.JP_BIRTHDAY_TOKEN }}
ACTOR: ${{ github.actor }}
REPOSITORY: $(echo ${{ github.repository }} | sed -e "s#.*/##")
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: fregante/setup-git-user@v1

- name: Set up Ruby 3.0
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.0

- name: update CHANGELOG
run: |
gem install github_changelog_generator
echo ${{ env.TOKEN }}
echo ${{ env.REPOSITORY }}
echo ${{ env.ACTOR }}

rm HISTORY.md
github_changelog_generator -u ${{ env.ACTOR }} \
-p ${{ env.REPOSITORY }} \
--header-label '# HISTORY' \
-t ${{ env.TOKEN }} \
--release-branch master \
--output HISTORY.md

- name: convert md to rst HISTORY.
run: |
sudo apt install pandoc

pandoc -f markdown -t rst -o README.rst README.md
pandoc -f markdown -t rst -o HISTORY.rst HISTORY.md

# rm HISTORY.md

- name: update master
run: |
ls -la

git config user.email
git config user.name

git add ./
git branch
git status
git commit -m "docs: update HISTORY [$(date --iso-8601=seconds)]"
git push

- name: update develop
run: |
ls -la

git fetch origin
git pull

git checkout develop
git branch
git status

git merge master
git push
78 changes: 1 addition & 77 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,86 +32,10 @@ jobs:
draft: false
prerelease: false

changelog:
runs-on: ubuntu-latest
needs: release
env:
TOKEN: ${{ secrets.JP_BIRTHDAY_TOKEN }}
ACTOR: ${{ github.actor }}
REPOSITORY: $(echo ${{ github.repository }} | sed -e "s#.*/##")
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: fregante/setup-git-user@v1

- name: Set up Ruby 3.0
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.0

- name: update CHANGELOG
run: |
gem install github_changelog_generator
echo ${{ env.TOKEN }}
echo ${{ env.REPOSITORY }}
echo ${{ env.ACTOR }}

rm HISTORY.md
github_changelog_generator -u ${{ env.ACTOR }} \
-p ${{ env.REPOSITORY }} \
--header-label '# HISTORY' \
-t ${{ env.TOKEN }} \
--output HISTORY.md

- name: convert md to rst HISTORY.
run: |
sudo apt install pandoc

pandoc -f markdown -t rst -o README.rst README.md
pandoc -f markdown -t rst -o HISTORY.rst HISTORY.md

# rm HISTORY.md

- name: update master
run: |
ls -la

git config user.email
git config user.name

git add ./
git status
git commit -m "docs: update HISTORY [$(date --iso-8601=seconds)]"
git push

git fetch origin
git pull

git checkout master
git branch

git merge release
git push

- name: update develop
run: |
ls -la

git fetch origin
git pull

git checkout develop
git branch

git merge master
git push

publish:
# if: github.repository == 'jazzband/django-model-utils'
runs-on: ubuntu-latest
needs: changelog
needs: release
env:
TWINE_USERNAME: "__token__"
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
branches:
- master
- develop
- feature/*
paths:
- 'jp_birthday/*'
- 'tests/*'
Expand Down
49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ Authored by [shimakaze_soft](https://github.com/shimakaze-git) and some great

# Features

- Get all user profiles within the next 30 days
- Get all user profiles which have their birthday today
- order the user profiles according to their birthday
- Converting Birthdays to Japanese Style
- Get all birthdays in the specified Japanese calendar
- Calculate age based on birthday

-----

- Converting Birthdays to Japanese Style
- Calculate age based on birthday
- Get all birthdays in the specified Japanese calendar
- Get all user profiles within the next 30 days
- Get all user profiles which have their birthday today
- order the user profiles according to their birthday

# Installation

Expand Down Expand Up @@ -59,6 +59,43 @@ class ModelsTest(BirthdayModel):
ordering = ('pk',)
```

## Converting Birthdays to Japanese Style

```Python
# id: 1
# ["2001-01-01"]

m = ModelTest.objects.filter(id=1).first()
birthday = m.get_wareki_birthday()
# h-13-1-1

birthday = m.get_wareki_birthday(True)
# {'era': 'heisei', 'era_short': 'h', 'era_kanji': '平成', 'year': 13, 'month': 1, 'day': 1}
```

## Get all birthdays in the specified Japanese calendar

```Python
# ["2001-01-01", "2000-01-02", "2002-12-31", "1980-03-01"]

birthdays = ModelTest.objects.get_wareki_birthdays("heisei")
# ["2001-01-01", "2000-01-02", "2002-12-31"]

birthdays = ModelTest.objects.get_wareki_birthdays("へいせい")
# ["2001-01-01", "2000-01-02", "2002-12-31"]
```

## Calculate age based on birthday

```Python
# id: 1
# ["1995-01-05"]

m = ModelTest.objects.filter(id=1).first()
birthday = m.get_age()
# 27
```

## Get all user profiles within the next 30 days

```Python
Expand Down
24 changes: 21 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

sys.path.insert(0, os.path.abspath(".."))

from recommonmark.parser import CommonMarkParser
from recommonmark.transform import AutoStructify

import jp_birthday

# -- General configuration ---------------------------------------------
Expand All @@ -32,16 +35,31 @@

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode", "recommonmark"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"
source_suffix = {
".rst": "restructuredtext",
".txt": "restructuredtext",
".md": "markdown",
}
# source_suffix = [".rst", ".md"]
# source_suffix = ".rst"

source_parsers = {
".md": CommonMarkParser,
# '.md' : 'recommonmark.parser.CommonMarkParser'
}


def setup(app):
app.add_transform(AutoStructify)


# The master toctree document.
master_doc = "index"
Expand Down
16 changes: 8 additions & 8 deletions docs/jp_birthday.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
jp\_birthday package
====================

Subpackages
-----------

.. toctree::
:maxdepth: 4

jp_birthday.management

Submodules
----------

Expand All @@ -20,6 +12,14 @@ jp\_birthday.admin module
:undoc-members:
:show-inheritance:

jp\_birthday.eras module
------------------------

.. automodule:: jp_birthday.eras
:members:
:undoc-members:
:show-inheritance:

jp\_birthday.fields module
--------------------------

Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
sphinx-rtd-theme==1.0.0
commonmark==0.9.1
recommonmark==0.7.1
2 changes: 1 addition & 1 deletion jp_birthday/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """shimakaze-git"""
__email__ = "shimakaze.soft+github@googlemail.com"
__version__ = "0.6.0"
__version__ = "0.7.0"

__copyright__ = "Copyright (C) 2020 shimakaze-git"
__license__ = "MIT"
Expand Down
33 changes: 3 additions & 30 deletions jp_birthday/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class JpBirthdayManager(models.Manager):

@property
def _birthday_doy_field(self):
# print("self.model", self.model)
# print("self.model._meta", self.model._meta)
# print("self.model._meta.birthday_field", self.model._meta.birthday_field)
# print("doy_name", self.model._meta.birthday_field.doy_name)

return self.model._meta.birthday_field.doy_name

def _doy(self, day):
Expand Down Expand Up @@ -74,12 +69,6 @@ def _order(self, reverse=False, case=False) -> QuerySet:
def get_queryset(self):
return JpBirthdayQuerySet(self.model, using=self._db)

def cursor_filter_ids(self, cursor: backends.utils.CursorWrapper) -> list:
columns = [col[0] for col in cursor.description]
ids = [dict(zip(columns, row))["id"] for row in cursor.fetchall()]

return ids

def get_wareki_birthdays(self, wareki: str) -> QuerySet:
"""
入力された和暦の誕生日を抽出
Expand Down Expand Up @@ -110,10 +99,10 @@ def get_wareki_birthdays(self, wareki: str) -> QuerySet:
return range_birthdays
return self.filter(birthday=None)

def _get_upcoming_birthdays(
def get_upcoming_birthdays(
self, days=30, after=None, include_day=True, order=True, reverse=False
) -> JpBirthdayQuerySet:
"""[summary]
"""get_upcoming_birthdays

Args:
days (int, optional): [description]. Defaults to 30.
Expand All @@ -125,6 +114,7 @@ def _get_upcoming_birthdays(
Returns:
JpBirthdayQuerySet: [description]
"""

today = self._doy(after)
limit = today + days

Expand All @@ -150,23 +140,6 @@ def _get_upcoming_birthdays(

return self.filter(q)

def get_upcoming_birthdays(
self, days=30, after=None, include_day=True, order=True, reverse=False
) -> JpBirthdayQuerySet:
"""get_upcoming_birthdays

Args:
days (int, optional): [description]. Defaults to 30.
after ([type], optional): [description]. Defaults to None.
include_day (bool, optional): [description]. Defaults to True.
order (bool, optional): [description]. Defaults to True.
reverse (bool, optional): [description]. Defaults to False.

Returns:
JpBirthdayQuerySet: [description]
"""
return self._get_upcoming_birthdays(30, after, include_day, order, reverse)

def get_birthdays(self, day=None) -> JpBirthdayQuerySet:
"""[summary]

Expand Down
Loading