Skip to content

Commit

Permalink
chore: run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
janhvipatil committed Apr 8, 2024
1 parent 6132d1d commit 97acc52
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 191 deletions.
24 changes: 12 additions & 12 deletions raven/api/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def get_channel_members(channel_id):
if frappe.get_cached_value("Raven Channel", channel_id, "type") == "Open":
# select all users, if channel member exists, get is_admin
member_query = (
frappe.qb.from_(user)
.join(channel_member, JoinType.left)
.on((user.name == channel_member.user_id) & (channel_member.channel_id == channel_id))
.select(
user.name,
user.full_name,
user.user_image,
user.first_name,
user.type,
channel_member.is_admin,
)
.orderby(channel_member.creation, order=Order.desc)
frappe.qb.from_(user)
.join(channel_member, JoinType.left)
.on((user.name == channel_member.user_id) & (channel_member.channel_id == channel_id))
.select(
user.name,
user.full_name,
user.user_image,
user.first_name,
user.type,
channel_member.is_admin,
)
.orderby(channel_member.creation, order=Order.desc)
)
else:
member_query = (
Expand Down
9 changes: 4 additions & 5 deletions raven/api/raven_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ def retract_vote(poll_id):
# delete all votes by the user for the poll (this takes care of the case where the user has voted for multiple options in the same poll)
user = frappe.session.user
votes = frappe.get_all(
"Raven Poll Vote",
filters={"poll_id": poll_id, "user_id": user},
fields=["name"])
"Raven Poll Vote", filters={"poll_id": poll_id, "user_id": user}, fields=["name"]
)
if not votes:
frappe.throw(_("You have not voted for any option in this poll."))
else:
else:
for vote in votes:
frappe.delete_doc("Raven Poll Vote", vote.name)
frappe.delete_doc("Raven Poll Vote", vote.name)
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,82 @@


class RavenSchedulerEvent(Document):
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from frappe.types import DF
if TYPE_CHECKING:
from frappe.types import DF

bot: DF.Link
channel: DF.Link
content: DF.SmallText
cron_expression: DF.Data | None
disabled: DF.Check
dm: DF.Link | None
event_frequency: DF.Literal["Every Day",
"Every Day of the week", "Date of the month", "Cron"]
event_name: DF.Data
scheduler_event_id: DF.Link | None
send_to: DF.Literal["Channel", "DM"]
# end: auto-generated types
bot: DF.Link
channel: DF.Link
content: DF.SmallText
cron_expression: DF.Data | None
disabled: DF.Check
dm: DF.Link | None
event_frequency: DF.Literal["Every Day", "Every Day of the week", "Date of the month", "Cron"]
event_name: DF.Data
scheduler_event_id: DF.Link | None
send_to: DF.Literal["Channel", "DM"]
# end: auto-generated types

def before_save(self):
'''
1. If the 'scheduler_event_id' is not set, create a Server Script of type 'Scheduler Event' and set the 'scheduler_event_id' to the name of the Server Script.
'''
if not self.scheduler_event_id:
self.scheduler_event_id = self.create_scheduler_event()
else:
server_script = frappe.get_doc(
'Server Script', self.scheduler_event_id)
server_script.cron_format = self.cron_expression
server_script.script = self.get_scheduler_event_script()
server_script.save()
def before_save(self):
"""
1. If the 'scheduler_event_id' is not set, create a Server Script of type 'Scheduler Event' and set the 'scheduler_event_id' to the name of the Server Script.
"""
if not self.scheduler_event_id:
self.scheduler_event_id = self.create_scheduler_event()
else:
server_script = frappe.get_doc("Server Script", self.scheduler_event_id)
server_script.cron_format = self.cron_expression
server_script.script = self.get_scheduler_event_script()
server_script.save()

def on_update(self):
'''
1. If the 'scheduler_event_id' is set, and the 'disabled' field is updated, update the 'disabled' field of the Server Script of type 'Scheduler Event' with the name 'scheduler_event_id'.
'''
if self.scheduler_event_id:
server_script = frappe.get_doc(
'Server Script', self.scheduler_event_id)
server_script.disabled = self.disabled
server_script.save()
def on_update(self):
"""
1. If the 'scheduler_event_id' is set, and the 'disabled' field is updated, update the 'disabled' field of the Server Script of type 'Scheduler Event' with the name 'scheduler_event_id'.
"""
if self.scheduler_event_id:
server_script = frappe.get_doc("Server Script", self.scheduler_event_id)
server_script.disabled = self.disabled
server_script.save()

def on_trash(self):
'''
1. If the 'scheduler_event_id' is set, delete the Server Script of type 'Scheduler Event' with the name 'scheduler_event_id'.
'''
if self.scheduler_event_id:
frappe.delete_doc('Server Script', self.scheduler_event_id)
def on_trash(self):
"""
1. If the 'scheduler_event_id' is set, delete the Server Script of type 'Scheduler Event' with the name 'scheduler_event_id'.
"""
if self.scheduler_event_id:
frappe.delete_doc("Server Script", self.scheduler_event_id)

def create_scheduler_event(self):
'''
Create a Server Script of type 'Scheduler Event' and set the 'scheduler_event_id' to the name of the Server Script.
'''
server_script = frappe.get_doc({
'doctype': 'Server Script',
'script_type': 'Scheduler Event',
'name': self.event_name,
'disabled': 0,
'event_frequency': 'Cron',
'cron_format': self.cron_expression,
'script': self.get_scheduler_event_script()
})
server_script.insert()
return server_script.name
def create_scheduler_event(self):
"""
Create a Server Script of type 'Scheduler Event' and set the 'scheduler_event_id' to the name of the Server Script.
"""
server_script = frappe.get_doc(
{
"doctype": "Server Script",
"script_type": "Scheduler Event",
"name": self.event_name,
"disabled": 0,
"event_frequency": "Cron",
"cron_format": self.cron_expression,
"script": self.get_scheduler_event_script(),
}
)
server_script.insert()
return server_script.name

def get_scheduler_event_script(self):
'''
Get the script for the Scheduler Event
'''
# bot = frappe.get_doc('Raven Bot', self.bot)
# bot.send_message(self.channel, {'text': self.content})
# return code snippet with bot & content as values
message = {'text': self.content}
script = f'''
def get_scheduler_event_script(self):
"""
Get the script for the Scheduler Event
"""
# bot = frappe.get_doc('Raven Bot', self.bot)
# bot.send_message(self.channel, {'text': self.content})
# return code snippet with bot & content as values
message = {"text": self.content}
script = f"""
bot = frappe.get_doc('Raven Bot', '{self.bot}')\n
bot.send_message('{self.channel}', {message})
'''
return script
"""
return script
Loading

0 comments on commit 97acc52

Please sign in to comment.