1
1
from flask import Blueprint , render_template , abort
2
+ from flask import *
2
3
from jinja2 import TemplateNotFound
3
4
import stripe
4
5
import config
5
- import os
6
+ import sys , os
7
+ from colorama import Fore , Back , Style
8
+ from colorama import init
9
+ import imp
10
+ import json
6
11
module = Blueprint ('Loona Products' , __name__ )
7
12
module .hasAdminPage = True
8
13
module .moduleDescription = 'The Core Product Management Module for LoonaBilling'
14
+ module .version = '1.1'
9
15
10
16
def cf (folder ):
11
17
try :
@@ -14,12 +20,53 @@ def cf(folder):
14
20
except Exception as e :
15
21
#print(e)
16
22
pass
23
+ mods = {}
24
+ for path , dirs , files in os .walk ("core/payments" , topdown = False ):
25
+ for fname in files :
26
+ try :
27
+ name , ext = os .path .splitext (fname )
28
+ if ext == '.py' and not name == '__init__' :
29
+ f , filename , descr = imp .find_module (name , [path ])
30
+ mods [fname ] = imp .load_module (name , f , filename , descr )
31
+ #print(getattr(mods[fname]))
32
+ print (Fore .GREEN + '[Product Module] ' + Style .RESET_ALL + 'Imported' , mods [fname ].module .name )
33
+ #globals()
34
+ except Exception as e :
35
+ exc_type , exc_obj , exc_tb = sys .exc_info ()
36
+ fname = os .path .split (exc_tb .tb_frame .f_code .co_filename )[1 ]
37
+ print (Fore .RED , '[ERROR]' , path , name , e , exc_type , fname , exc_tb .tb_lineno , Style .RESET_ALL )
17
38
18
39
def checks ():
19
40
cf ('products' )
41
+ cf ('products/default' )
20
42
21
43
checks ()
22
44
23
45
@module .route ('/admin/{}' .format (module .name ))
24
46
def adminPage ():
25
47
return render_template ('core/LoonaProducts/admin.html' , businessName = config .businessName , moduleName = module .name , moduleDescription = module .moduleDescription )
48
+
49
+ @module .route ('/admin/{}/createProduct' .format (module .name ), methods = ['GET' , 'POST' ])
50
+ def createProduct ():
51
+ if request .method == 'POST' :
52
+ print (request .form )
53
+ description = ''
54
+ if 'description' in request .form :
55
+ description = request .form ['description' ]
56
+ if 'title' not in request .form :
57
+ return render_template ('core/LoonaProducts/adminCreateProduct.html' , categories = os .listdir ('products' ), msg = 'Title is missing' , businessName = config .businessName , moduleName = module .name , moduleDescription = module .moduleDescription )
58
+ elif 'price' not in request .form :
59
+ return render_template ('core/LoonaProducts/adminCreateProduct.html' , categories = os .listdir ('products' ), msg = 'Price is missing' , businessName = config .businessName , moduleName = module .name , moduleDescription = module .moduleDescription )
60
+ else :
61
+ data = {}
62
+ data ['Config' ] = []
63
+ data ['Config' ].append ({
64
+ 'title' : request .form ['title' ],
65
+ 'description' : description ,
66
+ 'price' : request .form ['price' ],
67
+ 'automation' : None
68
+ })
69
+ with open ('products/{}/{}.json' .format (request .form ['category' ], len (os .listdir ('products/{}' .format (request .form ['category' ])))), 'w+' ) as of :
70
+ json .dump (data , of )
71
+ return render_template ('core/LoonaProducts/adminCreateProduct.html' , categories = os .listdir ('products' ), msg = f'Created Product: { request .fprm ["title" ]} ' , businessName = config .businessName , moduleName = module .name , moduleDescription = module .moduleDescription )
72
+ return render_template ('core/LoonaProducts/adminCreateProduct.html' , categories = os .listdir ('products' ), businessName = config .businessName , moduleName = module .name , moduleDescription = module .moduleDescription )
0 commit comments