Commit f6fce4bf authored by Tyler Hallada's avatar Tyler Hallada
Browse files

Moved export_data() function to seperate file

Database errors may have been caused by having export_data() in
the models.py file.
parent 0f3ddfef
from website.models import Restaurant
def export_data():
restaurants = list()
for restaurant in Restaurant.objects.all():
restaurant_data = {'name': restaurant.name}
open_times = list()
for time in restaurant.main_schedule.open_times.all():
open_times.append({
'start_day': time.start_day,
'start_time': time.start_time.isoformat(),
'end_day': time.end_day,
'end_time': time.end_time.isoformat()
})
restaurant_data['main_schedule'] = {
'name': restaurant.main_schedule.name,
'id': restaurant.id,
'open_times': open_times
}
special_schedules = list()
for schedule in restaurant.special_schedules.all():
open_times = list()
for time in schedule.open_times.all():
open_times.append({
'start_day': time.start_day,
'start_time': time.start_time.isoformat(),
'end_day': time.end_day,
'end_time': time.end_time.isoformat()
})
special_schedules.append({
'name': schedule.name,
'id': restaurant.id,
'start': schedule.valid_start.isoformat(),
'end': schedule.valid_end.isoformat(),
'open_times': open_times
})
restaurant_data['special_schedules'] = special_schedules
restaurants.append(restaurant_data)
return restaurants
...@@ -103,42 +103,3 @@ class OpenTime(BaseModel): ...@@ -103,42 +103,3 @@ class OpenTime(BaseModel):
return '%s %s to %s %s' % (weekdays[self.start_day], return '%s %s to %s %s' % (weekdays[self.start_day],
self.start_time.strftime("%H:%M:%S"), weekdays[self.end_day], self.start_time.strftime("%H:%M:%S"), weekdays[self.end_day],
self.end_time.strftime("%H:%M:%S")) self.end_time.strftime("%H:%M:%S"))
def export_data():
restaurants = list()
for restaurant in Restaurant.objects.all():
restaurant_data = {'name': restaurant.name}
open_times = list()
for time in restaurant.main_schedule.open_times.all():
open_times.append({
'start_day': time.start_day,
'start_time': time.start_time.isoformat(),
'end_day': time.end_day,
'end_time': time.end_time.isoformat()
})
restaurant_data['main_schedule'] = {
'name': restaurant.main_schedule.name,
'id': restaurant.id,
'open_times': open_times
}
special_schedules = list()
for schedule in restaurant.special_schedules.all():
open_times = list()
for time in schedule.open_times.all():
open_times.append({
'start_day': time.start_day,
'start_time': time.start_time.isoformat(),
'end_day': time.end_day,
'end_time': time.end_time.isoformat()
})
special_schedules.append({
'name': schedule.name,
'id': restaurant.id,
'start': schedule.valid_start.isoformat(),
'end': schedule.valid_end.isoformat(),
'open_times': open_times
})
restaurant_data['special_schedules'] = special_schedules
restaurants.append(restaurant_data)
return restaurants
from django.template import RequestContext from django.template import RequestContext
from website.models import Restaurant, OpenTime, BaseModel, export_data from website.models import Restaurant, OpenTime, BaseModel
from website.json import export_data
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.http import HttpResponse from django.http import HttpResponse
from django.views.decorators.http import condition from django.views.decorators.http import condition
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment