Skip to content

Commit

Permalink
fix resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
zahiramanzur committed May 16, 2018
1 parent c41bad6 commit a875f9f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion banner/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SelectBannerForm(forms.Form):

class EventsSortForm(forms.Form):

sort = forms.IntegerField(required=True)
sort = forms.ChoiceField(required=True)
event = forms.IntegerField(
required=True,
widget=forms.HiddenInput(),
Expand Down
4 changes: 2 additions & 2 deletions banner/templates/event/sort_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ <h4 style="padding-top: 4px" >Título</h4>
<h4 style="padding-top: 4px" >Descripción</h4>
<p class="text-truncate" style="max-width: 400px">{{ forms.description.value }}</p>
</div>
<div class=" col-md-3">
{% bootstrap_field forms.sort %}
<div class=" col-md-3" style="padding-top: 25px">
{{ forms.sort }}
</div>
</div>
</div>
Expand Down
52 changes: 32 additions & 20 deletions banner/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def edit_banner(self, form, formset, *args, **kwargs):
for event in updated_events:
if event['selection']:

'''create events'''
'''add events in events (create in bd)'''
if int(event['evb_id']) not in events_evb_id_list:
e_design = EventDesign.objects.get(
id=DEFAULT_EVENT_DESIGN,
Expand Down Expand Up @@ -231,6 +231,8 @@ def post(self, request, *args, **kwargs):

@transaction.atomic
def form_valid(self, form, formset):


form.instance.user = self.request.user
banner = form.save(commit=False)
events = formset.save(commit=False)
Expand All @@ -247,21 +249,25 @@ def form_valid(self, form, formset):
)

last_banner_id = Banner.objects.latest('created').id
for event in events:
if event is not None:
event.banner = banner
event.design = e_design
if Event.objects.all().count() == 0:
last_event_id = 1
else:
last_event_id = Event.objects.latest('created').id
if event.custom_logo:
event.custom_logo = img_upload(
event.custom_logo,
last_banner_id + 1,
last_event_id + 1,
)
event.save()

count_events = [event for event in enumerate(sorted(events, reverse=True), 1) if event[1] != None]

for idx, event in count_events:

event.sort = idx
event.banner = banner
event.design = e_design
if Event.objects.all().count() == 0:
last_event_id = 1
else:
last_event_id = Event.objects.latest('created').id
if event.custom_logo:
event.custom_logo = img_upload(
event.custom_logo,
last_banner_id + 1,
last_event_id + 1,
)
event.save()
except IntegrityError as error:
print error.message

Expand Down Expand Up @@ -563,7 +569,6 @@ def get_context_data(self, **kwargs):
for event in events:
initial_data.append(
{
'sort': 1,
'event': event.id,
'description': event.description,
'title': event.title,
Expand All @@ -583,14 +588,17 @@ def get_context_data(self, **kwargs):
initial=initial_data
)

for ev_form in formset:
sort = enumerate(range(1, len(events) + 1), 1)
ev_form.fields['sort'].choices = [i for i in sort]

context['form'] = form
context['formset'] = formset
context['events'] = events
context['banner'] = banner
return context

def post(self, request, *args, **kwargs):

banner = Banner.objects.get(id=self.kwargs['pk'])
events = Event.objects.filter(banner=banner)

Expand All @@ -612,7 +620,6 @@ def post(self, request, *args, **kwargs):
for event in events:
initial_data.append(
{
'sort': 1,
'event': event.id,
'description': event.description,
'title': event.title,
Expand All @@ -625,7 +632,12 @@ def post(self, request, *args, **kwargs):
initial=initial_data
)

for ev_form in formset:
sort = enumerate(range(1, len(events) + 1), 1)
ev_form.fields['sort'].choices = [i for i in sort]

if bannerform.is_valid() and formset.is_valid():

list_input_sort = []
for element in formset.cleaned_data:
list_input_sort.append(element['sort'])
Expand All @@ -637,7 +649,7 @@ def post(self, request, *args, **kwargs):
NON_FIELD_ERRORS,
'Colocó ordenes iguales')

max_sort = max(sort)
max_sort = str(max(sort))
max_list_input_sort = max(list_input_sort)

if max_list_input_sort > max_sort:
Expand Down

0 comments on commit a875f9f

Please sign in to comment.