Skip to content

Commit

Permalink
v2-Beta15 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed May 2, 2024
1 parent b2afe54 commit 6ee60a9
Show file tree
Hide file tree
Showing 42 changed files with 2,668 additions and 10,279 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright 2022 Level Up Marketing & Development Services
Copyright 2024 Level Up Marketing & Development Services

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ It supports RTL layout and dark mode out of the box.

⚠️ **v2 is still in BETA stage** ⚠️

![v2 Beta15](https://img.shields.io/badge/v2_Beta15-2024/05/02-green?style=plastic)

**Apologies in advance for any problem or bug you face with this module.**
**Please report any problem or bug you face so it can be fixed.**

---

<p align="center">
Expand All @@ -28,10 +33,11 @@ It supports RTL layout and dark mode out of the box.
### Special Thanks
**A simple display of gratitude and appreciation to those who provided helped and kind support.**
#### Version 2
- [MohsinAli](https://github.com/mohsinalimat) (Testing - Debugging - Bug Fixing)
- [Robert C](https://github.com/robert1112) (Testing - Debugging)
- [![MohsinAli](https://img.shields.io/badge/MohsinAli-Debug_%7C_Test_%7C_Fix-red?style=plastic)](https://github.com/mohsinalimat)
- [![Robert C](https://img.shields.io/badge/Robert_C-Debug_%7C_Test-blue?style=plastic)](https://github.com/robert1112)
- [![NirajRegmi](https://img.shields.io/badge/NirajRegmi-Debug_%7C_Test-orange?style=plastic)](https://github.com/NirajRegmi)
#### Version 1
- [CA. B.C.Chechani](https://github.com/chechani) (Testing - Debugging)
- [![CA. B.C.Chechani](https://img.shields.io/badge/CA._B.C.Chechani-Debug_%7C_Test-green?style=plastic)](https://github.com/chechani)

---

Expand Down Expand Up @@ -121,7 +127,7 @@ bench build --app frappe_better_attach_control
bench --site [sitename] migrate
```

6. (Optional) Restart bench
6. (Optional) Restart bench to clear cache

```
bench restart
Expand All @@ -146,7 +152,7 @@ bench --site [sitename] uninstall-app frappe_better_attach_control
bench remove-app frappe_better_attach_control
```

4. (Optional) Restart bench
4. (Optional) Restart bench to clear cache

```
bench restart
Expand Down Expand Up @@ -189,11 +195,9 @@ You can't modify the original fields of a doctype, so create a new field or clon
### Available JavaScript Methods
| Method | Description |
| :--- | :--- |
| **enable_reload()** | Allow reloading attachments and show the reload button (🔶Frappe >= v13.0.0). |
| **disable_reload()** | Deny reloading attachments and hide reload button (🔶Frappe >= v13.0.0). |
| **enable_remove()** | Allow removing and clearing attachments and show the clear and remove buttons. |
| **disable_remove()** | Deny removing and clearing attachments and hide the clear and remove buttons. |
| **set_options(JSON)** | Set or change the plugin current options. |
| **toggle_reload(allow: Boolean !Optional)** | Allow/Deny reloading attachments and toggle the reload button (🔶Frappe >= v13.0.0). |
| **toggle_remove(allow: Boolean !Optional)** | Allow/Deny removing and clearing attachments and toggle the clear and remove buttons. |
| **set_options(options: JSON Object)** | Set or change the plugin options. |

---

Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2023
# Frappe Better Attach Control © 2024
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand Down
3 changes: 1 addition & 2 deletions frappe_better_attach_control/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Frappe Better Attach Control © 2023
# Frappe Better Attach Control © 2024
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file


from .attachment import *
from .field import *
from .file_manager import *
25 changes: 10 additions & 15 deletions frappe_better_attach_control/api/attachment.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# Frappe Better Attach Control © 2023
# Frappe Better Attach Control © 2024
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file


import frappe
from frappe import (
_,
is_whitelisted,
__version__ as frappe_version
)
from frappe import _, is_whitelisted
from frappe.utils import cint

from .common import (
is_version_gt,
parse_json_if_valid,
send_console_log
)
Expand All @@ -36,12 +33,10 @@

@frappe.whitelist(allow_guest=True)
def upload_file():
version = int(frappe_version.split('.')[0])

user = None
ignore_permissions = False

if version > 12:
if is_version_gt(12):
if frappe.session.user == "Guest":
if frappe.get_system_settings("allow_guests_to_upload_files"):
ignore_permissions = True
Expand All @@ -63,19 +58,19 @@ def upload_file():
optimize = False
content = None

if version > 13:
if is_version_gt(13):
filename = frappe.form_dict.file_name
optimize = frappe.form_dict.optimize

if version > 12:
if is_version_gt(12):
import mimetypes

if "file" in files:
file = files["file"]
content = file.stream.read()
filename = file.filename

if version > 13:
if is_version_gt(13):
content_type = mimetypes.guess_type(filename)[0]
if optimize and content_type.startswith("image/"):
args = {"content": content, "content_type": content_type}
Expand All @@ -90,15 +85,15 @@ def upload_file():
frappe.local.uploaded_file = content
frappe.local.uploaded_filename = filename

if version > 13:
if is_version_gt(13):
if not file_url and content is not None and (
frappe.session.user == "Guest" or (user and not user.has_desk_access())
):
filetype = mimetypes.guess_type(filename)[0]
if filetype not in _ALLOWED_MIMETYPES_:
frappe.throw(_("You can only upload JPG, PNG, PDF, TXT or Microsoft documents."))

elif version > 12:
elif is_version_gt(12):
if not file_url and frappe.session.user == "Guest" or (user and not user.has_desk_access()):
filetype = mimetypes.guess_type(filename)[0]

Expand All @@ -118,7 +113,7 @@ def upload_file():
"is_private": cint(is_private),
"content": content,
})
if version > 12:
if is_version_gt(12):
ret.save(ignore_permissions=ignore_permissions)
else:
ret.save()
Expand Down
22 changes: 17 additions & 5 deletions frappe_better_attach_control/api/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2024
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand All @@ -7,12 +7,26 @@
import json

import frappe
from frappe import _, _dict
from frappe import __version__, _, _dict


__frappe_base_ver__ = int(__version__.split(".")[0])


def is_version_gt(num: int):
return __frappe_base_ver__ > num


def is_version_lt(num: int):
return __frappe_base_ver__ < num


def error(msg, throw=True):
title = "Better Attach Control"
frappe.log_error(title, msg)
if is_version_lt(14):
frappe.log_error(text, title)
else:
frappe.log_error(title, text)
if throw:
frappe.throw(msg, title=title)

Expand Down Expand Up @@ -54,7 +68,6 @@ def to_json_if_valid(data, default=None):

if default is None:
default = data

try:
return json.dumps(data)
except Exception:
Expand All @@ -67,7 +80,6 @@ def parse_json_if_valid(data, default=None):

if default is None:
default = data

try:
return json.loads(data)
except Exception:
Expand Down
76 changes: 37 additions & 39 deletions frappe_better_attach_control/api/field.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2023
# Frappe Better Attach Control © 2024
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand All @@ -10,7 +10,7 @@


@frappe.whitelist(methods=["POST"], allow_guest=True)
def get_options(doctype, name):
def get_options(doctype, name, webform):
if not doctype or not isinstance(doctype, str):
send_console_log({
"message": "Empty or invalid field doctype",
Expand All @@ -26,45 +26,43 @@ def get_options(doctype, name):
return ""

fieldtypes = ["in", ["Attach", "Attach Image"]]
options = frappe.db.get_value(
"DocField",
{
"fieldname": name,
"parent": doctype,
"parenttype": "DocType",
"parentfield": "fields",
"fieldtype": fieldtypes
},
"options"
)
options = None

if options and isinstance(options, str):
return options

options = frappe.db.get_value(
"Custom Field",
{
"fieldname": name,
"dt": doctype,
"fieldtype": fieldtypes
},
"options"
)

if options and isinstance(options, str):
return options
if webform:
options = frappe.db.get_value(
"Web Form Field",
{
"fieldname": name,
"parent": doctype,
"parenttype": "Web Form",
"parentfield": "web_form_fields",
"fieldtype": fieldtypes
},
"options"
)

options = frappe.db.get_value(
"Web Form Field",
{
"fieldname": name,
"parent": doctype,
"parenttype": "Web Form",
"parentfield": "web_form_fields",
"fieldtype": fieldtypes
},
"options"
)
else:
options = frappe.db.get_value(
"DocField",
{
"fieldname": name,
"parent": doctype,
"parenttype": "DocType",
"parentfield": "fields",
"fieldtype": fieldtypes
},
"options"
)
if not options or not isinstance(options, str):
options = frappe.db.get_value(
"Custom Field",
{
"fieldname": name,
"dt": doctype,
"fieldtype": fieldtypes
},
"options"
)

if options and isinstance(options, str):
return options
Expand Down
Loading

0 comments on commit 6ee60a9

Please sign in to comment.