q2rad 0.1.231__tar.gz → 0.1.233__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of q2rad might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: q2rad
3
- Version: 0.1.231
3
+ Version: 0.1.233
4
4
  Summary: RAD - database, GUI, reports
5
5
  Author: Andrei Puchko
6
6
  Author-email: andrei.puchko@gmx.de
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "q2rad"
3
- version = "0.1.231"
3
+ version = "0.1.233"
4
4
  description = "RAD - database, GUI, reports"
5
5
  authors = ["Andrei Puchko <andrei.puchko@gmx.de>"]
6
6
  readme = "README.md"
@@ -22,6 +22,8 @@ from q2rad import Q2Form
22
22
  from q2terminal.q2terminal import Q2Terminal
23
23
  from q2rad.q2raddb import insert, update, get
24
24
  from datetime import datetime
25
+ from urllib.parse import urlparse
26
+ from q2rad.q2utils import ftp_upload
25
27
 
26
28
  import json
27
29
  import os
@@ -163,6 +165,7 @@ class AppManager(Q2Form):
163
165
  control="button",
164
166
  # datalen=14,
165
167
  valid=self.export_q2market,
168
+ style="background:LightCoral",
166
169
  )
167
170
  self.add_control("/")
168
171
 
@@ -184,6 +187,7 @@ class AppManager(Q2Form):
184
187
  control="button",
185
188
  # datalen=10,
186
189
  valid=self.import_app_all,
190
+ style="background:red",
187
191
  )
188
192
  if self.q2_app.app_url:
