How do I make dropdown roles in pycord? - pycord

As many may know, discord.py has stopped being maintained. As a result of this, I switched over to Pycord.
My question is:
How do I make the dropdown menu do roles?
I looked at the example on the Github Example file for making dropdown menus in Pycord, and I attempted to make a dropdown menu (successfully). However, this only sends a message when an option is selected from the menu. I want to use this menu for adding and removing roles. How would I go about doing that?

class Select(discord.ui.Select):
def __init__(self):
options = [
discord.SelectOption(label="role name", description="Add the Role_Name role"), #These are the labels
discord.SelectOption(label="role name 2", description="Add role name role."),#^
]
super().__init__(placeholder="Waiting for selection...", max_values=1, min_values=1, options=options)#what will be written waiting for a choise
async def callback(self, interaction: discord.Interaction):
if self.values[0] == 'role name': #'role name'must be the same as the label u want the action to happen. Ex: if label name == hi, well uchange role name to hi here
role = interaction.guild.get_role(ROLE_ID_HERE)#add ur role ID here
await interaction.user.add_roles(role)#Basically if the interaction happen, itll add the role role^ to the user
elif self.values[0] == 'role name 2':
rolee = interaction.guild.get_role(ROLE_ID_HERE)#same as up
await interaction.user.add_roles(rolee)
class SelectView(discord.ui.View):
def __init__(self, *, timeout):
super().__init__(timeout=timeout)
self.add_item(Select())
#client.command()
async def droproles(ctx):
select = SelectView(timeout=None)
await ctx.send("Choose ur role here", view=select)
This is the code. If there is an error tell me, i didnt test it, but it should work. If u dont understand something, tell me. U need to understand to be able to re do it sometime

Related

Make cascading list mandatory on JIRA based on another cascading list

I think this can be achieved with behaviors but I am struggling with the code.
I am trying to make "Cascading list 2" mandatory when an option is picked from "Cascading list 1"
Eg:
On "Cascading list 1" if a user picks option "A" then they have to also fill out "Cascading list 2"
If they pick option "B" on "Cascading list 1" then "Cascading list 2" is not required.
This is some of the code I was playing around with:
def fieldA = getFieldByName('BI Reporting & Analytics Request Categories') //this is cascading list 1
def fieldC = getFieldByName('Reporting') //this is the cascading list 2
def fieldAValuesThatTriggerFieldCRequired = ['Reporting'] //this is the option choosen in cascading list 1
def valueA = fieldA.value
def fieldCIsRequired = valueA in fieldAValuesThatTriggerFieldCRequired
fieldC.setRequired(fieldCIsRequired)
Any assistance is appreciated.
Image on JIRA
Thanks.
If my understanding is correct, they are not cascading field.
The request here is that when field A has particular value saying 'aaa', then field B becomes required (mandatory).
This is a typical use case for Jira plugin Adaptavist ScriptRunner behaviours.
But Behaviours is only available for Jira server or data center version. It is not for Jira cloud.
If your Jira is server version, you can refer to below steps and scripts:
go to behaviours settings, if you don't have a behaviour item for
your workflow, please create it. If behaviour has been created,
click into action/edit.
choose the field A and add it.
click Add server-side script, you will see the black inline edit section.
add below code.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
#BaseScript FieldBehaviours fieldBehaviours
FormField field1 = getFieldById(getFieldChanged()) // we need to capture the change in field 1.
FormField pmAuthor = getFieldByName("field2")
if (field1.getValue()) { // to check if field1 has value as the action on field could be a deleting value operation.
if (field2.getValue()=="A") {
field2.setRequired(true)
} else {
field2.setRequired(false)
}
} else { // if the value was deleted, then remove the requirement.
field2.setRequired(false)
}

Shiny disable selectinput but the users can see the available options, but I cannot select them

Good morning,
I have a selectinput with several options. I need that this input is disabled, but the user can see the available options, but I cannot select them.
Thank you
I mean, I have a selectinput in shiny with a list of questions from 1 to 100. How do I make the person see the questions, but cannot select any, like disabling them. It would be disable in Selectinput, but the person can see the available options.
selectInput(inputId = "question", label = "questions", choices = c("question1", "question2", "question3", "question4", "question100" ) ),
Thank you
Using the package shinyjs(), you can use the disable function although this doesn't allow you to see the dropdown choices. So... only half way answers your question, not sure if it is possible to see the choices.
library(shiny)
library(shinyjs)
#####/UI/####
header <- dashboardHeader()
sidebar <- dashboardSidebar()
body <- dashboardBody(
useShinyjs(),
selectInput(inputId = "question", label = "questions",
choices = c("question1", "question2", "question3", "question4", "question100" )
)
)
ui <- dashboardPage(header, sidebar, body)
#####/SERVER/####
server <- function(session, input, output) {
shinyjs::disable("question")
}
shinyApp(ui, server)
Depending on what you are trying to accomplish, there may be some other ways to get the same affect (i.e. not having the dropdown start a reactive unless another condition is met, etc.)

