Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Some code clean-up viur-base #133

Merged
merged 2 commits into from
Aug 28, 2024
Merged
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
302 changes: 151 additions & 151 deletions Pipfile.lock

Large diffs are not rendered by default.

43 changes: 11 additions & 32 deletions deploy/modules/file.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
import datetime
from typing import Dict, List
from viur.core import i18n, db, current
from viur.core.modules.file import File

from viur.core import db, utils
from viur.core.modules.file import File as _File

class File(File):

class File(_File):
def getAvailableRootNodes(self, *args, **kwargs):
# Any user who is logged in can see the root-node.
if current.user.get():
repository = self.ensureOwnModuleRootNode()

def getAvailableRootNodes(self, *args, **kwargs) -> List[Dict]:
if utils.getCurrentUser():
repo: db.Entity = self.ensureOwnModuleRootNode()

res = [
{
"name": "Files",
"key": repo.key
}
]
return res
return [{
"name": i18n.translate("Files"),
"key": repository.key
}]

return []

def ensureOwnModuleRootNode(self) -> db.Entity:
"""
Ensures, that general root-node for the current module exists.
If no root-node exists yet, it will be created.

:returns: The entity of the root-node.
"""
key = "rep_module_repo"
kindName = self.viewSkel("node").kindName

return db.GetOrInsert(
db.Key(kindName, key),
creationdate=datetime.datetime.now(),
rootNode=1
)
28 changes: 1 addition & 27 deletions deploy/modules/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import datetime
import logging
from viur.core import current, errors, exposed, utils, Module
from google.cloud.datastore_admin_v1.services.datastore_admin.client import DatastoreAdminClient
from viur.core import current, errors, exposed, Module


class Index(Module):
Expand Down Expand Up @@ -35,26 +32,3 @@ def scriptor(self):
def sitemap_xml(self, *args, **kwargs):
current.request.get().response.headers["Content-Type"] = "text/xml"
return self.render.view({}, tpl="sitemap")

# @tasks.PeriodicTask(24 * 60)
def backup(self, *args, **kwargs):
"""
Backup job kick-off for Google Cloud Storage.
Use the maintenance script setup/enable-backup.sh to configure your project for backups.
"""
if utils.isLocalDevelopmentServer:
logging.info("Backup tool is disabled on local development server")
return

bucket = "backup-dot-%s" % utils.projectID
admin_client = DatastoreAdminClient()
timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")

output_url_prefix = "gs://%s/%s" % (bucket, timestamp)

admin_client.export_entities(
project_id=utils.projectID,
output_url_prefix=output_url_prefix
)

logging.info("Backup queued to be exported to %r", output_url_prefix)
10 changes: 8 additions & 2 deletions deploy/modules/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class User(User):

# Extend default adminInfo to custom adminInfo
adminInfo = User.adminInfo | {
"columns": ["lastname", "firstname", "name"],
"filter": {"orderby": "lastname"},
"columns": [
"name",
"firstname",
"lastname",
],
"filter": {
"orderby": "lastname",
},
}
2 changes: 1 addition & 1 deletion deploy/render/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from viur.core.render import admin, html, json, vi, xml
from viur.core.render import admin, html, json, vi
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"admin": {
"command": "viur package install admin",
"kind": "exec",
"version": "4.4.3"
"version": "4.4.6"
},
"npm": {
"command": "build",
Expand Down
41 changes: 0 additions & 41 deletions setup/enable-backup.sh

This file was deleted.

Loading