189
193
  self.add_control(
@@ -313,16 +317,46 @@ class AppManager(Q2Form):
313
317
  if app_name == "demo_app":
314
318
  self.export_data(f"{self.q2_app.q2market_path}/demo_data.json")
315
319
 
316
- trm = Q2Terminal(callback=print)
317
-
318
- def worker():
319
- trm.run(f"cd {self.q2_app.q2market_path}")
320
- trm.run("git add -A")
321
- trm.run(f"""git commit -a -m"{version}" """)
320
+ if os.path.isdir(f"{self.q2_app.q2market_path}/.git"):
321
+ trm = Q2Terminal(callback=print)
322
+
323
+ def worker():
324
+ trm.run(f"cd {self.q2_app.q2market_path}")
325
+ trm.run("git add -A")
326
+ trm.run(f"""git commit -a -m"{version}" """)
327
+
328
+ q2working(worker, "Commiting")
329
+ q2Mess(trm.run("""git push"""))
330
+ trm.close()
331
+ else: # try FTP
332
+ if os.path.isfile(".ftp"):
333
+ login, password = open(".ftp").read().split("\n")
334
+ else:
335
+ login, password = (
336
+ "",
337
+ "",
338
+ )
322
339
 
323
- q2working(worker, "Commiting")
324
- q2Mess(trm.run("""git push"""))
325
- trm.close()
340
+ app_file = f"{self.q2_app.q2market_path}/{os.path.basename(self.q2_app.app_url)}"
341
+ app_file_json = f"{app_file}.json"
342
+ app_file_version = f"{app_file}.version"
343
+ server = urlparse(self.q2_app.app_url).netloc
344
+ if server in self.q2_app.app_url:
345
+ workdir = os.path.dirname(self.q2_app.app_url.split(server)[1])
346
+ else:
347
+ workdir = ""
348
+ ftp_creds = Q2Form("FTP credentials")
349
+ ftp_creds.add_control("server", "Server", datalen=100, data=server)
350
+ ftp_creds.add_control("login", "Login", datalen=100, data=login)
351
+ ftp_creds.add_control("password", "Password", pic="*", datalen=100, data=password)
352
+ ftp_creds.ok_button = 1
353
+ ftp_creds.cancel_button = 1
354
+ ftp_creds.run()
355
+ if ftp_creds.ok_pressed:
356
+ try:
357
+ ftp_upload([app_file_json, app_file_version], server, workdir, login, password)
358
+ except Exception as error:
359
+ q2Mess(f"Error while uploading: {error}")
326
360
 
327
361
  def export_app(self, file="", app_json=None):
328
362
  filetype = "JSON(*.json)"
@@ -924,7 +924,7 @@ class Q2RadApp(Q2App):
924
924
  if self.frozen:
925
925
  return
926
926
 
927
- if not os.path.isdir(self.q2market_path) and self.app_url and self.app_version or force_update:
927
+ if not os.path.isdir(self.q2market_path) and self.app_url or force_update:
928
928
  try:
929
929
  market_version = read_url(self.app_url + ".version").decode("utf-8") # noqa F405
930
930
  except Exception as e: # noqa F841
@@ -170,7 +170,7 @@ def rollback(q2_db=None):
170
170
 
171
171
 
172
172
  def today():
173
- return datetime.date.today()
173
+ return str(datetime.date.today())
174
174
 
175
175
 
176
176
  def ensure_empty_pk(table="", row={}, q2_db=None):
@@ -212,12 +212,15 @@ def last_day_of_month(date):
212
212
 
213
213
  def ffinder(module_name="module", function_name="fname"):
214
214
  from q2rad.q2rad import run_module
215
+
215
216
  glo = {}
216
217
  glo.update(globals())
217
- run_module(module_name, import_only=True, _globals = glo)
218
+ run_module(module_name, import_only=True, _globals=glo)
218
219
  if function_name in glo:
219
220
  return glo[function_name]
220
221
  else:
222
+
221
223
  def empty_function(*args, **kwargs):
222
224
  pass
223
- return empty_function
225
+
226
+ return empty_function
@@ -27,7 +27,7 @@ from q2gui.q2model import Q2Model
27
27
  from q2gui.q2dialogs import q2ask
28
28
  from q2gui.q2model import Q2CursorModel
29
29
  from q2gui import q2app
30
- from q2gui.q2dialogs import q2working, q2Mess
30
+ from q2gui.q2dialogs import q2working, q2Mess, q2wait
31
31
  from q2gui.q2app import Q2Actions
32
32
  from q2gui.q2app import Q2Controls
33
33
  from q2gui.q2utils import int_
@@ -37,6 +37,9 @@ from logging.handlers import TimedRotatingFileHandler
37
37
 
38
38
  import gettext
39
39
 
40
+ import math
41
+ from ftplib import FTP
42
+
40
43
 
41
44
  _ = gettext.gettext
42
45
 
@@ -361,7 +364,11 @@ def q2choice(records=[], title="Make your choice", column_title=["Column"]):
361
364
 
362
365
  def choice_table():
363
366
  return q2choice(
364
- [{"table": x} for x in q2app.q2_app.db_data.db_schema.get_schema_tables() if not x.startswith("log_")],
367
+ [
368
+ {"table": x}
369
+ for x in q2app.q2_app.db_data.db_schema.get_schema_tables()
370
+ if not x.startswith("log_")
371
+ ],
365
372
  title="Select table",
366
373
  column_title="Table",
367
374
  )
@@ -531,8 +538,17 @@ class auto_filter:
531
538
  col["control"] = "line"
532
539
  col = Q2Controls.validate(col)
533
540
  self.filter_columns.append(cu.r.column)
534
-
535
- if col["datatype"] in ["date"] or (col.get("num") and col.get("to_form", "") == ""):
541
+ if col["datatype"] in ["date"] or (
542
+ col.get("num")
543
+ and col.get("to_form", "") == ""
544
+ and col.get("control", "")
545
+ not in (
546
+ "radio",
547
+ "vradio",
548
+ "list",
549
+ "combo",
550
+ )
551
+ ):
536
552
  self.mem.add_control("/h", cu.r.label, check=1)
537
553
  col["label"] = "from"
538
554
  co = col["column"]
@@ -543,6 +559,8 @@ class auto_filter:
543
559
  self.mem.add_control(**col)
544
560
  self.mem.add_control("/s")
545
561
  self.mem.add_control("/")
562
+ # elif col.get("control", "") == "check":
563
+ # pass
546
564
  else:
547
565
  col["label"] = cu.r.label
548
566
  col["check"] = 1
@@ -554,52 +572,28 @@ class auto_filter:
554
572
  def valid(self):
555
573
  where = []
556
574
  for x in self.filter_columns:
557
- where.append(self.prepare_where(x))
575
+ where.append(self.mem.prepare_where(x))
558
576
  where_string = " and ".join([x for x in where if x])
559
577
  q2app.q2_app.run_form(self.form_name, where=where_string)
560
578
  return False
561
579
 
562
- def prepare_where(self, column=None, control1=None, control2=None):
563
- mem_widgets = self.mem.widgets().keys()
564
- if control1 is None:
565
- if column in mem_widgets:
566
- control1 = column
567
- elif column + "____1" in mem_widgets:
568
- control1 = column + "____1"
569
- if control1 not in mem_widgets:
570
- return ""
571
-
572
- if not self.mem.w.__getattr__(control1).is_checked():
573
- return ""
574
-
575
- date_control = self.mem.controls.c.__getattr__(control1)["datatype"] == "date"
576
- num_control = self.mem.controls.c.__getattr__(control1).get("num")
577
- control1_value = self.mem.s.__getattr__(control1)
578
- if control2 is None:
579
- if control1.endswith("____1"):
580
- control2 = control1[:-5] + "____2"
581
- control2_value = self.mem.s.__getattr__(control2)
582
- else:
583
- control2_value = None
584
- if date_control:
585
- if control1_value == "0000-00-00":
586
- control1_value = ""
587
- if control2_value == "0000-00-00":
588
- control2_value = ""
589
- elif num_control:
590
- control1_value = num(control1_value)
591
- if control2_value:
592
- control2_value = num(control2_value)
593
-
594
- if (control2_value is None) or control1_value == control2_value:
595
- if date_control or num_control:
596
- return f"{column} = '{control1_value}'"
597
- else:
598
- return f"{column} like '%{control1_value}%'"
599
- elif (control1_value and not control2_value) or (control2_value and control1_value > control2_value):
600
- return f"{column} >= '{control1_value}'"
601
- elif not control1_value and control2_value:
602
- return f"{column} <= '{control2_value}'"
603
- elif control1_value and control2_value:
604
- return f"{column} >= '{control1_value}' and {column}<='{control2_value}'"
605
- return ""
580
+
581
+ def ftp_upload(files=[], server="", workdir="", login="", password=""):
582
+ chunks = sum([math.ceil(os.path.getsize(x) / 1000) for x in files])
583
+ w = q2wait(chunks)
584
+ connection = FTP(server)
585
+ connection.login(login, password)
586
+ connection.cwd(workdir)
587
+
588
+ def send_call_back(w=w):
589
+ def realDo(chunk):
590
+ w.step()
591
+
592
+ return realDo
593
+
594
+ for x in files:
595
+ localfile = open(x, "rb")
596
+ connection.storbinary(f"STOR {os.path.basename(x)}", localfile, 1024, send_call_back())
597
+ localfile.close()
598
+ connection.quit()
599
+ w.close()
@@ -0,0 +1 @@
1
+ __version__ = "0.1.233"
@@ -1 +0,0 @@
1
- __version__ = "0.1.231"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes