Skip to content

Commit

Permalink
feat: Google adsense add codeQ
Browse files Browse the repository at this point in the history
Signed-off-by: William Moreno <wmoreno@bmogroup.solutions>
  • Loading branch information
williamjmorenor committed Feb 3, 2025
1 parent 2db7ae4 commit 05e5773
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions now_lms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
crear_configuracion_predeterminada,
cuenta_cursos_por_programa,
get_addsense_meta,
get_addsense_code,
logo_perzonalizado,
obtener_estilo_actual,
verifica_docente_asignado_a_curso,
Expand Down Expand Up @@ -348,6 +349,7 @@ def carga_configuracion_del_sitio_web_desde_db(): # pragma: no cover
lms_app.jinja_env.globals["mkdonw2thml"] = markdown_to_clean_hmtl
lms_app.jinja_env.globals["cuenta_cursos"] = cuenta_cursos_por_programa
lms_app.jinja_env.globals["adsense_meta"] = get_addsense_meta
lms_app.jinja_env.globals["adsense_code"] = get_addsense_code


# ---------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions now_lms/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,4 @@ class AdSense(database.Model):
meta_tag = database.Column(database.String(100))
meta_tag_include = database.Column(database.Boolean(), default=False)
pub_id = database.Column(database.String(20))
add_code = database.Column(database.String(200))
17 changes: 17 additions & 0 deletions now_lms/db/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,20 @@ def get_addsense_meta():
return ""
else:
return ""


def get_addsense_code():
"""AdSense metatags."""
try:
query = database.session.execute(database.select(AdSense)).first()
except:
query = None

if query:
data = query[0]
if data.meta_tag_include:
return data.add_code
else:
return ""
else:
return ""
1 change: 1 addition & 0 deletions now_lms/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,4 @@ class AdSenseForm(FlaskForm):
meta_tag = TextAreaField(validators=[])
meta_tag_include = BooleanField(validators=[])
pub_id = StringField(validators=[])
add_code = TextAreaField(validators=[])
11 changes: 11 additions & 0 deletions now_lms/templates/admin/adsense.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ <h4 class="pb-2 border-bottom">Editar configuración de anunciós de AdSense.</h

<br>

<div class="row">

<div class="col-sm-6">
<label for="add_code" class="form-label">Código de AdSense:</label>
{{ form.add_code(class="form-control", id="add_code",) }}
</div>

</div>

<br>

<div class="row">

<div class="col-sm-6">
Expand Down
2 changes: 2 additions & 0 deletions now_lms/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

{{ adsense_meta() | safe }}

{{ adsense_code() | safe }}

{%- endmacro %}


Expand Down
5 changes: 4 additions & 1 deletion now_lms/vistas/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ def adsense():
database.session.commit()
config = database.session.execute(database.select(AdSense)).first()[0]

form = AdSenseForm(meta_tag=config.meta_tag, meta_tag_include=config.meta_tag_include, pub_id=config.pub_id)
form = AdSenseForm(
meta_tag=config.meta_tag, meta_tag_include=config.meta_tag_include, pub_id=config.pub_id, add_code=config.add_code
)

if form.validate_on_submit() or request.method == "POST":

config.meta_tag = form.meta_tag.data
config.meta_tag_include = form.meta_tag_include.data
config.pub_id = form.pub_id.data
config.add_code = form.add_code.data

try: # pragma: no cover
database.session.commit()
Expand Down

0 comments on commit 05e5773

Please sign in to comment.