Skip to content

Commit

Permalink
Merge pull request #141 from sei-vsarvepalli/version-3.0.0
Browse files Browse the repository at this point in the history
Update to VINCE 3.0.0
  • Loading branch information
sei-vsarvepalli authored Apr 12, 2024
2 parents 3f3e1ba + 532853b commit ecbe946
Show file tree
Hide file tree
Showing 42 changed files with 1,734 additions and 1,878 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# VINCE Changelog

CHANGELOG
VINCE Coordination platform code

Version 3.0.0 2024-04-10

* Made the Vendor Association button to track and populate ticket id & (if appropriate) vendor name.
* Upgraded `Django` 4.2 - Django 3 is end-of-life
* Restructured code for preparing vendors table data on VINCE Track case page so as to reduce load time
* Refactored certain queries for the VINCE Track reports page in support of the long term goal of reducing its load time


Version 2.1.11 2024-03-14

* Dependabot update recommendations: `cryptography` 41.0.6 to 42.0.4 and `django` from 3.2.23 to 3.2.24
* Dependabot update recommendations: `cryptography` 41.0.6 to 42.0.4 and `django` from 3.2.23 to 3.2.24
* Added code to ensure comments entered into comment box will be preserved when user uploads a file
* Fixed filters above vendor table in vendor tab of case page to ensure consistency with data in vendor table
* Added logging to make it easier to track user deactivation & MFA resetting processes
Expand Down
8 changes: 6 additions & 2 deletions bakery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
default_app_config = 'bakery.apps.BakeryConfig'
import django

if django.VERSION < (3, 2):
default_app_config = "bakery.apps.BakeryConfig"

DEFAULT_GZIP_CONTENT_TYPES = (
"application/atom+xml",
"application/javascript",
Expand Down Expand Up @@ -31,5 +35,5 @@
"text/vtt",
"text/x-component",
"text/x-cross-domain-policy",
"text/xml"
"text/xml",
)
109 changes: 44 additions & 65 deletions bakery/management/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Filesystem
from fs import path
from fs import copy
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str as smart_text

# Pooling
import multiprocessing
Expand All @@ -25,6 +25,7 @@
from django.apps import apps
from django.conf import settings
from django.core import management

try:
from django.core.urlresolvers import get_callable
except ImportError:
Expand All @@ -34,57 +35,54 @@

# Logging
import logging

logger = logging.getLogger(__name__)


class Command(BaseCommand):
help = 'Bake out a site as flat files in the build directory'
help = "Bake out a site as flat files in the build directory"
build_unconfig_msg = "Build directory unconfigured. Set BUILD_DIR in settings.py or provide it with --build-dir"
views_unconfig_msg = "Bakery views unconfigured. Set BAKERY_VIEWS in settings.py or provide a list as arguments."
# regex to match against for gzipping. CSS, JS, JSON, HTML, etc.
gzip_file_match = getattr(
settings,
'GZIP_CONTENT_TYPES',
DEFAULT_GZIP_CONTENT_TYPES
)
gzip_file_match = getattr(settings, "GZIP_CONTENT_TYPES", DEFAULT_GZIP_CONTENT_TYPES)

def add_arguments(self, parser):
parser.add_argument('view_list', nargs='*', type=str, default=[])
parser.add_argument("view_list", nargs="*", type=str, default=[])
parser.add_argument(
"--build-dir",
action="store",
dest="build_dir",
default='',
default="",
help="Specify the path of the build directory. \
Will use settings.BUILD_DIR by default."
Will use settings.BUILD_DIR by default.",
)
parser.add_argument(
"--keep-build-dir",
action="store_true",
dest="keep_build_dir",
default=False,
help="Skip initializing the build directory before building files."
help="Skip initializing the build directory before building files.",
)
parser.add_argument(
"--skip-static",
action="store_true",
dest="skip_static",
default=False,
help="Skip collecting the static files when building."
help="Skip collecting the static files when building.",
)
parser.add_argument(
"--skip-media",
action="store_true",
dest="skip_media",
default=False,
help="Skip collecting the media files when building."
help="Skip collecting the media files when building.",
)
parser.add_argument(
"--pooling",
action="store_true",
dest="pooling",
default=False,
help=("Pool builds to run concurrently rather than running them one by one.")
help=("Pool builds to run concurrently rather than running them one by one."),
)

def handle(self, *args, **options):
Expand Down Expand Up @@ -118,14 +116,14 @@ def set_options(self, *args, **options):
"""
Configure a few global options before things get going.
"""
self.verbosity = int(options.get('verbosity', 1))
self.verbosity = int(options.get("verbosity", 1))

# Figure out what build directory to use
if options.get("build_dir"):
self.build_dir = options.get("build_dir")
settings.BUILD_DIR = self.build_dir
else:
if not hasattr(settings, 'BUILD_DIR'):
if not hasattr(settings, "BUILD_DIR"):
raise CommandError(self.build_unconfig_msg)
self.build_dir = settings.BUILD_DIR

Expand All @@ -144,15 +142,15 @@ def set_options(self, *args, **options):
self.fs.makedirs(self.build_dir)

# Figure out what views we'll be using
if options.get('view_list'):
self.view_list = options['view_list']
if options.get("view_list"):
self.view_list = options["view_list"]
else:
if not hasattr(settings, 'BAKERY_VIEWS'):
if not hasattr(settings, "BAKERY_VIEWS"):
raise CommandError(self.views_unconfig_msg)
self.view_list = settings.BAKERY_VIEWS

# Are we pooling?
self.pooling = options.get('pooling')
self.pooling = options.get("pooling")

