Skip to content
Open

Dev #12

Show file tree
Hide file tree
Changes from all commits
Commits
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.

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)
35 changes: 29 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,31 @@ 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.entered_at == 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