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

A few commits... #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ htmlcov
.idea
.tox
node_modules
.vscode
.vscode
56 changes: 56 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "^package.json|^package-lock.json"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
# syntax
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-xml
- id: pretty-format-json
# git & filesystem
- id: check-added-large-files
- id: check-symlinks
- id: detect-private-key
- id: check-merge-conflict
- id: check-case-conflict # file conflicts: a.txt vs. A.txt
# formatters
- id: mixed-line-ending
- id: trailing-whitespace
exclude: "(.*\\.html|.*\\.md)$"
- id: end-of-file-fixer
exclude: "(.*\\.xml|.*\\.svg)$"
# python
- id: check-ast # abstract syntax tree
- id: check-builtin-literals # no {} and [], but dict() and list()
- id: debug-statements
- id: name-tests-test
args: [--pytest-test-first]
exclude: "(\/tests\/(settings|utils\/django_utils|urls).py)$"
# django-upgrade suggestions
- repo: https://github.com/adamchainz/django-upgrade
rev: "1.14.0"
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
# tha black
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.7.0"
hooks:
- id: black
# flake8 replacement (&more)
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.284"
hooks:
- id: ruff
args: [--fix]
# js/sass/etc formatter
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.2
hooks:
- id: prettier
args: [--list-different]
exclude: "(.*\\.html|.*\\.md)$"
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# django-socials Changelog

## May 2024

- added pre-commit
- Django 4.2 compat
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

pre alpha

If you use django < 3.1, you must generate migrations on your own, ie with settings.MIGRATION_MODULES.
If you use django < 3.1, you must generate migrations on your own, ie with settings.MIGRATION_MODULES.
3 changes: 1 addition & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'socials.tests.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "socials.tests.settings")

from django.core.management import execute_from_command_line

Expand Down
85 changes: 85 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[tool.ruff]
# Enable the pycodestyle (`E`) and Pyflakes (`F`) rules by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
# B = Bugbear
# DJ = django
# T20 = print
select = [
# pyflakes, pycodestyle
"F", "E", "W",
# mmcabe
"C90",
# isort
"I",
# pep8-naming
# "N",
# pyupgrade
# "UP",
# flake8-2020
"YTT",
# flake8-boolean-trap
# "FBT",
# flake8-bugbear
# "B",
# flake8-comprehensions
"C4",
# flake8-django
"DJ",
# flake8-pie
# "PIE",
# flake8-simplify
# "SIM",
# flake8-gettext
"INT",
# pygrep-hooks
# "PGH",
# pylint
# "PL",
# unused noqa
"RUF100",
# flake8-print
"T20",
]
ignore = []
# Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
# "migrations",
]
per-file-ignores = {}

# Same as Black.
line-length = 88

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.9
target-version = "py311"

[tool.ruff.mccabe]
max-complexity = 15
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
django >= 2.2
requests
requests
2 changes: 2 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pre-commit
black
36 changes: 18 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
from setuptools import setup, find_packages

from setuptools import find_packages, setup

# not so bad: http://joebergantine.com/blog/2015/jul/17/releasing-package-pypi/
version = __import__('socials').__version__
version = __import__("socials").__version__


def read(fname):
Expand All @@ -14,28 +14,28 @@ def read(fname):
setup(
name="django-socials",
version=version,
url='https://github.com/rouxcode/django-socials',
license='MIT',
platforms=['OS Independent'],
url="https://github.com/rouxcode/django-socials",
license="MIT",
platforms=["OS Independent"],
description="fetch posts from various social media",
long_description='none yet',
author=u'Alaric Mägerle, Ben Stähli',
author_email='[email protected]',
long_description="none yet",
author="Alaric Mägerle, Ben Stähli",
author_email="[email protected]",
packages=find_packages(),
install_requires=(
'django>=1.11',
'requests',
'Pillow',
"django>=1.11",
"requests",
"Pillow",
),
include_package_data=True,
zip_safe=False,
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Internet :: WWW/HTTP',
"Development Status :: 4 - Beta",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Internet :: WWW/HTTP",
],
)
3 changes: 1 addition & 2 deletions socials/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__version__ = '0.0.1'
default_app_config = 'socials.apps.SocialsConfig'
__version__ = "0.0.1"
3 changes: 1 addition & 2 deletions socials/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.contrib import admin

from ..models import Post
from .instagram_configuration import InstagramConfiguration, InstagramConfigurationAdmin
from .post import PostAdmin
from ..models import Post


admin.site.register(InstagramConfiguration, InstagramConfigurationAdmin)
admin.site.register(Post, PostAdmin)
16 changes: 6 additions & 10 deletions socials/admin/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@


class ConfigurationAdminForm(forms.ModelForm):

class Meta:
fields = '__all__'
fields = "__all__" # noqa
model = Configuration
labels = {}
widgets = {
'url': forms.TextInput
}
widgets = {"url": forms.TextInput}


class ConfigurationAdmin(admin.ModelAdmin):

form = ConfigurationAdminForm
list_display = [
'name',
"name",
]
readonly_fields = [
'date_added',
'date_changed',
'date_changed',
"date_added",
"date_changed",
"date_changed",
]
42 changes: 19 additions & 23 deletions socials/admin/instagram_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,55 @@


class InstagramConfigurationAdminForm(forms.ModelForm):

new_token = forms.CharField(
required=False,
help_text='get it from instagram, must be entered only once.',
help_text="get it from instagram, must be entered only once.",
)

def __init__(self, *args, **kwargs):
super_result = super().__init__(*args, **kwargs)
show_new = False
if kwargs.get('initial', None):
if kwargs.get("initial", None):
# creation. need a token!
show_new = True
elif not self.instance.token_ok:
# whatever reaseon...a long lived token is again needed.
show_new = True
if not show_new:
self.fields['new_token'].widget = self.fields['new_token'].hidden_widget()
self.fields["new_token"].widget = self.fields["new_token"].hidden_widget()
return super_result

def save(self, *args, **kwargs):
if not self.errors:
if not self.instance.token_ok and self.cleaned_data.get('new_token', None):
self.instance.token = self.cleaned_data.get('new_token', None)
if not self.instance.token_ok and self.cleaned_data.get("new_token", None):
self.instance.token = self.cleaned_data.get("new_token", None)
# assume it works!
self.instance.token_refresh_date = timezone.now()
self.instance.token_ok = True
return super().save(*args, **kwargs)

class Meta:
fields = '__all__'
fields = "__all__" # noqa
model = InstagramConfiguration
labels = {}
widgets = {
'url': forms.TextInput
}
widgets = {"url": forms.TextInput}


class InstagramConfigurationAdmin(admin.ModelAdmin):

form = InstagramConfigurationAdminForm
list_display = [
'name',
'active',
'posts_refresh_date',
'token_ok',
'token_refresh_date',
"name",
"active",
"posts_refresh_date",
"token_ok",
"token_refresh_date",
]
list_filters = ('active', )
list_filters = ("active",)
readonly_fields = [
'date_added',
'date_changed',
'token',
'token_ok',
'token_refresh_date',
'posts_refresh_date',
"date_added",
"date_changed",
"token",
# 'token_ok',
"token_refresh_date",
"posts_refresh_date",
]
Loading