コード例 #1
0
ファイル: views.py プロジェクト: fredwilliam/PMO
def delete_resources(req, pk):
    resource = get_object_or_404(Resource, pk=pk)
    resource.delete()

    transaction.commit()
    id = int(pk)
    return message(req, "A resource %d deleted" % (id), link="/resources")
コード例 #2
0
def delete(request, html_cache_id):
    """Delete record"""

    data, code, valid = validator.delete(request)

    if valid:
        if settings.ENV == 'production':
            try:
                data, code = resource.delete(request, html_cache_id)
            except:
                return {'code': 'html_cache/delete/fail'}, 404
        else:
            data, code = resource.delete(request, html_cache_id)

    return data, code
コード例 #3
0
def delete(request, tag_id):
    """Delete record"""

    data, code, valid = validator.delete(request)

    if valid:
        if settings.ENV == "production":
            try:
                data, code = resource.delete(request, tag_id)
            except:
                return {"code": "tag/delete/fail"}, 404
        else:
            data, code = resource.delete(request, tag_id)

    return data, code
コード例 #4
0
ファイル: views.py プロジェクト: fredwilliam/PMO
    def post(req):
        # delete notification if a delete button was pressed.
        if req.POST.get("delete", ""):
            pk = resource.pk
            resource.delete()

            transaction.commit()
            return message(req, "Resource %d deleted" % (pk), link="/resources")
        else:
            # check the form for errors
            notice_errors = check_resource_form(req)

            # if any fields were missing, abort.
            missing = notice_errors["missing"]
            exists = notice_errors["exists"]

            if missing:
                transaction.rollback()
                return message(req, "Missing Field(s): %s" % comma(missing), link="/resources/add")

            try:
                # create the resource object from the form
                cat = ResourceCategory.objects.get(pk=req.POST.get("category", ""))
                resource.category = cat

                status = Status.objects.get(pk=req.POST.get("status", ""))
                resource.status = status

                pk = req.POST.get("facility", "")
                if pk != "":
                    facility = Facility.objects.get(pk=req.POST.get("facility", ""))
                    resource.facility = facility
                else:
                    resource.facility = None

                resource.name = req.POST.get("name", "")
                resource.code = req.POST.get("code", "")

                # save the changes to the db
                resource.save()
                transaction.commit()

                # full-page notification
                return message(req, "A resource %s updated" % (resource.pk), link="/resources")

            except Exception, err:
                transaction.rollback()
                raise
