Skip to content

Commit

Permalink
Upgraded to Django 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Casassarnau committed Oct 2, 2021
1 parent f382107 commit 52a293d
Show file tree
Hide file tree
Showing 25 changed files with 357 additions and 167 deletions.
38 changes: 38 additions & 0 deletions app/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,41 @@ def clean(self):
model_data = model_to_dict(self.instance)
model_data.update(cleaned_data)
return model_data


class BootstrapFormMixin:

# example: {'TITLE': {'fields': [{'name': 'FIELD_NAME', 'space': GRID_NUMBER},], 'description': 'DESCRIPTION'},}
# UPPER LETTERS MUST BE CHANGED
bootstrap_field_info = {}
read_only = []

def get_bootstrap_field_info(self):
return self.bootstrap_field_info

def set_read_only(self):
for field in self.fields.values():
field.disabled = True

@property
def is_read_only(self):
for field in self.fields.values():
if not field.disabled:
return False
return True

@property
def get_fields(self):
result = self.get_bootstrap_field_info()
for list_fields in result.values():
sum = 0
for field in list_fields.get('fields'):
if sum + field.get('space') > 12:
sum = field.get('space')
field['new_row'] = True
else:
sum += field.get('space')
field['new_row'] = False
name = field.get('name')
field.update({'field': self.fields.get(name).get_bound_field(self, name)})
return result
9 changes: 2 additions & 7 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@

# Application definition
INSTALLED_APPS = [
'jet',
'jet.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.humanize',
'django.contrib.messages',
'django.contrib.staticfiles',
'form_utils',
'bootstrap3',
'django_tables2',
'organizers',
Expand Down Expand Up @@ -212,10 +209,6 @@
else:
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

# Jet configs
JET_SIDE_MENU_COMPACT = True
JET_INDEX_DASHBOARD = 'app.jet_dashboard.CustomIndexDashboard'

# Set up custom auth
AUTH_USER_MODEL = 'user.User'
LOGIN_URL = 'account_login'
Expand Down Expand Up @@ -275,3 +268,5 @@
'M': MENTOR_EXPIRES, # Mentor can expire
'V': VOLUNTEER_EXPIRES, # Volunteer can expire
}

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
5 changes: 5 additions & 0 deletions app/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,8 @@ hr {
display:block !important;
}
}

.row {
margin-left: 0px;
margin-right: 0px;
}
32 changes: 32 additions & 0 deletions app/templates/include/bootstrap_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% load bootstrap3 %}
{% if messages %}
<div>
{% for message in messages %}
<div class="alert {% if message.tags %} alert-{{ message.tags }}{% endif %} alert-dismissible show" role="alert">
{{ message|capfirst }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endfor %}
</div>
{% endif %}
{% for title, zone in form.get_fields.items %}
<fieldset>
<h3 class="heading-primary">{{ title }}</h3>
{% if zone.description %}
<p>{{ zone.description }}</p>
{% endif %}
<div class="row">
{% for field in zone.fields %}
{% if field.new_row %}
</div>
<div class="row">
{% endif %}
<div class="col-{{ field.space }}">
{% bootstrap_field field.field %}
</div>
{% endfor %}
</div>
</fieldset>
{% endfor %}
4 changes: 2 additions & 2 deletions app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^user/', include('user.urls')),
url(r'^jet/', include('jet.urls', 'jet')), # Django JET URLS
url(r'^jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')), # Django JET dashboard URLS
# url(r'^jet/', include('jet.urls', 'jet')), # Django JET URLS
# url(r'^jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')), # Django JET dashboard URLS
url(r'^applications/', include('organizers.urls')),
url(r'^', include('applications.urls')),
url(r'^$', views.root_view, name='root'),
Expand Down
4 changes: 2 additions & 2 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@


def root_view(request):
if not request.user.is_authenticated() and not utils.is_app_closed():
if not request.user.is_authenticated and not utils.is_app_closed():
return HttpResponseRedirect(reverse('account_signup'))
if not request.user.is_authenticated() and utils.is_app_closed():
if not request.user.is_authenticated and utils.is_app_closed():
return HttpResponseRedirect(reverse('account_login'))
if not request.user.has_usable_password():
return HttpResponseRedirect(reverse('set_password'))
Expand Down
Loading

0 comments on commit 52a293d

Please sign in to comment.