from django db import connection from django http import HttpResponse

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from django.db import connection
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response
from django.core.exceptions import ObjectDoesNotExist
from django.template import Context, Template, loader
from corporate import settings
from corporate.pages.models import SomePage, TypeofthePage, AvtoModels, Accessories, Services, Contacts
# Create your views here.
def page(request, object_list):
first_menu_items = SomePage.objects.filter(page_first_menu__exact=True)
first_menu=[]
for this_page in first_menu_items:
root_pages = this_page.get_ancestors()
urltext = ''
for root_page in root_pages:
urltext = urltext+'/'+root_page.page_name
urltext = urltext+'/'+this_page.page_name+'/'
first_menu.append({'url': urltext,'item': this_page,'image_first_menu':settings.MEDIA_URL+this_page.image_first_menu})
root_page = None
need_models = False
second_menu_base_path = '/'
filterpage = ''
for page in object_list.split('/'):
currentpage = SomePage.objects.filter(page_name__exact=page)
try:
if root_page:
currentpage = currentpage.get(parent__exact=root_page)
else:
currentpage = currentpage.get(parent__isnull=True)
root_page = currentpage
second_menu_base_path = second_menu_base_path+currentpage.page_name+'/'
table_AvtoModels = AvtoModels.objects.filter(parrent_page__exact=currentpage)
table_Accessories = Accessories.objects.filter(parrent_page__exact=currentpage)
table_Services = Services.objects.filter(parrent_page__exact=currentpage)
table_Contacts = Contacts.objects.filter(parrent_page__exact=currentpage)
except (ObjectDoesNotExist):
filterpage = page
if currentpage:
right_content = {'text': '','models': [],'accessories': [],'services': [], 'contacts': []}
second_menu = {'text':'','items':[]}
if table_AvtoModels:
if filterpage:
table_AvtoModels = table_AvtoModels.filter(type__category_page_name__exact=filterpage)
for AvtoModel in table_AvtoModels:
right_content['models'].append({'model':AvtoModel,'short_description':AvtoModel,'price':AvtoModel})
for AvtoModel_menu in set([table_AvtoModel.type for table_AvtoModel in table_AvtoModels]):
second_menu['items'].append({'text':AvtoModel_menu.category_description,'url':AvtoModel_menu.category_page_name})
if table_Accessories:
if filterpage:
table_Accessories = table_Accessories.objects.filter(type__category_page_name__exact=filterpage)
for Accessorie in table_Accessories:
right_content['accessories'].append({'short_description': Accessorie,'model':Accessorie,'price':Accessorie})
for Accessories_menu in set([table_Accessory.type for table_Accessory in table_Accessories]):
second_menu['items'].append({'text':Accessories_menu.category_description,'url':Accessories_menu.category_page_name})
if table_Services:
if filterpage:
table_Services = table_Services.objects.filter(type__category_page_name__exact=filterpage)
for Service in table_Services:
right_content['services'].append({'short_description':Service,'normochas':Service,'price':Service})
for Services_menu in set([table_Service.type for table_Service in table_Services]):
second_menu['items'].append({'text':Services_menu.category_description,'url':Services_menu.category_page_name})
if table_Contacts:
if filterpage:
table_Contacts = table_Contacts.objects.filter(type__category_page_name__exact=filterpage)
for Contact in table_Contacts:
right_content['contacts'].append({'city':Contact,'address':Contact,'url':Contact,'email':Contact,'location_image':Contact,'phone':Contact})
for Contacts_menu in set([table_Contact.type for table_Contact in table_Contacts]):
second_menu['items'].append({'text':Contacts_menu.category_description,'url':Contacts_menu.category_page_name})
template_file = currentpage.page_type.template_name
image_top_banner = settings.MEDIA_URL+currentpage.image_top_banner
image_left_banner = settings.MEDIA_URL+currentpage.image_left_banner
return render_to_response(template_file, {"image_top_banner":image_top_banner,"image_left_banner":image_left_banner,"first_menu":first_menu,'right_content':right_content,'second_menu':second_menu })
else:
raise Http404