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
from django.contrib.auth.models import ( | |
BaseUserManager, AbstractBaseUser | |
) | |
from django.db import models | |
class MyUserManager(BaseUserManager): | |
use_in_migrations = True | |
def create_user(self, username, email=None, password=None): | |
if not username: |
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
from django.shortcuts import render, get_object_or_404, redirect | |
from .models import Post | |
def all_post(request): | |
return render(request, 'index.html', { | |
'posts': Post.objects.all()[:3] | |
}) | |
def post_detail(request, pk): | |
return render(request, 'detail.html', { |
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
from django.urls import path | |
from . import views | |
urlpatterns = [ | |
path('', views.all_post, name='posts'), | |
path('', views.post_detail, name='post_detail'), | |
] |
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
from django.db import models | |
class Post(models.Model): | |
title = models.CharField(max_length=200) | |
content = models.TextField(max_length=200, unique=True) | |
def __str__(self): | |
return self.title |
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
import sys | |
import os | |
import time | |
import logging | |
from watchdog.observers import Observer | |
from watchdog.events import LoggingEventHandler, FileCreatedEvent | |
source_path = os.path.dirname(os.path.abspath(__file__)) | |
# test_files_dir = os.path.join(source_path, "test_files") |
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
[Unit] | |
Description=Simple Service to monitor Directory state. | |
[Service] | |
Type=simple | |
ExecStart=/bin/bash /usr/bin/run_python.sh | |
[Install] | |
WantedBy=multi-user.target |
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
import os | |
import sys | |
source_path = os.path.dirname(os.path.abspath(__file__)) | |
# test_files_dir = os.path.join(source_path, "test_files") | |
if __name__ == '__main__': | |
files = os.listdir(source_path) | |
for file in files: |
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
def directory_checker(self): | |
# Checking if the directory exists | |
if os.path.exists(template_dir): | |
return template_dir | |
else: | |
os.makedirs(template_dir) | |
if os.path.exists(template_dir): | |
return template_dir |
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
def directory_checker(): | |
# Checking if the directory exists | |
if os.path.exists(template_dir): | |
return template_dir | |
else: | |
os.makedirs(template_dir) | |
directory_checker() |
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
def add_arguments(self, parser): | |
parser.add_argument('template_name', type=str, help="Indicates the template name(e.g home.html)") | |
# Optional app directory | |
parser.add_argument('-a', '--app', type=str, help="Defines a parent dir with the name of the app") |