예제 #1
0
def manage_skills_post(request):
    form = ValidateSkills(request)
    if form.is_valid():
        form.save()
        MessagesSystem(request).append_skills(COMMANDS_SUCCESS_MESSAGE)
    else:
        MessagesSystem(request).append_skills(form.errors)
예제 #2
0
    def test_recaptcha_will_give_message_to_site_on_failure(self):
        returns = self.make_request(b'{"success": true, "score": 0.3}')
        request = returns.get("request")

        message = MessagesSystem(request).pop_contact()
        self.assertEqual(message, [
            "It looks like you're a bot. If not, contact me the other way. url"
        ])
예제 #3
0
    def test_can_handle_missing_keys(self):
        message_system = MessagesSystem(self.request)
        item_message = message_system.pop_items()
        plugin_message = message_system.pop_plugins()
        skills_message = message_system.pop_skills()

        self.assertEqual(item_message, [])
        self.assertEqual(plugin_message, [])
        self.assertEqual(skills_message, [])
예제 #4
0
 def test_append_message_dont_override_older_messages(self):
     self.request.session.update({"plugins_messages": ["test01"]})
     message_system = MessagesSystem(self.request)
     message_system._append_message("plugins_messages", "test")
     self.assertEqual(self.request.session.get("plugins_messages"),
                      ["test01", "test"])
     message_system._append_message("plugins_messages", ["other_test"])
     self.assertEqual(self.request.session.get("plugins_messages"),
                      ["test01", "test", "other_test"])
예제 #5
0
def spells_view(request):
    if not SelectedPlugins(request).exist():
        MessagesSystem(request).append_plugin(NO_PLUGIN_SELECTED_ERROR_MESSAGE)
        return redirect("tec:plugins")

    if request.method == "POST":
        spells = convert_value_post(request)
        ChosenSpells(request).set(spells)
        Commands(request).set_spells(spells)
        if spells:
            message = COMMANDS_SUCCESS_MESSAGE
        else:
            message = SPELLS_COMMANDS_POST_EMPTY_MESSAGE
        return JsonResponse({"message": message})

    message = MessagesSystem(request).pop_spells()
    return render(request, "the_elder_commands/spells.html", {
        "active": "spells",
        "messages": message
    })
예제 #6
0
def send_contact_email(request):
    messages = MessagesSystem(request)
    try:
        email_message = f"Email: {request.POST.get('email')} \nMessage: {request.POST.get('message')}"
        send_mail(request.POST.get("subject"), email_message, "",
                  ["*****@*****.**"])
        messages.append_contact("Message was sent!")
    except SMTPException:
        messages.append_contact(
            "Something went wrong! \nPlease try a different method of contact."
        )
예제 #7
0
def contact(request):
    messages = MessagesSystem(request)
    if request.method == "POST":

        send_contact_email(request)

        return redirect("main_page:contact")

    return render(
        request, "main_page/contact.html", {
            "messages": messages.pop_contact(),
            "site_key": settings.RECAPTCHA_SITE_KEY
        })
예제 #8
0
def other_view(request):
    if not SelectedPlugins(request).exist():
        MessagesSystem(request).append_plugin(NO_PLUGIN_SELECTED_ERROR_MESSAGE)
        return redirect("tec:plugins")

    if request.method == "POST":
        variety = convert_value_post(request)
        ChosenOther(request).set(variety)
        Commands(request).set_other(variety)
        if variety:
            message = COMMANDS_SUCCESS_MESSAGE
        else:
            message = OTHER_COMMANDS_POST_EMTPY_MESSAGE
        return JsonResponse({"message": message})

    messages = MessagesSystem(request).pop_other()
    chosen = ChosenOther(request).get()
    return render(request, "the_elder_commands/other.html", {
        "active": "other",
        "chosen": chosen,
        "messages": messages
    })
