Opencart 新增訂單狀態

訂單狀態加急(Urgent)

Opencart 後台設定: 【System】>>【Location】>>【Order Statuses】

  資料庫關聯示意圖

訂單狀態值

初始值:Pending

生產中的值:Processing

生產完成的值:Processed

急單的值:Urgent

訂單完成的值:Complete

切換訂單狀態

  • 程式必需新增一筆資料進oc_order_history, 並更新oc_order中的order_status_id值
狀態
Pending1
Processing2
Complete5
Processed15
Urgent17
分類: Opencart | 標籤: | 發佈留言

Opencart新增加工流程

Opencart 後台設定: 【Options】

Opencart 後台設定: 【Products】>>【Options】

分類: Opencart | 標籤: | 發佈留言

Opencart 自訂產品屬性

考題注意事項:蓋印次數

Opencart 後台設定: 【Attributes】

Opencart 後台設定: 【Products】>>【Attribute】

分類: Opencart | 標籤: | 發佈留言

http -> https, Nignx, Let’s Encrypt

Install Certbot on Ubuntu Host

  • certificate:/etc/letsencrypt/live/your_domain.com/fullchain.pem
  • privatekey:/etc/letsencrypt/live/your_domain.com/privkey.pem
分類: 未分類 | 標籤: | 發佈留言

Django Optimistic Locking (樂觀鎖定)

current in process record the version will be update += 1, so when in the same time another one do same thing will updated_rows == 0.

分類: Django | 標籤: | 發佈留言

Django Pessimistic Locking (悲觀鎖定)

when select task by id, the database lock the record. if other one to do same time the second one will get the “Task is already claimed or completed”

We use transaction.atomic() as a context manager to ensure that all database operations within the block are atomic, meaning they are either all committed or all rolled back in case of an error.

分類: Django | 標籤: | 發佈留言

Digango Views

  • Understanding Django Views
    • avoid add business logic into the view, if embedding business logic directly into the view will make it nonreusable, not testability and coupling.
  • Django’s Generic Views
    • from django.views.generic import ListView, DetailView, TemplateView
    • from django.views.generic.dates import ArchiveIndexView, YearArchiveView, MonthArchiveView, DayArchiveView, TodayArchiveView, DateDetailView
    • from django.views.generic.edit import FormView, CreateView, DeleteView, UpdateView, DeleteView
    • use help(ListView) to check detail property and method and so on
  • Mixins
    • refers to a class that provides additional functionality to other classes through inheritance.
  • Django Mixin
    • ContextMixin: Adds extra context data to the view
    • TemplateResponseMixin: Renders template and returns an HTTP response
    • FormMixin: Used to handle form submission and validation
    • CreateModelMixin: Used to save a new object to database
    • UpdateModelMixin: Used to upate an existing object in database
    • DeleteModelMixin: Used to delete an object
  • URL Configuration
    • ulrpatterns = [ re_path(r’^tasks/(?P<by_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/$’, views.query_by_date, name=”task_list”),]

^: indicating the begin

$: indicateing the last

[0-9]{4}: 4 characters and each character is 0~9.

(?P<by_date>…….), will pass the value as by_date parameter to the view.

r preceding the string is a flag, informing Python that this is a raw string

  • url path built-in convert:
    • str
    • int
    • slug
    • uuid
    • path
  • url path custom convert
  • URL Namespace and Name tasks:task-detail

to use namespace for urls, use app_name in the urls.py

  • HttpRequest object
    • request.method
    • request.user
    • request.path
    • request.GET
    • request.POST
    • request.FIELS
    • request.headers
  • HttpResponse object
    • the object accept a parameter that contains the content destined for client.
分類: Django | 標籤: | 發佈留言

Use Docker-Compose to help Django Development

cd ~

mkdir practice_folder

#create a virtualenv

python -m venv .venv

.venv\scripts\activate.bat

pip install django~=4.0.0 psycopg2-binary~=2.9.9

django-admin startproject django_project .

python manage.py runserver 0.0.0.0:8000

pip freeze > requirements.txt

create a Dockfile

create docker-compose.yml

docker-compose up -d –build

vim django_project/settings.py

In the Windows Host Computer Modify django source code and

  • docker-compose.exe web python manage.py startapp accounts
  • docker-compose.exe web python manage.py makemigrations accounts
  • docker-compose.exe web python manage.py migrate
  • docker-compose.exe web python manage.py createsuperuser
  • …………
分類: Django | 發佈留言

Use Docker to help Django Development

if you have pyenv Dockerfile, you can use docker built -t django:latest . to build a docker image.

command: docker run –rm -p 8000:8000 -p 3000:3000 -v c:\Users\Fluber\Project\Docker\django\book_django_beginners\:/home/fluber/code -it django:latest

enter a docker console environment to develop.

virtualenv .venv to build a python project environment.

pip install django==4.0.10

ajango-admin startproject new_project

python manage.py startapp new_app

modify new_project/settings.py and new_project/urls.py

modify new_app/models.py new_app/views.py new_app/urls.py

use python manage.py makemigrations

use python manage.py migrate

using python manage runserver 0.0.0.0:8000

I suggest to study the following books to help you know how to use django.

分類: Docker | 標籤: , | 發佈留言

Dockerfile for pyenv environment

  • Use a base image with a specific version of Ubuntu

FROM ubuntu:20.04

ENV TZ = Asia\Taipei

  • Set environment variables for non-interactive apt installation

ENV DEBIAN_FRONTEND=noninteractive

  • Install essential packages

RUN apt-get update && \
apt-get install -y \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libffi-dev \
liblzma-dev \
python3-venv \
sudo \
git \
tree \
vim \
&& rm -rf /var/lib/apt/lists/*

  • Switch to the /home directory

RUN useradd -m -s /bin/bash fluber && \
usermod -aG sudo fluber

  • Set a password for the ‘fluber’ user (change ‘password’ to your desired password)

RUN echo ‘fluber:123456’ | chpasswd

  • Switch to the ‘fluber’ user

USER fluber

  • Set the working directory to the home directory of the ‘fluber’ user

WORKDIR /home/fluber

  • Install pyenv

RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv

  • Add pyenv to the PATH

ENV PATH=”/home/fluber/.pyenv/bin:${PATH}”
RUN echo ‘export PYENV_ROOT=”/home/fluber/.pyenv”‘ >> ~/.bashrc
RUN echo ‘export PATH=”$PYENV_ROOT/bin:$PATH”‘ >> ~/.bashrc
RUN echo ‘eval “$(pyenv init –path)”‘ >> ~/.bashrc
RUN echo ‘eval “$(pyenv init -)”‘ >> ~/.bashrc

  • Install Python 3.8.12 and set it as the default version

RUN pyenv install 3.8.12 && \
pyenv global 3.8.12

  • Create a user named ‘fluber’ with sudo permissions
  • Expose any ports you need for your application (if applicable)
  • EXPOSE …
  • Start a bash shell when the container runs

CMD [“/bin/bash”]

分類: Django | 標籤: , | 發佈留言