Skip to content

Commit

Permalink
Merge pull request #64 from petroly-initiative/strawberry
Browse files Browse the repository at this point in the history
Strawberry integration
  • Loading branch information
ammar-faifi authored Jul 7, 2022
2 parents 3fdc419 + cee6f7c commit 87be021
Show file tree
Hide file tree
Showing 48 changed files with 1,982 additions and 1,201 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
open-pull-requests-limit: 50
9 changes: 6 additions & 3 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ on:
pull_request:
branches: [ main ]

env:
CLOUDINARY_API_SECRET: ${{ secrets.CLOUDINARY_API_SECRET}}
EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD}}

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.9.13]
python-version: [3.10.5]

steps:
- uses: actions/checkout@v2
Expand All @@ -27,5 +31,4 @@ jobs:
pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test --settings=kfupm.settings.dev
python manage.py test --settings=kfupm.settings.dev --no-input account
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ celerybeat.pid
*.sage.py

# Environments
# .env
.env
.venv
env/
env3.10/
venv/
ENV/
env.bak/
Expand Down
44 changes: 22 additions & 22 deletions account/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from .models import Profile
from django.apps import apps
from graphql_auth.models import UserStatus
# from graphql_auth.models import UserStatus
from django.contrib.auth.admin import UserAdmin
from django.core.mail import send_mail
from django.contrib.auth.models import User
Expand Down Expand Up @@ -43,14 +43,14 @@ def send_message_email(self, request, queryset):
)
print(user.email)

@admin.action(description="Create a UserStatus object")
def create_status(self, request, queryset):
for user in queryset:
try:
obj = UserStatus.objects.get_or_create(user=user)
print(obj)
except Exception as e:
print(e)
# @admin.action(description="Create a UserStatus object")
# def create_status(self, request, queryset):
# for user in queryset:
# try:
# obj = UserStatus.objects.get_or_create(user=user)
# print(obj)
# except Exception as e:
# print(e)


@admin.register(Profile)
Expand All @@ -64,21 +64,21 @@ class ProfileAdmin(admin.ModelAdmin):
# admin.site.register(model)


@admin.register(UserStatus)
class UserStatusAdmin(admin.ModelAdmin):
# @admin.register(UserStatus)
# class UserStatusAdmin(admin.ModelAdmin):

list_display = ["user", "verified", "archived"]
list_filter = ["verified"]
actions = ["make_verified", "make_unverified", "make_archived", "make_unarchived"]
# list_display = ["user", "verified", "archived"]
# list_filter = ["verified"]
# actions = ["make_verified", "make_unverified", "make_archived", "make_unarchived"]

def make_verified(self, request, queryset):
queryset.update(verified=True)
# def make_verified(self, request, queryset):
# queryset.update(verified=True)

def make_unverified(self, request, queryset):
queryset.update(verified=False)
# def make_unverified(self, request, queryset):
# queryset.update(verified=False)

def make_archived(self, request, queryset):
queryset.update(archived=True)
# def make_archived(self, request, queryset):
# queryset.update(archived=True)

def make_unarchived(self, request, queryset):
queryset.update(archived=False)
# def make_unarchived(self, request, queryset):
# queryset.update(archived=False)
36 changes: 36 additions & 0 deletions account/middleware.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import re
import sys
from urllib.parse import urlparse
import requests

from django.conf import settings
from django.core.mail import mail_managers
from django.http import HttpResponseForbidden
from django.utils.deprecation import MiddlewareMixin


Expand Down Expand Up @@ -61,3 +63,37 @@ def is_ignorable_request(self, request, uri, domain, referer):
return True

return any(pattern.search(uri) for pattern in settings.IGNORABLE_404_URLS)


class AllowOnlyStaffMiddleware(MiddlewareMixin):
'''
This middleware used after authenticating middlewares,
to block non-staff users from some urls.
'''

def is_testing(self):
'''To ignore testing.'''

if (len(sys.argv) > 0 and 'runtests' in sys.argv[0]) \
or (len(sys.argv) > 1 and sys.argv[1] == 'test'):
# python runtests.py | python manage.py test | python
# setup.py test | django-admin.py test
return True

else:
return False

def process_response(self, request, response):
ALLOWED_PATHS = [
'/account/login/',
'/account/logout/',
'/endpoint/',
]

if request.user.is_staff:
return response

else:
if request.path in ALLOWED_PATHS:
return response
return HttpResponseForbidden('Forbidden 403')
20 changes: 20 additions & 0 deletions account/migrations/0012_alter_profile_major.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.0.5 on 2022-07-02 06:34

import data
from django.db import migrations
import django_choices_field.fields


class Migration(migrations.Migration):

dependencies = [
('account', '0011_auto_20220116_1133'),
]

operations = [
migrations.AlterField(
model_name='profile',
name='major',
field=django_choices_field.fields.TextChoicesField(blank=True, choices=[('AF', 'Accounting & Finance'), ('AE', 'Aerospace Engineering'), ('ARE', 'Architectural Engineering'), ('ARC', 'Architecture'), ('CE', 'Civil & Environmental Engg'), ('CEM', 'Construction Engg & Management'), ('CHE', 'Chemical Engineering'), ('CHEM', 'Chemistry'), ('COE', 'Computer Engineering'), ('CPG', 'CPG'), ('CRP', 'City & Regional Planning'), ('ERTH', 'Earth Sciences'), ('EE', 'Electrical Engineering'), ('ELI', 'English Language Inst. (Prep)'), ('ELD', 'English Language Department'), ('FIN', 'Finance'), ('ISOM', 'Info. Systems & Operations Mgt'), ('GS', 'Global & Social Studies'), ('IAS', 'Islamic & Arabic Studies'), ('ICS', 'Information & Computer Science'), ('LS', 'Life Sciences'), ('MATH', 'Mathematics & Statistics'), ('MBA', 'Business Administration'), ('ME', 'Mechanical Engineering'), ('MGT', 'Management & Marketing'), ('PE', 'Physical Education'), ('PETE', 'Petroleum Engineering'), ('PHYS', 'Physics'), ('PSE', 'Prep Science & Engineering'), ('SE', 'Systems Engineering')], choices_enum=data.DepartmentEnum, max_length=25, null=True),
),
]
12 changes: 5 additions & 7 deletions account/models.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from tabnanny import verbose
from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
from PIL import Image
from cloudinary.models import CloudinaryField
from cloudinary import CloudinaryImage
from data import departments, years
from data import DepartmentEnum, years
from django.dispatch import receiver
from django.db.models.signals import post_save
from django.utils.translation import gettext as _

from cloudinary.models import CloudinaryField
from django_choices_field import TextChoicesField

# Create your models here.


Expand All @@ -32,7 +30,7 @@ class Meta:
blank=True,
max_length=350,
)
major = models.CharField(blank=True, null=True, max_length=25, choices=departments)
major = TextChoicesField(blank=True, null=True, max_length=25, choices_enum=DepartmentEnum)
year = models.CharField(blank=True, null=True, max_length=25, choices=years)
language = models.CharField(_("language"), max_length=10, default='en-US')
theme = models.CharField(_("theme"), max_length=10, default='light')
Expand Down
Loading

0 comments on commit 87be021

Please sign in to comment.