예제 #9
0
def skills_view(request):
    if request.method == "POST":
        if "race" in request.POST:
            manage_race_post(request)
        else:
            manage_skills_post(request)
        return redirect("tec:skills")

    message = MessagesSystem(request).pop_skills()
    service = SkillsService(request)
    Commands(request).set_skills(service.commands)
    return render(request, "the_elder_commands/skills.html", {
        "service": service,
        "messages": message,
        "active": "skills"
    })
예제 #10
0
 def wrapper(request):
     recaptcha_data = {
         "response": request.POST.get("g-recaptcha-response"),
         "secret": settings.RECAPTCHA_SECRET_KEY
     }
     recaptcha_response = recaptcha_request.post(
         "https://www.google.com/recaptcha/api/siteverify",
         recaptcha_data)
     result = json.loads(recaptcha_response.content)
     if result.get("success") and result.get("score") >= 0.4:
         func(request)
     else:
         messages = MessagesSystem(request)
         url = HttpRequest.build_absolute_uri(
             request, reverse('main_page:about_me'))
         getattr(
             messages, "append_" + site
         )("It looks like you're a bot. If not, contact me the other way. "
           f"{url}")
예제 #11
0
def plugins_view(request):
    if request.method == "POST":
        if "add_plugin" in request.POST:
            manage_add_plugin_post(request)
            return redirect("tec:plugins")
        elif "unselect" in request.POST:
            manage_unselect_post(request)
            return redirect("tec:plugins")
        if "selected_plugins" in request.POST:
            manage_selected_post(request)
            return JsonResponse({})

    service = PluginsService(request)
    messages = MessagesSystem(request).pop_plugins()
    zedit_data = get_zedit_data()
    return render(
        request, "the_elder_commands/plugins.html", {
            "active": "plugins",
            "service": service,
            "messages": messages,
            "zedit": zedit_data,
            "site_key": settings.RECAPTCHA_SITE_KEY
        })
예제 #12
0
 def test_append_plugin_message(self):
     message_system = MessagesSystem(self.request)
     message_system.append_plugin("test")
     self.assertEqual(self.request.session.get("plugins_messages"),
                      ["test"])
예제 #13
0
def manage_selected_post(request):
    form = SelectedPluginsForm(request)
    if form.is_valid():
        MessagesSystem(request).append_plugin(SELECTED_PLUGINS_SUCCESS)
    else:
        MessagesSystem(request).append_plugin(form.errors)
예제 #14
0
def manage_add_plugin_post(request):
    form = AddPluginsForm(request)
    if form.is_valid():
        MessagesSystem(request).append_plugin(ADD_PLUGIN_SUCCESS_MESSAGE)
    else:
        MessagesSystem(request).append_plugin(form.errors)
예제 #15
0
 def test_append_message(self):
     message_system = MessagesSystem(self.request)
     message_system._append_message("items_messages", "test")
     self.assertEqual(self.request.session.get("items_messages"), ["test"])
예제 #16
0
 def test_append_contact_messages(self):
     message_system = MessagesSystem(self.request)
     message_system.append_contact("test")
     self.assertEqual(self.request.session.get("contact_messages"),
                      ["test"])
예제 #17
0
 def test_pop_other_messages(self):
     self.request.session.update({"other_messages": ["test"]})
     messages_system = MessagesSystem(self.request)
     message = messages_system.pop_other()
     self.assertEqual(self.request.session.get("other_messages"), [])
     self.assertEqual(message, ["test"])
예제 #18
0
 def test_append_message_can_handle_list(self):
     message_system = MessagesSystem(self.request)
     message_system._append_message("plugins_messages", ["test_02"])
     self.assertEqual(self.request.session.get("plugins_messages"),
                      ["test_02"])
예제 #19
0
 def test_append_message_can_handle_nested_list(self):
     message_system = MessagesSystem(self.request)
     message_system._append_message("items_messages",
                                    [[["test"]], "test02"])
     self.assertEqual(self.request.session.get("items_messages"),
                      ["test", "test02"])