How to change a modx revolution users class_key when newly created VIA the manager?

I'm trying to change a new user's class_key value when they are created VIA the manager.
In a plugin that fires on the onUserSave event:
<?php
$uid = $_POST['id'];
$sql = "update modx_users set `class_key` = 'extUser' where id = $uid;";
$modx->log(modX::LOG_LEVEL_ERROR, 'query = ' . $sql);
$query = $modx->query($sql);
return;
Which works when you EDIT an EXISTING user, but does not work if you try to CREATE a NEW user.
Any thoughts on how to do this?
None of the system events look like they fire when a new user is created.
Looking at the user/create processor, you would need to listen for OnUserFormSave which is fired after saving the new user.
I haven't tested this, but in your plugin you have access to $modx->event. Log the output of this for the OnUserFormSave event, hopefully it should include a 'data' property containing the new user object. The object should contain the new user id.
Let me know how that goes!
Update
I've tested this out. As expected, you have access to the new user id, user object (and much more) in the $modx->event object:
if ($modx->event->name == 'OnUserFormSave') {
// id of user you've just created
$newUserId = $modx->event->name->params->id;
// full modUser object is available here
$newUserObj = $modx->event->name->params->user;
}
In plugin with OnUserSave event:
$scriptProperties['user']->set('class_key','extUser');
That's it nothing more.
You cannot call
$scriptProperties['user']->save();
in OnUserSave as other examples elsewhere have shown.

ImageField not getting deleted when save button is pressed : Django-admin

i have the following files
models.py
Class Trip(models.Model)
featured = models.BooleanField(default=False, help_text='Tags this trip as a featured trip.')
top_ten_trip = models.BooleanField(default=False)
header_image = models.ImageField(help_text='This is the image shown when viewing the details for this trip.', upload_to='images/', blank=True, null=True)
map_image = models.ImageField(help_text='The map image for this trip.', upload_to='images/', blank=True, null=True)
.....
and so on
admin.py
class TripAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'category', 'supplier', 'active', 'featured', 'top_ten_trip',)
search_fields = ('name', 'code',)
list_filter = ('category', 'featured', 'top_ten_trip',)
filter_horizontal = ('countries', 'related_trips',)
The field appear with browse button in admin something like this
Header image: Currently: images/comfort_japan.jpg
Change: Delete this file
Map image: Currently: images/map_japan_.jpg
Change: Delete this file
Now the Problem :-
When i click on Delete this imagefile( images/comfort_japan.jpg ) it get removed for that instant but does not deleted when i press save button on admin.
I want when i click on delete this file and press save it should get deleted.
What mistake i am doing or what am i missing ?
Thanks in advance.
This was intentionally changed in Django 1.3, see
Django Ticket #15224.
You need to implement file deletion yourself. Check related posts:
How do I get Django Admin to delete files when I remove an object from the database/model?
Django admin: Add a "remove file" field for Image- or FileFields
Hi All I solved my problem by using snippet 1633
http://djangosnippets.org/snippets/1633/ .It works pretty fine.

Django Admin Fieldsets

Trying to understand Django Admin a bit better, but I find the Django documentation a bit lacking sometimes (or perhaps my capacity to understand).
I know you can use fieldsets to control the layout of certain admin pages. What I can't seem to grasp is what the fieldset names are.
If I have the following class
class Demo(model.Model):
name = models.CharField(max_length=150)
address = models.CharField(max_length=150)
city = models.CharField(max_length=50)
zip = models.CharField(max_length=15)
and Admin class as the following
class DemoAdmin(admin.ModelAdmin):
list_display = ('name', 'City')
In this, albeit contrived example, what possible fieldsets could I use?
Try this, and you'll soon see how it looks/works.
class DemoAdmin(admin.ModelAdmin):
list_display = ('name', 'city')
fieldsets = (
('Standard info', {
'fields': ('name')
}),
('Address info', {
'fields': ('address', ('city', 'zip'))
}),
)
When you go to the change-page to edit, you'll get one box "standard info" with the name-box. And you'll get another box that says "address info" with the adress field first, and then the city and zip-fields on the same line after.

Resources