Skip to content

Commit

Permalink
property manager initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak committed Sep 19, 2022
1 parent c1c179f commit cdda464
Show file tree
Hide file tree
Showing 16 changed files with 641 additions and 159 deletions.
5 changes: 5 additions & 0 deletions src/OpenIntranet/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def get_current_user(self):

class BaseHandler(tornado.web.RequestHandler):
def prepare(self):

user_agent = self.request.headers["User-Agent"]
self.OIAPP = True if user_agent == 'OpenIntranetApp' else False
print("Iam running in app", self.OIAPP)

login = self.get_secure_cookie("user")
if login:
login = str(login, encoding="utf-8")
Expand Down
20 changes: 9 additions & 11 deletions src/OpenIntranet/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ def repl(f):
return layer


'''
@parametrized
def perm_validator(fn, permissions = [], sudo=True):
print("Validace opravneni.....")
print(permissions, sudo, fn.__dict__)
print(fn)
return fn
'''


def save_file(db, original_filename):
path = os.path.dirname(original_filename)
file = os.path.basename(original_filename)
Expand Down Expand Up @@ -116,6 +105,7 @@ def database_init():
def get_company_info(database):
return database.intranet.find_one({"_id": "company_info"}) or {}


def get_default_warehouse(database):
default = database.intranet.find_one({"_id": "default_warehouse"})
# TODO: umoznit uzivatelum mit vlastni vychozi sklad
Expand Down Expand Up @@ -213,6 +203,13 @@ class BaseHandler(tornado.web.RequestHandler):
role_module = []

def prepare(self):


user_agent = self.request.headers["User-Agent"]
self.in_app = True if 'Electron' in user_agent else False
print("Iam running in app", self.in_app)


login = self.get_secure_cookie("user")
if login:
login = str(login, encoding="utf-8")
Expand Down Expand Up @@ -256,6 +253,7 @@ def get_template_namespace(self):
ns = super(BaseHandler, self).get_template_namespace()
ns.update({
'intranet_title': tornado.options.options.intranet_name,
'in_app': self.in_app,
})

return ns
Expand Down
8 changes: 4 additions & 4 deletions src/OpenIntranet/plugins/android_reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def get_plugin_handlers():
plugin_name = get_plugin_info()["name"]

return [
(r'/%s' % plugin_name, hand_bi_home),
(r'/%s/' % plugin_name, hand_bi_home),
(r'/{}'.format(plugin_name), hand_bi_home),
(r'/{}/'.format(plugin_name), hand_bi_home),
]


Expand All @@ -30,7 +30,7 @@ def get_plugin_info():
"entrypoints": [
{
"title": "Android čtečka",
"url": "/payment",
"url": "/android_barcode",
"icon": "android",
}
],
Expand All @@ -40,7 +40,7 @@ def get_plugin_info():

class hand_bi_home(BaseHandler):
def get(self, data=None):
roles = self.authorized(['andorid'], sudo=False)
roles = self.authorized(['andorid'], sudo=True)
print(">>>>>", roles)

self.render("android_barcode.home.hbs", title="UST intranet", parent=self)
24 changes: 24 additions & 0 deletions src/OpenIntranet/plugins/property_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from .backend.property_manager import *
#from .. import BaseHandler


def get_plugin_handlers():
plugin_name = get_plugin_info()["name"]

return [
(r'/{}'.format(plugin_name), HomeHandler),
(r'/{}/'.format(plugin_name), HomeHandler),
]


