Skip to content

Commit

Permalink
feat: cdswebsites object extra fix-migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
revelis-vincenzo committed Nov 15, 2023
1 parent 47d9e66 commit 4b687f3
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 46 deletions.
16 changes: 12 additions & 4 deletions crud/cds_websites/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def __init__(self, *args, **kwargs):
if self.initial:
self.initial["visibile"] = bool(self.initial.get("visibile", None))


visibile = forms.BooleanField(
label=_("Visible"),
required=False,
Expand Down Expand Up @@ -146,7 +145,6 @@ def __init__(self, *args, **kwargs):


class SitoWebCdsOggettiPortaleForm(forms.ModelForm):


id_classe_oggetto_portale = forms.ChoiceField(
required=True,
Expand All @@ -157,16 +155,25 @@ class SitoWebCdsOggettiPortaleForm(forms.ModelForm):
required=True,
min_value=1901,
max_value=timezone.now().year,
label=_("Didactic Regulation Year"),
label=_("Didactic Regulation Academic Year"),
)
id_oggetto_portale = forms.IntegerField(
required=True,
min_value=0,
label=_("Object Id"),
)
class Meta:
model = SitoWebCdsOggettiPortale
exclude = ['dt_mod', 'id_user_mod','id_sito_web_cds_topic', 'cds', 'ordine', 'visibile']

labels = {
"titolo_it": _("Title (IT)"),
"titolo_en": _("Title (EN)"),
"testo_it": _("Text (IT)"),
"testo_en": _("Text (EN)"),
"id_oggetto_portale": _("Object Id"),
"aa_regdid_id": _("Didactic Regulation Academic Year"),
"id_classe_oggetto_portale": _("Object Class"),
}

class SitoWebCdsTopicArticoliRegAltriDatiForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
Expand All @@ -192,6 +199,7 @@ def __init__(self, *args, **kwargs):
)
link = forms.URLField(
label=_("Link"),
required=False,
)

class Meta:
Expand Down
12 changes: 12 additions & 0 deletions crud/cds_websites/templates/blocks/cds_website_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
<div class="collapse-header" id="heading_{{page_name}}_{{topic_obj_regarts.topic.id}}">
<button data-toggle="collapse" data-target="#collapse_{{page_name}}_{{topic_obj_regarts.topic.id}}" aria-expanded="false" aria-controls="collapse_{{page_name}}_{{topic_obj_regarts.topic.id}}">
<h4 style="font-weight: lighter;" class="pb-2">
{% if LANGUAGE_CODE == "it" or not topic_obj_regarts.topic.descr_topic_en %}
{{ topic_obj_regarts.topic.descr_topic_it }}
{% else %}
{{ topic_obj_regarts.topic.descr_topic_en }}
{% endif %}
</h4>
</button>
</div>
Expand Down Expand Up @@ -64,7 +68,11 @@ <h5 class="modal-title">
<!-- /Regart Remove Modal -->
<tr>
<td class="col-7">
{% if LANGUAGE_CODE == "it" or not regart.titolo_en %}
{{ regart.titolo_it }}
{% else %}
{{ regart.titolo_en }}
{% endif %}
</td>
<td class="col-2 text-center">
{{ regart.ordine }}
Expand Down Expand Up @@ -150,7 +158,11 @@ <h5 class="modal-title">
<!-- /Object Delete Modal -->
<tr>
<td class="col-7">
{% if LANGUAGE_CODE == "it" or not object.titolo_en %}
{{ object.titolo_it }}
{% else %}
{{ object.titolo_en }}
{% endif %}
</td>
<td class="col-2 text-center">
{{ object.ordine }}
Expand Down
7 changes: 6 additions & 1 deletion crud/cds_websites/templates/cds_website.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

{% block centered_container %}

{% get_current_language as LANGUAGE_CODE %}

<!-- Top Buttons -->
<table class="table">
Expand All @@ -31,7 +32,11 @@
<div class="card card-bg no-after">
<div class="card-body">
<h3 style="font-weight: normal;" class="mb-4 pb-4">
{{ cds.nome_cds_it }}
{% if LANGUAGE_CODE == "it" or not cds_website.nome_corso_en %}
{{ cds_website.nome_corso_it }}
{% else %}
{{ cds_website.nome_corso_en }}
{% endif %}
</h3>
<!-- Enroll -->
<div class="card-wrapper card-space">
Expand Down
6 changes: 5 additions & 1 deletion crud/cds_websites/templates/regulament_articles.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ <h5 class="modal-title">
<!-- /Extra Delete Modal -->
<tr>
<td class="col-7">
{{ extra.testo_it }}
{% if LANGUAGE_CODE == "it" or not extra.testo_en %}
{{ extra.testo_it }}
{% else %}
{{ extra.testo_en }}
{% endif %}
</td>
<td class="col-2 text-center">
{{ extra.ordine }}
Expand Down
7 changes: 4 additions & 3 deletions crud/cds_websites/templates/unique_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
{% load i18n %}
{% load static %}

