Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6d019a7
скачала архив и загрузила рек
Aug 29, 2024
192675c
Добавила прект на Гит
Sep 12, 2024
d06df55
Create README.md
Rrorrs Sep 12, 2024
59e6d88
Update README.md
Rrorrs Sep 12, 2024
5eef735
Create .gitignor
Rrorrs Sep 12, 2024
6dc9618
Delete .env
Rrorrs Sep 12, 2024
cede9e4
Delete venv directory
Rrorrs Sep 12, 2024
868f92f
Delete .gitignor
Rrorrs Sep 26, 2024
0a1e31f
Создала gitignore
Rrorrs Sep 26, 2024
1311c27
Delete replit_zip_error_log.txt
Rrorrs Sep 26, 2024
b17ba46
Delete replit.nix
Rrorrs Sep 26, 2024
723c02f
Delete .replit
Rrorrs Sep 26, 2024
e8b413d
Delete .cache directory
Rrorrs Sep 26, 2024
7883806
Delete .config directory
Rrorrs Sep 26, 2024
0c2145c
Delete .upm directory
Rrorrs Sep 26, 2024
db4a5c7
убрала dotenv
Oct 1, 2024
3acb4b2
изменила названия
Oct 10, 2024
6e724e5
изменила названия
Oct 10, 2024
fc42799
Merge branch 'master' of https://github.com/Rrorrs/django-orm-watchin…
Oct 10, 2024
a5d6ea2
Исправила env
Oct 17, 2024
5bb71d4
Вернула датацентер
Oct 22, 2024
fa0ecde
исправила ошибки
Oct 29, 2024
ae81409
Переименовала переменные
Oct 29, 2024
2aa7e58
убрала root
Oct 29, 2024
0914d56
добавила обозначения
Oct 29, 2024
55e8892
Update README.md
Rrorrs Oct 29, 2024
d18eadf
Дополнила README.md
Rrorrs Oct 31, 2024
da89e42
изменила названия переменных
Nov 28, 2024
f3ad941
Merge branch 'master' of https://github.com/Rrorrs/django-orm-watchin…
Nov 28, 2024
28c44f5
.
Nov 28, 2024
ffbb0b3
добавила библиотеку в requirements
Nov 28, 2024
c1c2a27
Исправила README
Nov 28, 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
167 changes: 167 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
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/
.config
.upm
.replit
replit.nix
replit_zip_error_log.txt

# 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/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# 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/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
2 changes: 0 additions & 2 deletions .replit

This file was deleted.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Пульт охраны банка

Это внутренний репозиторий для сотрудников банка «Сияние». Если вы попали в этот репозиторий случайно, то вы не сможете его запустить, т.к. у вас нет доступа к БД, но можете свободно использовать код вёрстки или посмотреть как реализованы запросы к БД.
Пульт охраны — это сайт, который можно подключить к удалённой базе данных с визитами и карточками пропуска сотрудников нашего банка.

## Как установить

### Переменные окружения

В переменных окружения находятся основные настройки сервера: пароли, ключ доступа и другие базовые данные для настройки сервера. Переменные храняться в файле `.env`

Python3 должен быть уже установлен.
Затем используйте `pip` (или `pip3`, есть конфликт с Python2) для установки зависимостей:
```
pip install -r requirements.txt
```

- 'DB_ENGINE' - ссылка на движок базы данных
- 'DB_HOST' - ссылка на сервер БД
- 'DB_PORT' - порт сервера БД
- 'DB_NAME' - имя сервера БД
- 'DB_USER' - имя пользователя, который имеет доступ к БД
- 'DB_PASSWORD' - пароль от БД
- 'DB_SECRET_KEY' - ключ доступа к БД
- 'DB_ALLOWED_HOSTS' - список адресов всех доменов, которые могут запускать проект
- 'DB_DEBUG' - активация/деактивация режима отладки

### Цель проекта

Код написан в образовательных целях на онлайн-курсе для веб-разработчиков [dvmn.org](https://dvmn.org/).
9 changes: 4 additions & 5 deletions datacenter/active_passcards_view.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from datacenter.models import Passcard
from datacenter.models import Visit
# from datacenter.models import Passcard
from datacenter.models import Passcard, Visit
from django.shortcuts import render


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)
18 changes: 18 additions & 0 deletions datacenter/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.db import models
from django.utils.timezone import localtime



class Passcard(models.Model):
Expand Down Expand Up @@ -28,3 +30,19 @@ def __str__(self):
if self.leaved_at else 'not leaved'
)
)


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

def format_duration(self, duration):
hours, minutes = int(duration // 3600), int((duration % 3600 // 60))
return f"{hours} ч. {minutes} м."

def is_visit_long(self, minutes=60):
duration = self.get_duration()
return duration // 60 > minutes


29 changes: 18 additions & 11 deletions datacenter/passcard_info_view.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
from datacenter.models import Passcard
from datacenter.models import Visit
# from models import Passcard
from datacenter.models import Passcard, Visit
from django.shortcuts import render
from django.utils.timezone import localtime
from django.shortcuts import get_object_or_404
from django.shortcuts import get_list_or_404


def passcard_info_view(request, passcode):
passcard = Passcard.objects.all()[0]
# Программируем здесь
passcard = get_object_or_404(Passcard, passcode=passcode)
this_passcard_visits = []
passcard_visits = get_list_or_404(Visit, passcard=passcard)
for visit in passcard_visits:
time_entered_at = localtime(visit.entered_at)
duration = visit.get_duration()

this_passcard_visits = [
{
'entered_at': '11-04-2018',
'duration': '25:03',
'is_strange': False
},
]
this_passcard_visits.append(
{
'entered_at': time_entered_at,
'duration': visit.format_duration(duration),
'is_strange': visit.is_visit_long(),
}
)
context = {
'passcard': passcard,
'this_passcard_visits': this_passcard_visits
Expand Down
28 changes: 18 additions & 10 deletions datacenter/storage_information_view.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
from datacenter.models import Passcard
from datacenter.models import Visit
from django.shortcuts import render
from django.utils.timezone import localtime


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

non_closed_visits = [
{
'who_entered': 'Richard Shaw',
'entered_at': '11-04-2018 25:34',
'duration': '25:03',
}
]
def storage_information_view(request):

active_visits = Visit.objects.filter(leaved_at=None)
non_closed_visits = []
for visit in active_visits:
name_visit = visit.passcard.owner_name
time_entered_at = localtime(visit.entered_at)
duration = visit.get_duration()
non_closed_visits.append(
{
'who_entered': name_visit,
'entered_at': time_entered_at,
'duration': visit.format_duration(duration),
'is_strange': visit.is_visit_long()
}
)
context = {
'non_closed_visits': non_closed_visits, # не закрытые посещения
'non_closed_visits': non_closed_visits,
}
return render(request, 'storage_information.html', context)
6 changes: 0 additions & 6 deletions main.py

This file was deleted.

14 changes: 14 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
Loading