Skip to content

Commit

Permalink
Last Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zeliangyao committed Sep 1, 2021
1 parent 901cfd2 commit 4066c75
Show file tree
Hide file tree
Showing 421 changed files with 84,993 additions and 52 deletions.
3 changes: 3 additions & 0 deletions book/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def __str__(self):
def get_absolute_url(self):
return reverse('category_list')

# class Meta:
# db_table='category'

class Publisher(models.Model):

name = models.CharField(max_length=50, blank=True)
Expand Down
18 changes: 0 additions & 18 deletions book/test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@



def mydeco(f):
# This function is what we "replace" hello with
def wrapper(*args, **kw):
print(args[0])
print(args[1])
return f(*args, **kw) # Call hello

return wrapper



@mydeco
def person(name,age,address,code):
print(name,age,address,code)

person("test",12,333,444)
6 changes: 3 additions & 3 deletions book/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.conf.urls.static import static
from .views import BorrowRecordListView,BorrowRecordCreateView,BorrowRecordDeleteView,BorrowRecordDetailView,auto_member,auto_book,BorrowRecordClose
from .views import DataCenterView,download_data
from .views import ChartView,global_serach,EmployeeView,EmployeeDetailView,EmployeeUpdate,CatNoticeListView,CatNoticeUpdateView
from .views import ChartView,global_serach,EmployeeView,EmployeeDetailView,EmployeeUpdate,NoticeListView,NoticeUpdateView

urlpatterns = [

Expand Down Expand Up @@ -77,8 +77,8 @@
path('employees-update/<int:pk>',EmployeeUpdate,name='employee_update'),

# Notice
path('notice-list/', CatNoticeListView.as_view(), name='notice_list'),
path('notice-update/', CatNoticeUpdateView.as_view(), name='notice_update'),
path('notice-list/', NoticeListView.as_view(), name='notice_list'),
path('notice-update/', NoticeUpdateView.as_view(), name='notice_update'),
]


Expand Down
58 changes: 40 additions & 18 deletions book/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
from comment.forms import CommentForm
from notifications.signals import notify
from .notification import send_notification
import logging

logger = logging.getLogger(__name__)



TODAY=get_n_days_ago(0,"%Y%m%d")
Expand Down Expand Up @@ -207,14 +211,15 @@ class BookDetailView(LoginRequiredMixin,DetailView):
template_name = 'book/book_detail.html'
login_url = 'login'
comment_form = CommentForm()

# def get_object(self, queryset=None):
# obj = super(BookDetailView, self).get_object(queryset=queryset)
# return obj

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
current_book_name = self.get_object().title
logger.info(f'Book <<{current_book_name}>> retrieved from db')
comments = Comment.objects.filter(book=self.get_object().id)
related_records = BorrowRecord.objects.filter(book=current_book_name)
context['related_records'] = related_records
Expand Down Expand Up @@ -317,23 +322,19 @@ class CategoryCreateView(LoginRequiredMixin,CreateView):
model=Category
fields=['name']
template_name='book/category_create.html'
success_url = reverse_lazy('category_list')

def form_valid(self, form):
new_cat = form.save(commit=False)
new_cat.save()
send_notification(self.request.user,new_cat,verb=f'Add New Category << {new_cat.name} >>')
return super(CategoryCreateView, self).form_valid(form)


def post(self,request, *args, **kwargs):
super(CategoryCreateView,self).post(request)
new_cat_name = request.POST['name']
messages.success(request, f"Category << {new_cat_name} >> Added")
logger.info(f'{self.request.user} created Category {new_cat.name}')
UserActivity.objects.create(created_by=self.request.user.username,
target_model=self.model.__name__,
detail =f"Create {self.model.__name__} << {new_cat_name} >>")
detail =f"Create {self.model.__name__} << {new_cat.name} >>")
return super(CategoryCreateView, self).form_valid(form)


return redirect('category_list')

class CategoryDeleteView(LoginRequiredMixin,View):
login_url = 'login'
Expand All @@ -349,6 +350,9 @@ def get(self,request,*args,**kwargs):
operation_type="danger",
target_model=model_name,
detail =f"Delete {model_name} << {delete_cat.name} >>")

logger.info(f'{self.request.user} delete Category {delete_cat.name}')

return HttpResponseRedirect(reverse("category_list"))


Expand Down Expand Up @@ -397,15 +401,29 @@ class PublisherCreateView(LoginRequiredMixin,CreateView):
login_url = 'login'
form_class=PubCreateEditForm
template_name='book/publisher_create.html'
success_url = reverse_lazy('publisher_list')


def form_valid(self,form):
new_pub = form.save(commit=False)
new_pub.save()
messages.success(self.request, f"New Publisher << {new_pub.name} >> Added")
send_notification(self.request.user,new_pub,verb=f'Add New Publisher << {new_pub.name} >>')
logger.info(f'{self.request.user} created Publisher {new_pub.name}')