{% get_current_language as LANGUAGE_CODE %}


{% block centered_container %}
<div>
<h3 style="font-weight: lighter;" class="mb-4">
{% if edit|default:False %}{% trans "Edit " %}{% else %}{% trans "New " %}{% endif %} {{item_label|default:"item"}} {% trans " for " %} {{ cds_website.nome_corso_it }}
{% if edit|default:False %}{% trans "Edit " %}{% else %}{% trans "New " %}{% endif %} {{item_label|default:"item"}} {% trans " for " %}
{% if LANGUAGE_CODE == "it" or not cds_website.nome_corso_en %}{{ cds_website.nome_corso_it }}{% else %} {{ cds_website.nome_corso_en }} {% endif %}
</h3>
{% block before_forms%}
{% endblock %}
Expand All @@ -18,8 +21,6 @@ <h3 style="font-weight: lighter;" class="mb-4">
<div class="card-body">
{% for form in forms %}
{% include "form_template.html" with form=form %}
<hr />
<hr />
{% endfor %}
{% block before_submit %}
{% endblock %}
Expand Down
60 changes: 27 additions & 33 deletions crud/cds_websites/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ def cds_websites_topics_edit(request, code, cds_website=None, my_offices=None):
"objects" : topic_objs,
"regarts" : topic_areg
}


if request.POST:
pass

