Passed
Push — master ( 86549a...e89d5b )
by -
01:38
created

mz_index()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032
Metric Value
cc 2
dl 0
loc 6
ccs 4
cts 5
cp 0.8
crap 2.032
rs 9.4285
1 1
from flask import Blueprint, render_template, request, redirect, flash
1 ignored issue
show
Configuration introduced by
The import flask could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2 1
from sqlalchemy.exc import SQLAlchemyError
0 ignored issues
show
Configuration introduced by
The import sqlalchemy.exc could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
3
4 1
from spike.model import db
5 1
from spike.model.value_templates import ValueTemplates
6
7 1
settings = Blueprint('settings', __name__)
8
9
10 1
@settings.route("/mz")
11
def mz_index():
12 1
    mz = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_mz").order_by(ValueTemplates.value).all()
13 1
    if not mz:
14
        return redirect("/settings")
15 1
    return render_template("settings/mz.html", mz=mz)
16
17
18 1
@settings.route("/mz/del", methods=["POST"])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
def mz_del():
20
    dmz = ValueTemplates.query.filter(ValueTemplates.id == request.form["mzid"]).first()
21
    if not dmz:
22
        flash("Nothing found in %s " % (request.form["mzid"]), "error")
23
        return redirect("/settings/mz")
24
25
    db.session.delete(dmz)
26
    try:
27
        db.session.commit()
28
        flash("OK: deleted %s " % dmz.value, "success")
29
    except SQLAlchemyError:
30
        flash("ERROR while trying to delete : %s" % dmz.value, "error")
31
    return redirect("/settings/mz")
32
33
34 1
@settings.route("/mz/new", methods=["POST"])
35
def mz_new():
36
    db.session.add(ValueTemplates("naxsi_mz", request.form["nmz"]))
37
    db.session.commit()
38
    flash("Updated MZ: %s" % request.form["nmz"], "success")
39
    return redirect("/settings/mz")
40
41
42 1
@settings.route("/scores")
43
def scores_index():
44 1
    sc = ValueTemplates.query.filter(ValueTemplates.name == "naxsi_score").order_by(ValueTemplates.value).all()
45 1
    if not sc:
46
        return redirect("/settings")
47 1
    return render_template("settings/scores.html", scores=sc)
48
49
50 1
@settings.route("/scores/new", methods=["POST"])
51
def scores_new():
52
    if not request.form["nscore"].startswith("$"):
53
        request.form["nscore"] = '$' + request.form["nscore"]
54
55
    db.session.add(ValueTemplates("naxsi_score", request.form["nscore"].upper()))
56
    db.session.commit()
57
    flash("Updated Score: %s" % request.form["nscore"], "success")
58
    return redirect("/settings/scores")
59
60
61 1
@settings.route("/scores/del", methods=["POST"])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
def scores_del():
63
    dsc = ValueTemplates.query.filter(ValueTemplates.id == request.form["scid"]).first()
64
    if not dsc:
65
        flash("Nothing found in %s " % (request.form["scid"]), "error")
66
        return redirect("/settings/scores")
67
    db.session.delete(dsc)
68
69
    try:
70
        db.session.commit()
71
        flash("OK: deleted %s " % dsc.value, "success")
72
    except SQLAlchemyError:
73
        flash("ERROR while trying to delete : %s" % dsc.value, "error")
74
    return redirect("/settings/scores")
75