コード例 #5
0
ファイル: main.py プロジェクト: HorizonTechnologies/Zbot
def _message_actions():
    """
    /slack/message_actions end point to receive HTTP POST Requests from Slack
    
    After Analysing the type of payload received whether a button click,
    dialogue,
    interactive message,
    dialogue submission repective response will be sent back to
    the user provoked the action
    """

    message_action = json.loads(request.form["payload"])

    user_id = message_action["user"]["id"]
    channel_id = message_action['channel']['id']

    if message_action["type"] == "interactive_message":

        # Add the message_ts to the user's order info
        for actions in message_action['actions']:
            if actions['name'] == "workform":

                # Show the ordering dialog to the user
                slack_client.api_call("chat.postMessage",
                                      channel=channel_id,
                                      icon_url=icon,
                                      text=f"Hey <@{user_id}> Let's Start",
                                      attachments=[])
                slack_client.api_call("chat.postMessage",
                                      channel=channel_id,
                                      text=chainmessages[0],
                                      icon_url=icon,
                                      attachments=[])

    elif message_action["type"] == "block_actions":
        action = message_action.get('actions')

        actiontype = action[0]['type']

        if actiontype == 'channels_select':
            channel = action[0]['selected_channel']

        if actiontype == 'button':
            text = action[0]['text']['text']
            value = action[0]['value']
            if text == "Delete":
                if value.startswith('resource'):
                    del_id = value[8:]
                    val = resourcemodule.delete(del_id)

                    slack_client.api_call("chat.postMessage",
                                          channel=channel_id,
                                          text="",
                                          icon_url=icon,
                                          attachments=[{
                                              "text":
                                              val,
                                              "color":
                                              "#3AA3E3",
                                              "attachment_type":
                                              "default",
                                          }])
                if value.startswith('timer'):
                    del_id = value[5:]
                    val = remind.deletereminder(del_id)
                    slack_client.api_call("chat.postMessage",
                                          channel=channel_id,
                                          text="",
                                          icon_url=icon,
                                          attachments=[{
                                              "text":
                                              val,
                                              "color":
                                              "#3AA3E3",
                                              "attachment_type":
                                              "default",
                                          }])

            if value == 'resourceadd':
                open_dialog = slack_client.api_call(
                    "dialog.open",
                    trigger_id=message_action["trigger_id"],
                    dialog={
                        "title":
                        "Add a resource",
                        "submit_label":
                        "Submit",
                        "callback_id":
                        'resourceadd',
                        "elements": [
                            {
                                "type": "text",
                                "label": "name",
                                "name": "resource"
                            },
                            {
                                "type": "text",
                                "label": "links/description",
                                "name": "link"
                            },
                        ]
                    })

            if text == 'Update':
                if value.startswith('resource'):
                    del_id = value[8:]
                    open_dialog = slack_client.api_call(
                        "dialog.open",
                        trigger_id=message_action["trigger_id"],
                        dialog={
                            "title":
                            "Daily Syncup",
                            "submit_label":
                            "Submit",
                            "callback_id":
                            'update' + del_id,
                            "elements": [
                                {
                                    "type": "text",
                                    "label": "name",
                                    "name": "resource"
                                },
                                {
                                    "type": "text",
                                    "label": "links/description",
                                    "name": "link"
                                },
                            ]
                        })

                    update_id = value[8:]

        if actiontype == 'static_select':
            option = action[0]['selected_option']['value']

            if option == 'dayoff':

                val = progress.dayoff(user_id)
                slack_client.api_call("chat.postMessage",
                                      channel=channel_id,
                                      icon_url=icon,
                                      text=val,
                                      attachments=[])
                blocks.divider(slack_client, channel_id)
            if option == "resources":

                resourcemodule.showresources(slack_client, channel_id)
                blocks.divider(slack_client, channel_id)
            if option == 'report':

                slack_client.api_call(
                    "chat.postMessage",
                    channel=channel_id,
                    icon_url=icon,
                    text=f":thumbsup: <@{user_id}> Please let us \
know your progress",
                    attachments=[])
                slack_client.api_call("chat.postMessage",
                                      channel=channel_id,
                                      icon_url=icon,
                                      text=chainmessages[0],
                                      attachments=[])

            if option == 'joke':

                url = "https://official-joke-api.appspot.com/random_joke"

                try:
                    data = requests.get(url=url)
                    data = data.content
                    data = json.loads(data)

                    slack_client.api_call(
                        "chat.postMessage",
                        channel=channel_id,
                        text=data['setup'] + " " + data['punchline'],
                        icon_url=icon,
                    )
                except:
                    slack_client.api_call(
                        "chat.postMessage",
                        channel=channel_id,
                        text="Failed to load",
                        icon_url=icon,
                    )
                blocks.divider(slack_client, channel_id)
            if option == 'show':

                progress.report(user_id, channel_id, slack_client)
                blocks.divider(slack_client, channel_id)
            return make_response("", 200)

    elif message_action["type"] == "dialog_submission":

        formdata = message_action['submission']

        callbackid = message_action['callback_id']

        if callbackid.startswith('updateresource'):
            update_id = callbackid[14:]
            resourcemodule.update(update_id, formdata['resource'],
                                  formdata['link'])
            val = 'Under Construction'
        elif callbackid.startswith('resourceadd'):
            formdata = message_action['submission']
            val = resourcemodule.insert(formdata['resource'], formdata['link'],
                                        user_id)

        slack_client.api_call("chat.postMessage",
                              channel=channel_id,
                              icon_url=icon,
                              text="",
                              attachments=[{
                                  "text": val,
                                  "color": "#3AA3E3",
                                  "attachment_type": "default",
                              }])

    return make_response("", 200)