breadcrumbs = {reverse('crud_utils:crud_dashboard'): _('Dashboard'),
reverse('crud_cds_websites:crud_cds_websites'): _('Cds websites'),
Expand Down Expand Up @@ -125,16 +121,11 @@ def cds_websites_topics_edit(request, code, cds_website=None, my_offices=None):
@can_manage_cds_website
@can_edit_cds_website
def cds_websites_item_delete(request, code, topic_id, data_id, cds_website=None, my_offices=None):
print(f"Deleting {data_id}")
regart = get_object_or_404(SitoWebCdsTopicArticoliReg, pk=data_id)
if regart.id_sito_web_cds_articoli_regolamento is not None:
#delete extras
extras = SitoWebCdsTopicArticoliRegAltriDati.objects.filter(id_sito_web_cds_topic_articoli_reg=regart.id)
print(extras)
#extras.delete()
#regart.delete()
regart.delete()
elif regart.id_sito_web_cds_oggetti_portale is not None:
pass
regart.id_sito_web_cds_oggetti_portale.delete()

return redirect('crud_cds_websites:crud_cds_websites_topics_edit', code=code)

Expand Down Expand Up @@ -375,20 +366,20 @@ def cds_websites_object_edit(request, code, topic_id, data_id, cds_website=None,

art_reg_form = SitoWebCdsTopicArticoliItemForm(data=request.POST if request.POST else None, instance=tregart)

item_form = SitoWebCdsOggettiPortaleForm(data=request.POST if request.POST else None, instance=tregart.id_sito_web_cds_oggetti_portale)
object_form = SitoWebCdsOggettiPortaleForm(data=request.POST if request.POST else None, instance=tregart.id_sito_web_cds_oggetti_portale)

if request.POST:
if art_reg_form.is_valid() and item_form.is_valid():
if art_reg_form.is_valid() and object_form.is_valid():

art_reg = art_reg_form.save(commit=False)
art_reg.id_user_mod = request.user
art_reg.dt_mod = now()
art_reg.save()

item_form.save(commit=False)
item_form.id_user_mod = request.user
item_form.dt_mod = now()
item_form.save()
_object = object_form.save(commit=False)
_object.id_user_mod = request.user
_object.dt_mod = now()
_object.save()

log_action(user=request.user,
obj=cds_website,
Expand All @@ -405,20 +396,20 @@ def cds_websites_object_edit(request, code, topic_id, data_id, cds_website=None,
for k, v in art_reg_form.errors.items():
messages.add_message(request, messages.ERROR,
f"<b>{art_reg_form.fields[k].label}</b>: {v}")
for k, v in item_form.errors.items():
for k, v in object_form.errors.items():
messages.add_message(request, messages.ERROR,
f"<b>{item_form.fields[k].label}</b>: {v}")
f"<b>{object_form.fields[k].label}</b>: {v}")

breadcrumbs = {reverse('crud_utils:crud_dashboard'): _('Dashboard'),
reverse('crud_cds_websites:crud_cds_websites'): _('Cds websites'),
reverse('crud_cds_websites:crud_cds_websites_topics_edit', kwargs={'code': code}):cds_website.cds.nome_cds_it,
reverse('crud_cds_websites:crud_cds_websites_topics_edit', kwargs={'code': code}): cds_website.cds.nome_cds_it,
'#': tregart.titolo_it }

return render(request, 'unique_form.html',
{
'cds_website': cds_website,
'breadcrumbs': breadcrumbs,
'forms': [art_reg_form, item_form,],
'forms': [art_reg_form, object_form,],
'item_label': _('Item'),
'edit': 1,
})
Expand All @@ -431,21 +422,24 @@ def cds_websites_object_new(request, code, topic_id, cds_website=None, my_office

art_reg_form = SitoWebCdsTopicArticoliItemForm(data=request.POST if request.POST else None)

item_form = SitoWebCdsOggettiPortaleForm(data=request.POST if request.POST else None)
object_form = SitoWebCdsOggettiPortaleForm(data=request.POST if request.POST else None)

if request.POST:
if art_reg_form.is_valid() and item_form.is_valid():
if art_reg_form.is_valid() and object_form.is_valid():

_object = object_form.save(commit=False)
_object.id_sito_web_cds_topic = topic_id
_object.cds = cds_website.cds
_object.id_user_mod = request.user
_object.dt_mod = now()
_object.save()

art_reg = art_reg_form.save(commit=False)
art_reg.id_sito_web_cds_oggetti_portale = _object
art_reg.id_sito_web_cds_topic = get_object_or_404(SitoWebCdsTopic, pk=topic_id)
art_reg.id_user_mod = request.user
art_reg.dt_mod = now()
art_reg.save()

item_form.save(commit=False)
item_form.id_sito_web_cds_oggetti_portale = art_reg
item_form.id_user_mod = request.user
item_form.dt_mod = now()
item_form.save()

log_action(user=request.user,
obj=cds_website,
Expand All @@ -462,20 +456,20 @@ def cds_websites_object_new(request, code, topic_id, cds_website=None, my_office
for k, v in art_reg_form.errors.items():
messages.add_message(request, messages.ERROR,
f"<b>{art_reg_form.fields[k].label}</b>: {v}")
for k, v in item_form.errors.items():
for k, v in object_form.errors.items():
messages.add_message(request, messages.ERROR,
f"<b>{item_form.fields[k].label}</b>: {v}")
f"<b>{object_form.fields[k].label}</b>: {v}")

breadcrumbs = {reverse('crud_utils:crud_dashboard'): _('Dashboard'),
reverse('crud_cds_websites:crud_cds_websites'): _('Cds websites'),
reverse('crud_cds_websites:crud_cds_websites_topics_edit', kwargs={'code': code}):cds_website.cds.nome_cds_it,
reverse('crud_cds_websites:crud_cds_websites_topics_edit', kwargs={'code': code}): cds_website.nome_corso_it if (request.LANGUAGE_CODE == 'it' or not cds_website.nome_corso_en) else cds_website.nome_corso_en,
'#': _("New Object") }

return render(request, 'unique_form.html',
{
'cds_website': cds_website,
'breadcrumbs': breadcrumbs,
'forms': [art_reg_form, item_form,],
'forms': [art_reg_form, object_form,],
'item_label': _('Item'),
'edit': 1,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Migration(migrations.Migration):
('dt_mod', models.DateField(db_column='DT_MOD')),
('id_user_mod', models.IntegerField(db_column='ID_USER_MOD')),
('id_sito_web_cds_articoli_regolamento', models.ForeignKey(db_column='ID_SITO_WEB_CDS_ARTICOLI_REGOLAMENTO', on_delete=django.db.models.deletion.DO_NOTHING, to='ricerca_app.sitowebcdsarticoliregolamento')),
('id_sito_web_cds_oggetti_portale', models.ForeignKey(blank=True, db_column='ID_SITO_WEB_CDS_OGGETTI_PORTALE', null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='ricerca_app.sitowebcdsoggettiportale')),
('id_sito_web_cds_oggetti_portale', models.ForeignKey(blank=True, db_column='ID_SITO_WEB_CDS_OGGETTI_PORTALE', null=True, on_delete=django.db.models.deletion.CASCADE, to='ricerca_app.sitowebcdsoggettiportale')),
('id_sito_web_cds_topic', models.ForeignKey(db_column='ID_SITO_WEB_CDS_TOPIC', on_delete=django.db.models.deletion.DO_NOTHING, to='ricerca_app.sitowebcdstopic')),
],
options={
Expand Down
2 changes: 1 addition & 1 deletion ricerca_app/migrations/0146_auto_20230712_1343.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Migration(migrations.Migration):
('testo_en', models.TextField(blank=True, db_column='TESTO_EN', null=True)),
('visibile', models.IntegerField(db_column='VISIBILE')),
('dt_mod', models.DateField(db_column='DT_MOD')),
('id_sito_web_cds_topic_articoli_reg', models.ForeignKey(db_column='ID_SITO_WEB_CDS_TOPIC_ARTICOLI_REG', on_delete=django.db.models.deletion.DO_NOTHING, to='ricerca_app.sitowebcdstopicarticolireg')),
('id_sito_web_cds_topic_articoli_reg', models.ForeignKey(db_column='ID_SITO_WEB_CDS_TOPIC_ARTICOLI_REG', on_delete=django.db.models.deletion.CASCADE, to='ricerca_app.sitowebcdstopicarticolireg')),
('id_user_mod', models.ForeignKey(blank=True, db_column='ID_USER_MOD', null=True, on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
],
options={
Expand Down
4 changes: 2 additions & 2 deletions ricerca_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4223,7 +4223,7 @@ class SitoWebCdsTopicArticoliReg(models.Model):
titolo_it = models.CharField(db_column='TITOLO_IT', max_length=1000) # Field name made lowercase.
titolo_en = models.CharField(db_column='TITOLO_EN', max_length=1000, blank=True, null=True) # Field name made lowercase.
id_sito_web_cds_topic = models.ForeignKey(SitoWebCdsTopic, models.DO_NOTHING, db_column='ID_SITO_WEB_CDS_TOPIC') # Field name made lowercase.
id_sito_web_cds_oggetti_portale = models.ForeignKey(SitoWebCdsOggettiPortale, models.DO_NOTHING, db_column='ID_SITO_WEB_CDS_OGGETTI_PORTALE', blank=True, null=True) # Field name made lowercase.
id_sito_web_cds_oggetti_portale = models.ForeignKey(SitoWebCdsOggettiPortale, models.CASCADE, db_column='ID_SITO_WEB_CDS_OGGETTI_PORTALE', blank=True, null=True) # Field name made lowercase.
id_sito_web_cds_articoli_regolamento = models.ForeignKey(SitoWebCdsArticoliRegolamento, models.DO_NOTHING, db_column='ID_SITO_WEB_CDS_ARTICOLI_REGOLAMENTO', blank=True, null=True) # Field name made lowercase.
ordine = models.IntegerField(db_column='ORDINE') # Field name made lowercase.
dt_mod = models.DateField(db_column='DT_MOD') # Field name made lowercase.
Expand All @@ -4248,7 +4248,7 @@ class Meta:

class SitoWebCdsTopicArticoliRegAltriDati(models.Model):
id = models.AutoField(db_column='ID', primary_key=True) # Field name made lowercase.
id_sito_web_cds_topic_articoli_reg = models.ForeignKey(SitoWebCdsTopicArticoliReg, models.DO_NOTHING, db_column='ID_SITO_WEB_CDS_TOPIC_ARTICOLI_REG') # Field name made lowercase.
id_sito_web_cds_topic_articoli_reg = models.ForeignKey(SitoWebCdsTopicArticoliReg, models.CASCADE, db_column='ID_SITO_WEB_CDS_TOPIC_ARTICOLI_REG') # Field name made lowercase.
ordine = models.PositiveIntegerField(db_column='ORDINE') # Field name made lowercase.
id_sito_web_cds_tipo_dato = models.ForeignKey(SitoWebCdsTipoDato, models.PROTECT, db_column='ID_SITO_WEB_CDS_TIPO_DATO') # Field name made lowercase.
titolo_en = models.CharField(db_column='TITOLO_EN', max_length=1000, blank=True, null=True) # Field name made lowercase.
Expand Down

0 comments on commit 4b687f3

Please sign in to comment.