Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
54e7ae3
1
Zney4 Sep 2, 2024
ada6868
Delete datacenter/__pycache__ directory
Zney4 Sep 4, 2024
58ea20e
Delete project/__pycache__ directory
Zney4 Sep 4, 2024
ee3fa45
Delete datacenter/migrations/__pycache__ directory
Zney4 Sep 4, 2024
9df67fa
Create .gitignore
Zney4 Sep 4, 2024
a897dfd
Delete .replit
Zney4 Sep 4, 2024
6de0bca
Delete .idea directory
Zney4 Sep 4, 2024
bf86646
Delete poetry.lock
Zney4 Sep 4, 2024
c0144f8
Delete pyproject.toml
Zney4 Sep 4, 2024
c68174e
Delete text
Zney4 Sep 4, 2024
8c68953
fix
Zney4 Sep 9, 2024
0fcee5b
fix
Zney4 Sep 9, 2024
651a81a
Merge branch 'master' of https://github.com/Zney4/django-orm-watching…
Zney4 Sep 9, 2024
c1d2f6c
fix code
Zney4 Sep 9, 2024
d53626e
fix code
Zney4 Sep 9, 2024
5123702
Merge pull request #1 from Zney4/dev
Zney4 Sep 9, 2024
e7a4308
Create README.md
Zney4 Sep 9, 2024
e05174e
Update README.md
Zney4 Sep 9, 2024
e252b4d
Update README.md
Zney4 Sep 23, 2024
3bb3fe0
fix code
Zney4 Sep 23, 2024
54099d5
Update requirements.txt
Zney4 Sep 27, 2024
eb02941
Create README.md
Zney4 Sep 27, 2024
7dc9eee
Update passcard_info_view.py
Zney4 Sep 27, 2024
23d45b9
Update models.py
Zney4 Sep 27, 2024
52aea4a
Merge branch 'dev'
Zney4 Sep 27, 2024
050fc50
fix code
Zney4 Sep 27, 2024
14f707c
fix code
Zney4 Oct 2, 2024
2823e1c
fix code
Zney4 Oct 2, 2024
2d7f08e
fix code
Zney4 Oct 2, 2024
4816ad6
fix code
Zney4 Oct 2, 2024
3e1b762
Update README.md
Zney4 Oct 2, 2024
b2d9f41
Update README.md
Zney4 Oct 7, 2024
e2c0fa5
Update README.md
Zney4 Oct 7, 2024
efa71d4
fix code
Zney4 Oct 9, 2024
5554ace
Merge remote-tracking branch 'origin/master'
Zney4 Oct 9, 2024
7d95104
fix code
Zney4 Oct 9, 2024
91cff69
Update README.md
Zney4 Oct 9, 2024
f09308f
Update README.md
Zney4 Oct 9, 2024
86cf795
fix code
Zney4 Oct 14, 2024
f2eadf2
Merge remote-tracking branch 'origin/master'
Zney4 Oct 14, 2024
b9563c9
Update README.md
Zney4 Oct 14, 2024
441b6c6
fix code
Zney4 Oct 21, 2024
bacceb6
Merge remote-tracking branch 'origin/master'
Zney4 Oct 21, 2024
eb09eae
Update README.md
Zney4 Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
.gitattributes
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
.idea
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
2 changes: 0 additions & 2 deletions .replit

This file was deleted.

47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# База данных хранилища или пульт управления для охранника

## Короткое описание проекта

Пульт управления для охранника, чтобы он мог следить за всеми, кто находится в хранилище.


## Требования к окружению
Python

Python3 должен быть уже установлен,
затем используйте `pip` (или `pip3`, есть конфликт с Python2) для установки зависимостей.
```python
pip install -r requirements.txt
```
## Переменные окружения
Файл .env
В нём надо указать данные для файла `settings.py`.
```
DB_ENGINE=example
DB_HOST=example
DB_PORT=example
DB_NAME=example
DB_USER=example
DB_PASSWORD=example
ALLOWED_HOSTS=example
SECRET_KEY=example
```
В файле settings.py есть настройка `DEBUG`, она включает отладочный режим работы сайта. На локальной машине она обычно равна True, а на сервере — False. Чтобы случайно не отправить `DEBUG` = True на сервер вместе с очередным коммитом, эту настройку выносят в переменную окружения.

#### Для запуска сайта
```
python main
```

### Пример результата

Открываем браузер и заходим на локальный сайт:
```
http://localhost:8000
```


### Цель проекта
Cделать пульт управления для охранника, чтобы он мог следить за всеми, кто находится в хранилище.

