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

Expiry Feature #62

Merged
merged 8 commits into from
Aug 1, 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
4 changes: 2 additions & 2 deletions django_psdb_engine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


class DatabaseWrapper(MysqlDatabaseWrapper):
vendor = 'planetscale'
features_class = DatabaseFeatures
vendor = "planetscale"
features_class = DatabaseFeatures
7 changes: 5 additions & 2 deletions django_psdb_engine/features.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.db.backends.mysql.features import DatabaseFeatures as MysqlBaseDatabaseFeatures
from django.db.backends.mysql.features import (
DatabaseFeatures as MysqlBaseDatabaseFeatures,
)


class DatabaseFeatures(MysqlBaseDatabaseFeatures):
supports_foreign_keys = False
supports_foreign_keys = False
4 changes: 2 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pasteme.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pasteme.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion pasteme/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pasteme.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pasteme.settings")

application = get_asgi_application()
91 changes: 45 additions & 46 deletions pasteme/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,70 +22,68 @@
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')
SECRET_KEY = config("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# 3rd parties
'rest_framework',
'drf_yasg',

"rest_framework",
"drf_yasg",
# apps
'snippet',
'blog',
'pypi',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'pasteme.urls'
ROOT_URLCONF = "pasteme.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [str(BASE_DIR.joinpath('templates'))],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [str(BASE_DIR.joinpath("templates"))],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = 'pasteme.wsgi.application'
WSGI_APPLICATION = "pasteme.wsgi.application"

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}

Expand All @@ -94,26 +92,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -123,21 +121,22 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = 'static/'
STATIC_URL = "/static/"
STATIC_ROOT = "static/"

MEDIA_URL = '/media/'
MEDIA_ROOT = 'media/'
MEDIA_URL = "/media/"
MEDIA_ROOT = "media/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

DOMAIN_URL = 'https://pasteme.pythonanywhere.com/'
DOMAIN_URL = "https://pasteme.pythonanywhere.com/"

# Import local settings

try:
from .local_settings import *
except ImportError: pass
except ImportError:
pass
20 changes: 10 additions & 10 deletions pasteme/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
from rest_framework import permissions

schema_view = get_schema_view(
openapi.Info(
title="PasteMe API Documentation",
default_version='v1',
description="API endpoints for PasteMe RESTful service.",
contact=openapi.Contact(email="lnxpylnxpy@gmail.com"),
license=openapi.License(name="MIT License"),
),
public=True,
permission_classes=[permissions.AllowAny],
authentication_classes=None,
openapi.Info(
title="PasteMe API Documentation",
default_version="v1",
description="API endpoints for PasteMe RESTful service.",
contact=openapi.Contact(email="lnxpylnxpy@gmail.com"),
license=openapi.License(name="MIT License"),
),
public=True,
permission_classes=[permissions.AllowAny],
authentication_classes=None,
)

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion pasteme/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pasteme.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pasteme.settings")

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion pypi/admin.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from django.contrib import admin
from django.contrib import admin
4 changes: 2 additions & 2 deletions pypi/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class PypiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'pypi'
default_auto_field = "django.db.models.BigAutoField"
name = "pypi"
36 changes: 24 additions & 12 deletions pypi/management/commands/collectstatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,35 @@


class Command(BaseCommand):
help = 'Collects stats of pasteme-cli package using pypistats SDK'
help = "Collects stats of pasteme-cli package using pypistats SDK"

def handle(self, *args, **options):
pasteme_totlal_stars = int(requests.get('https://api.github.com/repos/collove/pasteme').json()['stargazers_count'])
pastemecli_totlal_stars = int(requests.get('https://api.github.com/repos/collove/pasteme-cli').json()['stargazers_count'])
daily_payload = json.loads(pypistats.recent("pasteme-cli", format="json"))['data']
overall_downloads = json.loads(pypistats.overall('pasteme-cli', format='json'))['data'][0]['downloads']

pasteme_totlal_stars = int(
requests.get("https://api.github.com/repos/collove/pasteme").json()[
"stargazers_count"
]
)
pastemecli_totlal_stars = int(
requests.get("https://api.github.com/repos/collove/pasteme-cli").json()[
"stargazers_count"
]
)
daily_payload = json.loads(pypistats.recent("pasteme-cli", format="json"))[
"data"
]
overall_downloads = json.loads(pypistats.overall("pasteme-cli", format="json"))[
"data"
][0]["downloads"]

obj = Statistic(
last_day_downloads=daily_payload['last_day'],
last_week_downloads=daily_payload['last_week'],
last_month_downloads=daily_payload['last_month'],
last_day_downloads=daily_payload["last_day"],
last_week_downloads=daily_payload["last_week"],
last_month_downloads=daily_payload["last_month"],
total_downloads=overall_downloads,
total_service_stars=pasteme_totlal_stars,
total_package_stars=pastemecli_totlal_stars,
)

obj.save()
self.stdout.write(f'Statistics {obj} object created!')

self.stdout.write(f"Statistics {obj} object created!")
29 changes: 18 additions & 11 deletions pypi/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,28 @@ class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='Statistic',
name="Statistic",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('last_day_downloads', models.PositiveIntegerField()),
('last_week_downloads', models.PositiveIntegerField()),
('last_month_downloads', models.PositiveIntegerField()),
('total_downloads', models.PositiveIntegerField()),
('total_service_stars', models.PositiveIntegerField()),
('total_package_stars', models.PositiveIntegerField()),
('date', models.DateTimeField(auto_now=True)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("last_day_downloads", models.PositiveIntegerField()),
("last_week_downloads", models.PositiveIntegerField()),
("last_month_downloads", models.PositiveIntegerField()),
("total_downloads", models.PositiveIntegerField()),
("total_service_stars", models.PositiveIntegerField()),
("total_package_stars", models.PositiveIntegerField()),
("date", models.DateTimeField(auto_now=True)),
],
),
]
5 changes: 3 additions & 2 deletions pypi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class Statistic(models.Model):
total_service_stars = models.PositiveIntegerField()
total_package_stars = models.PositiveIntegerField()
date = models.DateTimeField(auto_now=True)

def __str__(self): return f'{self.id} at {self.date}'

def __str__(self):
return f"{self.id} at {self.date}"
4 changes: 2 additions & 2 deletions snippet/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class SnippetConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'snippet'
default_auto_field = "django.db.models.BigAutoField"
name = "snippet"
Loading