def init_build_dir(self):
"""
Expand All @@ -174,20 +172,13 @@ def build_static(self, *args, **options):
logger.debug("Building static directory")
if self.verbosity > 1:
self.stdout.write("Building static directory")
management.call_command(
"collectstatic",
interactive=False,
verbosity=0
)
management.call_command("collectstatic", interactive=False, verbosity=0)

# Set the target directory inside the filesystem.
target_dir = path.join(
self.build_dir,
settings.STATIC_URL.lstrip('/')
)
target_dir = path.join(self.build_dir, settings.STATIC_URL.lstrip("/"))
target_dir = smart_text(target_dir)
if os.path.exists(self.static_root) and settings.STATIC_URL:
if getattr(settings, 'BAKERY_GZIP', False):
if getattr(settings, "BAKERY_GZIP", False):
self.copytree_and_gzip(self.static_root, target_dir)
# if gzip isn't enabled, just copy the tree straight over
else:
Expand All @@ -197,15 +188,15 @@ def build_static(self, *args, **options):
# If they exist in the static directory, copy the robots.txt
# and favicon.ico files down to the root so they will work
# on the live website.
robots_src = path.join(target_dir, 'robots.txt')
robots_src = path.join(target_dir, "robots.txt")
if self.fs.exists(robots_src):
robots_target = path.join(self.build_dir, 'robots.txt')
robots_target = path.join(self.build_dir, "robots.txt")
logger.debug("Copying {}{} to {}{}".format(self.fs_name, robots_src, self.fs_name, robots_target))
self.fs.copy(robots_src, robots_target)

favicon_src = path.join(target_dir, 'favicon.ico')
favicon_src = path.join(target_dir, "favicon.ico")
if self.fs.exists(favicon_src):
favicon_target = path.join(self.build_dir, 'favicon.ico')
favicon_target = path.join(self.build_dir, "favicon.ico")
logger.debug("Copying {}{} to {}{}".format(self.fs_name, favicon_src, self.fs_name, favicon_target))
self.fs.copy(favicon_src, favicon_target)

Expand All @@ -217,10 +208,9 @@ def build_media(self):
if self.verbosity > 1:
self.stdout.write("Building media directory")
if os.path.exists(self.media_root) and settings.MEDIA_URL:
target_dir = path.join(self.build_dir, settings.MEDIA_URL.lstrip('/'))
target_dir = path.join(self.build_dir, settings.MEDIA_URL.lstrip("/"))
logger.debug("Copying {}{} to {}{}".format("osfs://", self.media_root, self.fs_name, target_dir))
copy.copy_dir("osfs:///", smart_text(self.media_root), self.fs, smart_text(target_dir))


def get_view_instance(self, view):
"""
Expand Down Expand Up @@ -249,7 +239,7 @@ def copytree_and_gzip(self, source_dir, target_dir):
# Figure out what we're building...
build_list = []
# Walk through the source directory...
for (dirpath, dirnames, filenames) in os.walk(source_dir):
for dirpath, dirnames, filenames in os.walk(source_dir):
for f in filenames:
# Figure out what is going where
source_path = os.path.join(dirpath, f)
Expand All @@ -261,7 +251,7 @@ def copytree_and_gzip(self, source_dir, target_dir):
logger.debug("Gzipping {} files".format(len(build_list)))

# Build em all
if not getattr(self, 'pooling', False):
if not getattr(self, "pooling", False):
[self.copyfile_and_gzip(*u) for u in build_list]
else:
cpu_count = multiprocessing.cpu_count()
Expand Down Expand Up @@ -299,48 +289,37 @@ def copyfile_and_gzip(self, source_path, target_path):
# If it isn't a file want to gzip...
if content_type not in self.gzip_file_match:
# just copy it to the target.
logger.debug("Copying {}{} to {}{} because its filetype isn't on the whitelist".format(
"osfs://",
source_path,
self.fs_name,
target_path
))
logger.debug(
"Copying {}{} to {}{} because its filetype isn't on the whitelist".format(
"osfs://", source_path, self.fs_name, target_path
)
)
copy.copy_file("osfs:///", smart_text(source_path), self.fs, smart_text(target_path))

# # if the file is already gzipped
elif encoding == 'gzip':
logger.debug("Copying {}{} to {}{} because it's already gzipped".format(
"osfs://",
source_path,
self.fs_name,
target_path
))
elif encoding == "gzip":
logger.debug(
"Copying {}{} to {}{} because it's already gzipped".format(
"osfs://", source_path, self.fs_name, target_path
)
)
copy.copy_file("osfs:///", smart_text(source_path), self.fs, smart_text(target_path))

# If it is one we want to gzip...
else:
# ... let the world know ...
logger.debug("Gzipping {}{} to {}{}".format(
"osfs://",
source_path,
self.fs_name,
target_path
))
logger.debug("Gzipping {}{} to {}{}".format("osfs://", source_path, self.fs_name, target_path))
# Open up the source file from the OS
with open(source_path, 'rb') as source_file:
with open(source_path, "rb") as source_file:
# Write GZIP data to an in-memory buffer
data_buffer = six.BytesIO()
kwargs = dict(
filename=path.basename(target_path),
mode='wb',
fileobj=data_buffer
)
kwargs = dict(filename=path.basename(target_path), mode="wb", fileobj=data_buffer)
if float(sys.version[:3]) >= 2.7:
kwargs['mtime'] = 0
kwargs["mtime"] = 0
with gzip.GzipFile(**kwargs) as f:
f.write(six.binary_type(source_file.read()))

# Write that buffer out to the filesystem
with self.fs.open(smart_text(target_path), 'wb') as outfile:
with self.fs.open(smart_text(target_path), "wb") as outfile:
outfile.write(data_buffer.getvalue())
outfile.close()
Loading

0 comments on commit ecbe946

Please sign in to comment.