|
21 | 21 | from django_tables2 import SingleTableMixin
|
22 | 22 |
|
23 | 23 | from app.mixins import TabsViewMixin
|
| 24 | +from app.utils import is_installed |
24 | 25 | from application import forms
|
25 | 26 | from application.mixins import ApplicationPermissionRequiredMixin
|
26 | 27 | from application.models import Application, FileField, ApplicationLog, ApplicationTypeConfig, PromotionalCode
|
@@ -123,22 +124,36 @@ def get_form(self, application_type):
|
123 | 124 | raise Http404()
|
124 | 125 | return ApplicationForm
|
125 | 126 |
|
| 127 | + def add_friends_details(self, details, application): |
| 128 | + if is_installed('friends'): |
| 129 | + friend_code = application.user.friendscode_set.first() |
| 130 | + if friend_code is not None: |
| 131 | + friends = friend_code.get_members().exclude(pk=friend_code.pk).values_list('user__email', flat=True) |
| 132 | + if len(friends) > 0: |
| 133 | + details[_('Number of friends')] = len(friends) |
| 134 | + details[_('Friends list')] = ', '.join(friends) |
| 135 | + |
| 136 | + def get_details(self, application): |
| 137 | + details = {_('Full Name'): application.user.get_full_name(), _('Status'): application.get_status_display()} |
| 138 | + if application.promotional_code: |
| 139 | + details[_('Promotion')] = application.promotional_code.name |
| 140 | + for name, value in application.form_data.items(): |
| 141 | + if isinstance(value, FileField): |
| 142 | + value = value.url |
| 143 | + if isinstance(value, bool): |
| 144 | + value = _('Yes') if value else _('No') |
| 145 | + if isinstance(value, list): |
| 146 | + value = ', '.join(value) |
| 147 | + details[name.replace('_', ' ').lower().title()] = value |
| 148 | + self.add_friends_details(details, application) |
| 149 | + return details |
| 150 | + |
126 | 151 | def get_context_data(self, **kwargs):
|
127 | 152 | context = super().get_context_data(**kwargs)
|
128 | 153 | application = self.get_application()
|
129 | 154 | if application is not None:
|
130 |
| - details = {_('Full Name'): application.user.get_full_name(), _('Status'): application.get_status_display()} |
131 |
| - if application.promotional_code: |
132 |
| - details[_('Promotion')] = application.promotional_code.name |
| 155 | + details = self.get_details(application) |
133 | 156 | ApplicationForm = self.get_form(application.type)
|
134 |
| - for name, value in application.form_data.items(): |
135 |
| - if isinstance(value, FileField): |
136 |
| - value = value.url |
137 |
| - if isinstance(value, bool): |
138 |
| - value = _('Yes') if value else _('No') |
139 |
| - if isinstance(value, list): |
140 |
| - value = ', '.join(value) |
141 |
| - details[name.replace('_', ' ').lower().title()] = value |
142 | 157 | icons = {name.replace('_', ' ').lower().title(): value
|
143 | 158 | for name, value in getattr(ApplicationForm.Meta, 'icon_link', {}).items()}
|
144 | 159 | comments = application.logs.filter(comment__isnull=False)
|
|
0 commit comments