-
Notifications
You must be signed in to change notification settings - Fork 0
Add core app #1
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
Open
ahmed-arb
wants to merge
25
commits into
main
Choose a base branch
from
add-core-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add core app #1
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ac3da43
feat: add models
ahmed-arb dabc6b2
Feat: add books api
ahmed-arb 008a898
Feat: add auth backend
ahmed-arb 1063a30
feat!: change BookViewSet permission method
ahmed-arb 044e041
feat: add book loan view
ahmed-arb 8d6fc0a
feat: update book stock
ahmed-arb bc6f012
feat: validate book loan request
ahmed-arb 2ace28d
feat: add import csv data command
ahmed-arb a008a62
cron job setup
ahmed-arb 8754897
feat: send reminder emails
ahmed-arb 98ec492
feat: add book request api
ahmed-arb 23821e5
feat: BookRequest signal
ahmed-arb 0a5e9fb
add formatting and docstrings
ahmed-arb 8415527
add docstrings
ahmed-arb 1c38dcb
Update select_related in core/cron.py
ahmed-arb 2e507ea
model changes
ahmed-arb 1e406c9
Merge branch 'add-core-app' of https://github.com/ahmed-arb/LMS-API i…
ahmed-arb 849c89f
change book filter query in core/serializers.py
ahmed-arb eeda78f
Update requirements.txt
ahmed-arb 33a2e89
Merge branch 'add-core-app' of https://github.com/ahmed-arb/LMS-API i…
ahmed-arb 2339d19
add logging
ahmed-arb 5d4c4b2
Feat!: remove librarian model
ahmed-arb 18ade71
add read serializers for book loans and request
ahmed-arb 24b07ad
add data migration
ahmed-arb af2c9a0
change enumeration types in models.py
ahmed-arb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "python.linting.pylintEnabled": true, | ||
| "python.linting.pylintArgs": [ | ||
| "--load-plugins=pylint_django", | ||
| "--max-line-length=120", | ||
| "--disable=django-not-configured", | ||
| "--django-settings-module=lms.settings" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """core admin panel""" | ||
|
|
||
| from django.contrib import admin | ||
| from django.contrib.auth.admin import UserAdmin as BaseUserAdmin | ||
|
|
||
| from core.models import User | ||
|
|
||
|
|
||
| @admin.register(User) | ||
| class UserAdmin(BaseUserAdmin): | ||
| """Over ride user view in admin panel""" | ||
|
|
||
| add_fieldsets = ( | ||
| ( | ||
| None, | ||
| { | ||
| "classes": ("wide",), | ||
| "fields": ("username", "email", "password1", "password2"), | ||
| }, | ||
| ), | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Core config of LMS""" | ||
|
|
||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class CoreConfig(AppConfig): | ||
| """This class defines core app configs""" | ||
|
|
||
| default_auto_field = "django.db.models.BigAutoField" | ||
| name = "core" | ||
|
|
||
| def ready(self) -> None: | ||
| """Sets up imports and pre-requisites for this app""" | ||
| import core.signals |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """ This module has all core app corn jobs""" | ||
|
|
||
| from datetime import datetime | ||
| import logging | ||
|
|
||
| from templated_mail.mail import BaseEmailMessage | ||
ahmed-arb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| from core.models import BookLoan | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def email_overdue_books(): | ||
| """cron job for emailing user which have a book overdue""" | ||
| today = datetime.now() | ||
| loan_queryset = BookLoan.objects.select_related('book', 'user').filter(date_due__lt=today) | ||
|
|
||
| for loan in loan_queryset: | ||
| message = BaseEmailMessage( | ||
| template_name="emails/overdue_books.html", | ||
| context={ | ||
| "name": loan.user, | ||
| "book": loan.book, | ||
| }, | ||
| ) | ||
| message.send([loan.user.email]) | ||
| logger.info("email sent to %s for %s due: %s", loan.user.email, loan.book, loan.date_due) | ||
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import csv | ||
| from typing import Any, Optional | ||
|
|
||
| from django.core.management.base import BaseCommand, CommandParser | ||
|
|
||
| from core.serializers import BookSerializer | ||
| from core.models import Book | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = "Import books form csv" | ||
|
|
||
| def add_arguments(self, parser: CommandParser) -> None: | ||
| parser.add_argument("file_path", nargs=1, type=str) | ||
|
|
||
| def handle(self, *args: Any, **options: Any) -> Optional[str]: | ||
| self.file_path = options['file_path'][0] | ||
| self.prepare() | ||
| self.main() | ||
| self.finalize() | ||
|
|
||
| def prepare(self): | ||
| self.imported_counter = 0 | ||
| self.skipped_counter = 0 | ||
|
|
||
| def main(self): | ||
| self.stdout.write("=== Importing Books ===\n\n") | ||
|
|
||
| with open(self.file_path, 'r') as f: | ||
| reader = csv.DictReader(f) | ||
|
|
||
| for index, row in enumerate(reader): | ||
| serializer = BookSerializer(data=row) | ||
ahmed-arb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if serializer.is_valid(): | ||
| self.imported_counter += 1 | ||
| serializer.save() | ||
| self.stdout.write(f'{index} {row["name"]} SAVED') | ||
| else: | ||
| self.skipped_counter += 1 | ||
| self.stdout.write(f'{index} {row["name"]} SKIPPED {serializer.errors}') | ||
|
|
||
| def finalize(self): | ||
| self.stdout.write("----------------------") | ||
| self.stdout.write(f"Books imported: {self.imported_counter}") | ||
| self.stdout.write(f"Books skipped: {self.skipped_counter}") | ||
|
Comment on lines
+43
to
+45
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can use |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.