Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/Django-Schedular.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

164 changes: 129 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,143 @@
# In name of Allah
# How To Run

## Introduction
We want a simple app to schedule tasks for users. It should be possible to use django admin as interface for this application.
i made **requirements.txt** to list packages and dependencies .

There are two kind of users:
- normal users:
- admin users
you have to make a venv and install dependencies(requirements.txt).

normal users can only see, filter & add to their own tasks. These tasks will have a title, description, owner and time to send field. When user creates new task, it should be scheduled to send an email to its owner at the specified time (use celery for this purpose).

admin users have the permission to manage users, add to them and delete them. Also they can manage all tasks of users, add task for them and edit their tasks. When created or edited, scheduled tasks should be added or edited.

**note** that each user must have below fields:
- email
- username
- password
- first name
- last name
- permissions (admin & normal)
also you need to run redis in port 6379 .

You should extend AbstractUser for implementing user model.
after set celery configurations you need to run it with command :

In addition to these (all should be implemented in django admin) write an API for authentication (login & signup) and an API for getting list of tasks (according to permission of user).
```
celery -A Schular beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler

### Note
Use django rest framework and JWT for authentication.
```
u also need to run :

Also do not forget to write unit test for authentication API.
```
celery -A Schedular worker -l info
```
u also need to config email settings in django app's settings.py

## Expectations
also you need to create superuser :

So What does matter to us?
- a clean structure of codebase & components
- clean code practices
- well written unit tests
- finally, ability to learn
```
python manage.py createsuperuser
```

## Tasks
and finnaly you need to run your app :

1. Fork this repository
2. Break and specify your tasks in project management tool (append the image of your tasks to readme file of your project)
3. Learn & Develop
4. Push your code to your repository
5. Explain the roadmap of your development in readme of repository (also append the image of your specified tasks on part 2 to file)
6. Send us a pull request, we will review and get back to you
7. Enjoy
```
python manage.py runserver
```

# Development RoadMap

# users

first of all i created my custom user model using Foreign key(profile method) model and add some fields to it and used signals to connect to original user model

i made a new user panel beside django admin panel.
normal users can login to their panel and add , edit , delete their own tasks they can also filter,order or search them with paginator and export their tasks as csv file
admin user can also do that job beside that they can add,edit and delete users tasks and even they can add ,delete users with their permissions
also create login and registration form
user cant see other user's task and they cant see or even acess admin perimissions thorugh urls

```
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
first_name = models.CharField(max_length=250, blank=True)
last_name = models.CharField(max_length=250, blank=True)
PERMISSION_STATUS = (
("Normal", "normal"),
("Admin", "admin"),
)
permissions = models.CharField(max_length=8, choices=PERMISSION_STATUS, default="N")

def __str__(self):
return self.user.username

@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)

@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
```


# celery

for manage schedule tasks we have to use celery . i installed celery and cofigure it in Schedular/celery.py file.

i used redis as Broker .
i used celery beat schedular that checks tasks if current time reachs the send time it will send a email to user
you can change celery beat settings in django admin .



we have to get exact time for celery task execution. i wrote a method in send_emails function to get time difference between current time
```
current_time = datetime.now().strftime("%H:%M")
tasks = Task.objects.all()

for i in tasks:

if i.time_to_send == current_time:

send_mail(
"Django Schedular",
"Your task's time has come ",
"Your Email",
[i.owner.email],
)



```


## Api

at the end i installed DRF(Django Rest framework) to manage APIes.

i used AuthToken to secure them.

we have 5 endpoints :

- register(POST)
- get token(POST)
- LOgin(POST)
- AllTasks(GET)
- UserTasks(GET)

after login or register through api user gets their token.they can always get token form api token ,too.

i write a custom permission for all tasks api to limit access for only admin users.


i made **serializers.py** to create input or output for APIes


## Tests

finally i wrote some tests in api/tests.py** file.

i tested login and register endpoints in such senarios :

- Valid_data
- invalid_data
-register with username that already signup
-IncorrentCredentials



email : alireza.sh076@gmail.com
phone_number : 09351974608

Alireza Shirmohammadi

**Finally** don't be afraid to ask anything from us.
7 changes: 7 additions & 0 deletions Schedular/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import absolute_import, unicode_literals

# This will make sure celery is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ["celery_app"]
Binary file added Schedular/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added Schedular/__pycache__/celery.cpython-36.pyc
Binary file not shown.
Binary file added Schedular/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file added Schedular/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added Schedular/__pycache__/wsgi.cpython-36.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions Schedular/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for Schedular project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Schedular.settings")

application = get_asgi_application()
15 changes: 15 additions & 0 deletions Schedular/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import absolute_import
import os
from celery import Celery
from celery.schedules import crontab

# set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Schedular.settings")
from django.conf import settings

app = Celery("Schedular")
# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
app.config_from_object("django.conf:settings")
# Load task modules from all registered Django app configs.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
Loading