def post(self,request, *args, **kwargs):
super(PublisherCreateView,self).post(request)
new_publisher_name = request.POST['name']
messages.success(request, f"New Publisher << {new_publisher_name} >> Added")
UserActivity.objects.create(created_by=self.request.user.username,
target_model=self.model.__name__,
detail =f"Create {self.model.__name__} << {new_publisher_name} >>")
return redirect('publisher_list')
detail =f"Create {self.model.__name__} << {new_pub.name} >>")
return super(PublisherCreateView, self).form_valid(form)

# def post(self,request, *args, **kwargs):
# super(PublisherCreateView,self).post(request)
# new_publisher_name = request.POST['name']
# messages.success(request, f"New Publisher << {new_publisher_name} >> Added")
# UserActivity.objects.create(created_by=self.request.user.username,
# target_model=self.model.__name__,
# detail =f"Create {self.model.__name__} << {new_publisher_name} >>")
# return redirect('publisher_list')

class PublisherUpdateView(LoginRequiredMixin,UpdateView):
model=Publisher
Expand Down Expand Up @@ -437,6 +455,8 @@ def get(self,request,*args,**kwargs):
model_name = delete_pub.__class__.__name__
messages.error(request, f"Publisher << {delete_pub.name} >> Removed")
delete_pub.delete()
send_notification(self.request.user,delete_pub,verb=f'Delete Publisher << {delete_pub.name} >>')
logger.info(f'{self.request.user} delete Publisher {delete_pub.name}')
UserActivity.objects.create(created_by=self.request.user.username,
operation_type="danger",
target_model=model_name,
Expand Down Expand Up @@ -810,6 +830,8 @@ def get(self, request, *args, **kwargs):
close_record.delay_days = close_record.get_delay_number_days
close_record.open_or_close = 1
close_record.save()
print(close_record.open_or_close,close_record.final_status,close_record.pk)


borrowed_book = Book.objects.get(title=close_record.book)
borrowed_book.quantity+=1
Expand Down Expand Up @@ -930,7 +952,7 @@ def EmployeeUpdate(request,pk):

# Notice

class CatNoticeListView(SuperUserRequiredMixin, ListView):
class NoticeListView(SuperUserRequiredMixin, ListView):
context_object_name = 'notices'
template_name = 'notice_list.html'
login_url = 'login'
Expand All @@ -940,7 +962,7 @@ def get_queryset(self):
return self.request.user.notifications.unread()


class CatNoticeUpdateView(SuperUserRequiredMixin,View):
class NoticeUpdateView(SuperUserRequiredMixin,View):
"""Update Status of Notification"""
# 处理 get 请求
def get(self, request):
Expand Down
83 changes: 72 additions & 11 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
'ckeditor',
'comment',
'notifications',
# 'elasticsearch-dsl',
# 'django_elasticsearch_dsl',
# 'django-elasticsearch-dsl-drf',
]

CRISPY_ALLOWED_TEMPLATE_PACKS = "tailwind"
Expand All @@ -51,7 +54,9 @@
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.cache.UpdateCacheMiddleware', # Redis
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware', # Redis
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
Expand Down Expand Up @@ -99,8 +104,8 @@
}

ROOT_URLCONF = 'core.urls'
LOGIN_REDIRECT_URL = "home" # Route defined in app/urls.py
LOGOUT_REDIRECT_URL = "home" # Route defined in app/urls.py
LOGIN_REDIRECT_URL = "home"
LOGOUT_REDIRECT_URL = "home"
TEMPLATE_DIR = os.path.join(BASE_DIR, "templates") # ROOT dir for templates

TEMPLATES = [
Expand All @@ -124,8 +129,6 @@

WSGI_APPLICATION = 'core.wsgi.application'

# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': {
Expand All @@ -152,9 +155,12 @@
},
]

ELASTICSEARCH_DSL={
'default': {
'hosts': 'localhost:9200'
},
}

# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

Expand All @@ -167,11 +173,52 @@

USE_TZ = True

#############################################################
# SRC: https://devcenter.heroku.com/articles/django-assets

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
LOGGING_DIR = os.path.join(BASE_DIR, 'logging')

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(asctime)s %(name)-12s %(lineno)d %(levelname)-8s %(message)s',
},
},
'handlers': {
"console": {
'class': "logging.StreamHandler",
'formatter': 'simple',
},
'mail_admins': {
'level': "ERROR",
'class': 'django.utils.log.AdminEmailHandler',
},
'file': {
'level': 'INFO',
'class': "logging.FileHandler",
'formatter': 'simple',
'filename': os.path.join(LOGGING_DIR, 'book.admin.log'),
},
'performance': {
'level': 'INFO',
'class': 'logging.FileHandler',
'formatter': 'simple',
'filename': os.path.join(LOGGING_DIR, 'book.performance.log'),
},
},

'root': {
'handlers': ['console', 'file'],
'level': 'INFO',
},
'loggers': {
"interview.performance": {
"handlers": ["console", "performance"],
"level": "INFO",
"propagate": False,
},
},
}

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
Expand All @@ -184,4 +231,18 @@