def get_plugin_info():
return {
"name": "property_manager",
"entrypoints": [
{
"title": "Property manager",
"url": "/property_manager",
"icon": "bi-pc-display",
}
]
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import json
from datetime import datetime, timedelta

import bson.json_util
import tornado
import tornado.options
from bson import ObjectId
from dateutil.relativedelta import relativedelta
from tornado.web import HTTPError

from plugins import BaseHandler, password_hash
from plugins import BaseHandlerOwnCloud
from plugins.helpers import database_user as udb
from plugins.helpers import str_ops
from plugins.helpers.contract_generation import generate_contract
from plugins.helpers.doc_keys import CONTRACT_DOC_KEYS
from plugins.helpers.emails import generate_validation_token, generate_validation_message, send_email
from plugins.helpers.exceptions import BadInputHTTPError, MissingInfoHTTPError, ForbiddenHTTPError
from plugins.helpers.mdoc_ops import find_type_in_addresses, update_workspans_contract_id
from plugins.helpers.owncloud_utils import get_file_url, generate_contracts_directory_path, \
generate_documents_directory_path
from plugins.users.backend.helpers.api import ApiJSONEncoder



"""
Role:
základní uživatel nemá speciální roli jelikož všichni jsou základními uživateli
users-proprety_manager - spravce majetku
users-sudo - Admin
"""

ROLE_SUDO = "users-sudo"

class HomeHandler(BaseHandler):
def get(self):

self.render("../plugins/property_manager/frontend/property_manager.overview.hbs")
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{% extends "base.hbs" %}
{% block title %} | Produkce, uvod{% end %}
{% block body %}

{% import datetime %}

<nav style="margin: 0.5rem;" style="--bs-breadcrumb-divider: url(&#34;data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' widtd='8' height='8'%3E%3Cpatd d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='currentColor'/%3E%3C/svg%3E&#34;);" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="./../">Home</a></li>
<li class="breadcrumb-item"><a href="#">Property manager</a></li>
</ol>
</nav>

<div class="container-fluid row">
<div class="col-md-4 col-sm-12 col-12 bg-faded sidebar">


<div class="card">
<div class="card-body">

<div class="card-title">
<h5>Kategorie</h5>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="search_by_category">
<label class="form-check-label" for="search_by_category">Vyhledávat dle kategorií</label>
</div>
<a href="#" class="badge bg-primary" onclick="$('#category-tree').jstree('open_all')">Rozbalit vše</a>
<a href="#" class="badge bg-primary" onclick="$('#category-tree').jstree('close_all')">Sbalit vše</a>
<a href="#" class="badge bg-primary" onclick="$('#category-tree').jstree('select_all')">Vybrat vše</a>
<a href="#" class="badge bg-primary" onclick="$('#category-tree').jstree('deselect_all')">Odznačit vše</a>
</div>

<div id="category-tree">

</div>

</div>

</div>

</div>
<div class="col-md-8 col-sm-12">



<div class="card">
<div class="card-body">

<div class="card-title">
<h5>Seznam majetku</h5>

</div>

<div id="category-tree">

</div>

</div>

</div>


</div>
</div>

</script>

{% end %}
13 changes: 8 additions & 5 deletions src/OpenIntranet/plugins/store/data_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ def api_call(action, params, token, app_secret, show_header=False):
return json.loads(html);


def mouser_api_call(action, mouser_key, body):
def mouser_api_call(action, mouser_key, body = {}, method = "POST", debug = True):
api_url = "https://api.mouser.com/api/v1/" + action + "?apiKey=" + mouser_key
response = request.Request(url=api_url, data=bytes(json.dumps(body), encoding='utf8'), headers={'Content-Type': 'application/json'}, method='POST' )
response = json.loads(request.urlopen(response).read())['SearchResults']['Parts'][0]
print("Mouser api call", api_url)
print(body)
response = request.Request(url=api_url, data=bytes(json.dumps(body), encoding='utf8'), headers={'Content-Type': 'application/json'}, method=method )
response = json.loads(request.urlopen(response).read())
print(response)
return response


Expand Down Expand Up @@ -231,7 +234,7 @@ def get(self, component_id = None):
}
}

product = mouser_api_call('search/partnumber', key, body)
product = mouser_api_call('search/partnumber', key, body)['SearchResults']['Parts'][0]

# self.write({'files': product_files['Data'], 'parameters': parameters['Data'], 'products': products})
self.render('store/store.api.importer.mouser.data.hbs',product=product)
Expand Down Expand Up @@ -302,7 +305,7 @@ def get(self):
}
}

product = mouser_api_call('search/partnumber', key, body)
product = mouser_api_call('search/partnumber', key, body)['SearchResults']['Parts'][0]

# self.write({'files': product_files['Data'], 'parameters': parameters['Data'], 'products': products})
self.render('store/store.api.importer.mouser.data.hbs',product=product)
Loading

0 comments on commit cdda464

Please sign in to comment.