Код написан в образовательных целях..
7 changes: 3 additions & 4 deletions datacenter/active_passcards_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@


def active_passcards_view(request):
# Программируем здесь

all_passcards = Passcard.objects.all()
active_passcards = Passcard.objects.filter(is_active=True)
context = {
'active_passcards': all_passcards, # люди с активными пропусками
"active_passcards": active_passcards,
}
return render(request, 'active_passcards.html', context)
return render(request, "active_passcards.html", context)
36 changes: 30 additions & 6 deletions datacenter/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.db import models
from django.utils.timezone import localtime
from datetime import timezone
import datetime


class Passcard(models.Model):
Expand All @@ -10,7 +13,7 @@ class Passcard(models.Model):
def __str__(self):
if self.is_active:
return self.owner_name
return f'{self.owner_name} (inactive)'
return f"{self.owner_name} (inactive)"


class Visit(models.Model):
Expand All @@ -20,11 +23,32 @@ class Visit(models.Model):
leaved_at = models.DateTimeField(null=True)

def __str__(self):
return '{user} entered at {entered} {leaved}'.format(
return "{user} entered at {entered} {leaved}".format(
user=self.passcard.owner_name,
entered=self.entered_at,
leaved=(
f'leaved at {self.leaved_at}'
if self.leaved_at else 'not leaved'
)
leaved=(f"leaved at {self.leaved_at}" if self.leaved_at else "not leaved"),
)

def get_duration(self):
visit_time = (
localtime(self.leaved_at) - localtime(self.entered_at)
).total_seconds()
return visit_time

def format_duration(self, visit_time):
seconds = visit_time.total_seconds()
hours = seconds // 3600

minutes = (seconds % 3600) // 60

return f"{int(hours)}ч {int(minutes)}мин"

def is_visit_long(self):
now = datetime.datetime.now(timezone.utc)
minutes = 60

if self.leaved_at is None:
duration = (now - localtime(self.entered_at)).total_seconds()
else:
duration = self.get_duration()
return duration // 60 > minutes
34 changes: 19 additions & 15 deletions datacenter/passcard_info_view.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from datacenter.models import Passcard
from datacenter.models import Visit
from django.shortcuts import render
from django.shortcuts import render, get_object_or_404
from django.utils.timezone import localtime


def passcard_info_view(request, passcode):
passcard = Passcard.objects.all()[0]
# Программируем здесь
this_passcard_visits = []
passcard = get_object_or_404(Passcard, passcode=passcode)
visits = Visit.objects.filter(passcard=passcard)

this_passcard_visits = [
{
'entered_at': '11-04-2018',
'duration': '25:03',
'is_strange': False
},
]
context = {
'passcard': passcard,
'this_passcard_visits': this_passcard_visits
}
return render(request, 'passcard_info.html', context)
for visit in visits:
entered = localtime(visit.entered_at)
leave = localtime(visit.leaved_at)

this_passcard_visits.append(
{
"entered_at": entered,
"duration": visit.format_duration(leave - entered),
"is_strange": visit.is_visit_long(),
}
)

context = {"passcard": passcard, "this_passcard_visits": this_passcard_visits}
return render(request, "passcard_info.html", context)
30 changes: 20 additions & 10 deletions datacenter/storage_information_view.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
from datacenter.models import Passcard
from datacenter.models import Visit
from django.shortcuts import render
from django.utils.timezone import localtime
from datetime import timezone
import datetime


def storage_information_view(request):
# Программируем здесь
non_closed_visits = []
not_leaved_visit = Visit.objects.filter(leaved_at=None)
now = datetime.datetime.now(timezone.utc)

for visit in not_leaved_visit:
entered = localtime(visit.entered_at)

non_closed_visits.append(
{
"who_entered": visit.passcard.owner_name,
"entered_at": entered,
"duration": visit.format_duration(now - entered),
"is_strange": visit.is_visit_long(),
}
)

non_closed_visits = [
{
'who_entered': 'Richard Shaw',
'entered_at': '11-04-2018 25:34',
'duration': '25:03',
}
]
context = {
'non_closed_visits': non_closed_visits, # не закрытые посещения
"non_closed_visits": non_closed_visits,
}
return render(request, 'storage_information.html', context)
return render(request, "storage_information.html", context)
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from django.core.management import execute_from_command_line

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
execute_from_command_line('manage.py runserver 0.0.0.0:8000'.split())
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
execute_from_command_line("manage.py runserver 0.0.0.0:8000".split())
Loading