DATA_URL = '/data/'
DATA_ROOT = os.path.join(BASE_DIR, 'data')
DATA_ROOT = os.path.join(BASE_DIR, 'data')


CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
# "PASSWORD": "mysecret"
"SOCKET_CONNECT_TIMEOUT": 5,
"SOCKET_TIMEOUT": 5,
}
}
}
12 changes: 12 additions & 0 deletions datacenter/Book_20210901.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
id,author,title,description,created_at,updated_at,total_borrow_times,quantity,category_id,publisher_id,status,floor_number,bookshelf_number,updated_by
1,B1,T1,"is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,",2021-07-31 18:22:29.835365+00:00,2021-08-11 21:20:01.168843+00:00,3,18,2,2,0,1,A004,yaozeliang
2,B2,T2,"is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,",2021-07-31 18:22:50.489077+00:00,2021-08-02 18:23:17.334439+00:00,0,28,3,1,0,3,C099,yaozeliang
3,B3,T3,"is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,",2021-07-31 18:23:14.800909+00:00,2021-08-15 17:07:22.109490+00:00,3,43,6,4,0,2,B012,yaozeliang
4,Jk.Rowling,MarkdownTestA,ADDADFADFASFS,2021-07-31 18:23:39.506959+00:00,2021-08-30 12:17:28.942049+00:00,9,17,11,3,0,1,C001,yaozeliang
5,Marie-Christine Helg,Your Titleo,adfadfas,2021-07-31 20:05:51.202141+00:00,2021-08-13 13:12:35.303482+00:00,3,7,8,2,0,2,C001,yaozeliang
6,Jk.Rowling,Harry Potter Children's Collection,adfaadfs,2021-08-02 17:50:43.193274+00:00,2021-08-29 14:39:26.937477+00:00,14,16,5,2,0,3,C071,admin_1
7,Test Book,Test Title,adsfadsfasdfasadsfadsfasdf,2021-08-02 18:09:29.120527+00:00,2021-08-13 13:37:31.065470+00:00,1,400,2,3,0,3,B028,yaozeliang
8,A.D. Martel,Amazing Test Book,Here's the amazing book,2021-08-03 18:54:38.342004+00:00,2021-08-16 12:48:11.143559+00:00,8,90,9,2,0,1,C076,yaozeliang
9,Best Author,Best Book,this is the description,2021-08-03 20:17:09.402964+00:00,2021-08-07 19:16:50.157458+00:00,6,94,7,3,0,1,C012,yaozeliang
10,Jk.Rowling,Harry Potter and magic stone,adffaaaaaaaaaa,2021-08-07 17:29:19.723300+00:00,2021-08-12 18:48:33.901959+00:00,6,192,5,3,0,2,C004,yaozeliang
11,Zeliang,My favourite,ADFADFADSFASDF,2021-08-20 08:38:55.975973+00:00,2021-08-30 12:05:14.639577+00:00,2,22,4,4,0,2,C091,yaozeliang
13 changes: 13 additions & 0 deletions datacenter/Category_20210901.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id,name,created_at
2,Economics,2021-07-31 18:19:30.473140+00:00
3,Finance,2021-07-31 18:19:43.229982+00:00
4,Historical,2021-07-31 18:19:49.221871+00:00
5,Fantasy,2021-07-31 18:19:56.916918+00:00
6,Cooking,2021-07-31 18:20:02.315268+00:00
7,Computers & Tech,2021-07-31 18:20:10.279309+00:00
8,Fiction,2021-07-31 18:20:17.988670+00:00
9,Watch,2021-07-31 18:20:31.205351+00:00
10,Detective and Mystery,2021-07-31 18:20:36.975123+00:00
11,Literary Fiction,2021-07-31 18:20:41.851775+00:00
12,Comic,2021-07-31 18:20:54.997368+00:00
20,Fashion,2021-08-09 17:29:13.408340+00:00
7 changes: 7 additions & 0 deletions datacenter/Publisher_20210901.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id,name,city,contact,created_at,updated_by,updated_at
1,Pub1,Paris,[email protected],2021-07-31 18:21:19.128665+00:00,yaozeliang,2021-07-31 18:21:19.129664+00:00
2,Pub2,Beijing,[email protected],2021-07-31 18:21:27.033171+00:00,yaozeliang,2021-07-31 18:21:27.034167+00:00
3,Pub3,Rome,[email protected],2021-07-31 18:21:36.376148+00:00,yaozeliang,2021-07-31 18:21:36.376148+00:00
4,Pub4,Tokyo,[email protected],2021-07-31 18:21:53.540765+00:00,yaozeliang,2021-08-01 15:14:28.407599+00:00
5,Fake Pub 5,Paris,[email protected],2021-08-05 10:03:22.230909+00:00,yaozeliang,2021-08-16 17:06:11.552131+00:00
11,Fake Pub 99,Paris,[email protected],2021-08-29 20:57:26.189029+00:00,yaozeliang,2021-08-29 20:57:26.200985+00:00
Loading

0 comments on commit 4066c75

Please sign in to comment.