Skip to content

Instantly share code, notes, and snippets.

View godfather68's full-sized avatar

Farel Ellely godfather68

View GitHub Profile
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:
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', {
from django.urls import path
from . import views
urlpatterns = [
path('', views.all_post, name='posts'),
path('', views.post_detail, name='post_detail'),
]
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
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")
[Unit]
Description=Simple Service to monitor Directory state.
[Service]
Type=simple
ExecStart=/bin/bash /usr/bin/run_python.sh
[Install]
WantedBy=multi-user.target
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:
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
def directory_checker():
# Checking if the directory exists
if os.path.exists(template_dir):
return template_dir
else:
os.makedirs(template_dir)
directory_checker()
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")