def view_playlist(request, child_id=None, **kwargs): # can be optimized to do a single SQL query to the database to pull adult_child relations # and a single call to get all friends (cached to memcached) my_view_children = None can_edit_child_playlist = False child = None cv = None if child_id: if not re.match('^[0-9]+$',child_id): raise Exception('Invalid input') try: child = Child.objects.select_related('photo','album','school').get(id=child_id) except Child.DoesNotExist: raise Exception("Invalid input") my_child = False if child is not None: cv = ChildView(user=request.user, child=child) if not cv.can_view_child_playlist: raise Exception("You do not have permissions for this") if cv.is_child_mine: my_child = True profile = request.user.get_profile() if child is None or my_child == True: my_view_children = get_cv_list_from_ac(request.user, profile.view_playlist_children) if child is None: child = my_view_children[0].child cv = my_view_children[0] my_child = True if cv is None: cv = ChildView(user=request.user, child=child) my_edit_children = get_cv_list_from_ac(request.user, profile.edit_playlist_children) cat_friends = False if my_child: cat_friends = True, ctx = { 'profile': profile, 'current_child': cv, 'my_view_children': my_view_children, 'my_edit_children':my_edit_children, 'my_child':my_child, 'cat_friends':cat_friends, } template = 'friends/view_playlist.html' return render_to_response(template, RequestContext(request, ctx))
def view_playlist(request, child_id=None, **kwargs): # can be optimized to do a single SQL query to the database to pull adult_child relations # and a single call to get all friends (cached to memcached) my_view_children = None can_edit_child_playlist = False child = None cv = None if child_id: if not re.match("^[0-9]+$", child_id): raise Exception("Invalid input") try: child = Child.objects.select_related("photo", "album", "school").get(id=child_id) except Child.DoesNotExist: raise Exception("Invalid input") my_child = False if child is not None: cv = ChildView(user=request.user, child=child) if not cv.can_view_child_playlist: raise Exception("You do not have permissions for this") if cv.is_child_mine: my_child = True profile = request.user.get_profile() if child is None or my_child == True: my_view_children = get_cv_list_from_ac(request.user, profile.view_playlist_children) if child is None: child = my_view_children[0].child cv = my_view_children[0] my_child = True if cv is None: cv = ChildView(user=request.user, child=child) my_edit_children = get_cv_list_from_ac(request.user, profile.edit_playlist_children) cat_friends = False if my_child: cat_friends = (True,) ctx = { "profile": profile, "current_child": cv, "my_view_children": my_view_children, "my_edit_children": my_edit_children, "my_child": my_child, "cat_friends": cat_friends, } template = "friends/view_playlist.html" return render_to_response(template, RequestContext(request, ctx))
def suggested_friends(request, child_id = None): children = None can_manage_child_playlist = False child = None manage_playlist_children = None cv = None if child_id: if not re.match('^[0-9]+$',child_id): raise Exception('Invalid input') try: child = Child.objects.select_related('photo','album','school').get(id=child_id) except Child.DoesNotExist: raise Exception("Invalid input") if child is not None: cv = ChildView(user=request.user, child=child) if not cv.can_edit_child_playlist: raise Exception("You do not have permissions for this") if cv.is_child_mine: my_child = True if child is None or my_child == True: manage_playlist_children = request.user.get_profile().manage_playlist_children if child is None: child = manage_playlist_children[0].child if manage_playlist_children is None: manage_playlist_children = request.user.get_profile().manage_playlist_children if cv is None: cv = ChildView(user=request.user, child=child) manage_playlist_children = get_cv_list_from_ac(request.user, manage_playlist_children) friend_suggestion_list = list(FriendSuggestion.objects.cache().select_related('child','child__photo','child__album','suggested_child','suggested_child__photo','suggested_child__school','suggested_child__album').filter(child=child, active=True).all()[:10]) # child_list = [] # for sf in friend_suggestion_list: # child_list.append(sf.suggested_child) suggested_list = create_list_of_children_and_parents(request, friend_suggestion_list) # tolog(str(cv.get_profile())) ctx = { 'suggested_list': suggested_list, 'current_child': cv, 'manage_playlist_children': manage_playlist_children, 'profile': request.user.get_profile(), 'cat_friends': True, } template = 'friends/suggested_friends.html' return render_to_response(template, RequestContext(request, ctx))
def view_calendar(request, child_id=None, periods=None, template="schedule/calendar.html"): children = None can_edit_child_schedule = False child = None view_schedule_children = None if child_id: if not re.match('^[0-9]+$', child_id): raise Exception('Invalid input') try: child = Child.objects.select_related('album', 'photo', 'school').get(id=child_id) except Child.DoesNotExist: raise Exception("Invalid input") my_child = False if child is not None: cv = ChildView(user=request.user, child=child) if not cv.can_view_child_schedule: raise Exception("You do not have permissions for this") if cv.is_child_mine: my_child = True if child is None or my_child == True: view_schedule_children = request.user.get_profile( ).view_schedule_children if child is None: child = view_schedule_children[0].child cv = ChildView(user=request.user, child=child) date = datetime.now() if view_schedule_children is None: view_schedule_children = request.user.get_profile( ).view_schedule_children view_schedule_children = get_cv_list_from_ac(request.user, view_schedule_children) ctx = { 'current_child': cv, 'view_schedule_children': view_schedule_children, 'date': date, } template = 'schedule/calendar.html' return render_to_response(template, RequestContext(request, ctx))
def view_calendar(request, child_id = None, periods=None, template="schedule/calendar.html"): children = None can_edit_child_schedule = False child = None view_schedule_children = None if child_id: if not re.match('^[0-9]+$',child_id): raise Exception('Invalid input') try: child = Child.objects.select_related('album','photo','school').get(id=child_id) except Child.DoesNotExist: raise Exception("Invalid input") my_child = False if child is not None: cv = ChildView(user=request.user, child=child) if not cv.can_view_child_schedule: raise Exception("You do not have permissions for this") if cv.is_child_mine: my_child = True if child is None or my_child == True: view_schedule_children = request.user.get_profile().view_schedule_children if child is None: child = view_schedule_children[0].child cv = ChildView(user=request.user, child=child) date = datetime.now() if view_schedule_children is None: view_schedule_children = request.user.get_profile().view_schedule_children view_schedule_children = get_cv_list_from_ac(request.user, view_schedule_children) ctx = { 'current_child': cv, 'view_schedule_children': view_schedule_children, 'date': date, } template = 'schedule/calendar.html' return render_to_response(template, RequestContext(request, ctx))
def list_playdates(request, child_id = None): children = None child = None view_schedule_children = None cv = None if child_id is not None: if not re.match('^[0-9]+$',child_id): raise Exception('Invalid input') try: child = Child.objects.select_related('album','photo','school').get(id=child_id) cv = ChildView(user=request.user, child=child) if not cv.can_view_child_schedule: raise Exception("You do not have permissions for this") if cv.is_child_mine: my_child = True except Child.DoesNotExist: raise Exception("Invalid input") all_friends = [] children = [] avail_list_ini = [] if child is None or my_child == True: view_schedule_children = request.user.get_profile().view_schedule_children if child is None: for vsc in view_schedule_children: children.append(vsc.child) all_friends = all_friends + vsc.child.friends my_child = True else: all_friends = child.friends children.append(child) max = int(request.GET.get("view_more", 4)) more = None view_more = None pdis = [] avail_list_ini = [] pdis = list(PlaydateInviteUser.objects.select_related('playdate','playdate__event').cache().filter(to_child__in=children).all()) pdis = sorted(pdis, compare_pd) if all_friends: avail_list_ini = list(EventPlan.objects.select_related('child','event').cache().filter(event__start__gte=datetime.now(),status='2',child__in=all_friends).order_by('event__start').all()[:max+1]) avail_list = [] iterator = 1 for avail in avail_list_ini: if iterator > max: more = True view_more = max + 4 break; iterator = iterator + 1 avail_cv = ChildView(user=request.user, child=avail.child) if avail_cv.can_view_child_schedule: avail_list.append({ 'avail':avail, 'childview':avail_cv }) playdates = [] view_schedule_children = get_cv_list_from_ac(request.user, view_schedule_children) pd_seen = {} for pdi in pdis: if not str(pdi.playdate_id) in pd_seen: playdates.append({ 'playdate': pdi.playdate, 'invites':invites_cv(pdi.playdate, request)}) pd_seen[str(pdi.playdate_id)] = True ctx = { 'view_schedule_children':view_schedule_children, 'current_child':cv, 'my_child':my_child, 'playdates':playdates, 'avail_list':avail_list, 'cat_playdates': True, 'more':more, 'view_more':view_more, } template = 'playdates/list_playdates.html' return render_to_response(template, RequestContext(request, ctx))
def new_playdate(request, key = None, start = None, end = None, **kwargs): template = 'playdates/new_playdate.html' edit_schedule_children = get_cv_list_from_ac(request.user, request.user.get_profile().edit_schedule_children) single_child = False if len(edit_schedule_children) == 1: single_child = True ctx = {} record = None oc = None start_date = '' start_time = '' end_time = '' if start is not None: todebug("start is not none") start_dt = dt_from_epoch(start) end_dt = dt_from_epoch(end) start_date = start_dt.strftime("%m/%d/%Y") start_time = start_dt.strftime("%I:%M%p") end_time = end_dt.strftime("%I:%M%p") todebug(start_time) todebug(end_time) todebug(start_date) if key is not None: if re.match('^[0-9]+_[0-9]+_[0-9]+$',key): parts = key.split('_') # key = str(which_child_friend_id) + '_' + str(parent_id) + '_' + str(self.child.id) oc = parts[0] child_id = parts[2] child = Child.objects.get(id=child_id) cv = create_childview(user=request.user, child=child) name = cv.profile["name"] if len(name) > 15: name = name[:15] + '...' record = { 'name': name, 'tip': cv.profile["name"], 'small_profile_pic': cv.profile["small_profile_pic"], 'key':key } elif re.match('^fb_[0-9]+$',key): #fb id parts = key.split('_') fb_contact_id = parts[1] fbc = ContactFB.objects.get(owner=request.user, id=int(fb_contact_id)) name = fbc.name if len(name) > 15: name = name[:15] + '..' record = { 'key':key, 'name':name, 'tip':fbc.name, 'small_profile_pic':'http://graph.facebook.com/'+ str(fbc.facebook_id) +'/picture?type=square' } elif re.match('^ce_[0-9]+$',key): parts = key.split('_') contact_id = parts[1] c = ContactEmail.objects.get(owner=request.user, id=contact_id) name = c.email if len(name) > 15: name = name[:15] + '..' record = { 'key': c.email, 'name': name, 'tip': c.email, } else: todebug("not matching nothing") if request.method == "POST": post = request.POST errors = [] if (post.get(u'dropoff',None) == 'yes'): dropoff = True else: dropoff = False min_participation = None max_participation = None expire_option = None new_loc_name = post.get(u'new_loc_name') address = post.get(u'address') ctx.update({ address: address }) details = post.get(u'details') # phone validation phone = post.get(u'phone') if not re.match('^[0-9\s\(\)\-]+$',phone): errors.append('phone contains invalid characters') ctx.update({ phone: phone }) activity = post.get(u'activity') if not re.match('^[0-9]+$',activity): raise Exception('invalid playdate activity') activity = PDActivity.objects.get(id=activity) # figure out how to have multiple organizer children organizer_child = post.getlist(u'organizer_child') invitees = post.getlist(u'invitee') # TODO validate invitees, organizer_child # date manipulation date_str = post.get(u'date') time_start_str = post.get(u'time_start') time_end_str = post.get(u'time_end') date_good = True if not re.match('^\d{1,2}/\d{1,2}/\d{4}$', date_str): errors.append("date not selected or is invalid") date_good = False if not re.match('^\d{1,2}:\d{2}\w{2}$', time_start_str): errors.append("start time not selected or is invalid") date_good = False if not re.match('^\d{1,2}:\d{2}\w{2}$', time_end_str): errors.append("end time not selected or is invalid") date_good = False if date_good: when_str = date_str + time_start_str when = datetime.strptime(when_str, '%m/%d/%Y%I:%M%p') until_str = date_str + time_end_str until = datetime.strptime(until_str, '%m/%d/%Y%I:%M%p') child_id = organizer_child[0] child = Child.objects.get(id=child_id) child_invite_design = child.default_invite if len(errors) > 0: tolog(str(errors)) ctx.update({ 'errors': errors }) else: pd = Playdate() pd.organizer = request.user pd.phone = phone # save phone for later profile = request.user.get_profile() profile.phone = phone profile.save() pd.details = details pd.address = address pd.when_from = when pd.when_until = until pd.is_dropoff = dropoff pd.max_participation = max_participation pd.min_participation = min_participation pd.expire_option = expire_option pd.invite_design = child_invite_design pd.activity = activity pd.save() ev = create_event(pd.when_from, pd.when_until, pd) if ((new_loc_name is not None) and (len(new_loc_name) > 0)): nl = Place(owner=request.user, name=new_loc_name, address=address) nl.save() child = None for child_id in organizer_child: if re.match('^[0-9]+$',child_id): child = Child.objects.get(id=child_id) pdi = PlaydateInviteUser() pdi.playdate = pd pdi.organizer_child = child pdi.to_child = child pdi.to_user = request.user pdi.phone = phone pdi.accept() create_eventplan(pdi.to_child, ev, "4") for invitee in invitees: if re.match('^[0-9]+_[0-9]+_[0-9]+$',invitee): # user id data_parts=invitee.split('_') pdi = PlaydateInviteUser() pdi.playdate = pd pdi.organizer_child=Child.objects.get(id=data_parts[0]) pdi.to_user=User.objects.get(id=data_parts[1]) pdi.to_child=Child.objects.get(id=data_parts[2]) pdi.save_and_invite() create_eventplan(pdi.to_child, ev, "4") elif re.match('^fb_[0-9]+$',invitee): #fb id data_parts=invitee.split('_') pdf = PlaydateInviteFB() pdf.playdate = pd pdf.organizer_child=child fbc = ContactFB.objects.get(owner=request.user, id=int(data_parts[1])) fbc.invited = True fbc.save() pdf.facebook_contact_id = int(data_parts[1]) pdf.save_and_invite() elif is_valid_email(invitee): pde = PlaydateInviteEmail() pde.playdate = pd pde.organizer_child=child pde.email = invitee pde.token = pde.assign_token() pde.save_and_invite() try: obj = ContactEmail.objects.get(owner=request.user, email=invitee) obj.invited=True obj.save() except ContactEmail.DoesNotExist: obj = ContactEmail(owner=request.user, email=invitee, invited=True) obj.save() request.session["event"] = 'Created a Playdate' return HttpResponseRedirect(reverse("view_playdate", kwargs={"playdate_id":pd.id})) places = list(request.user.places.all()) activities = list(PDActivity.objects.all()) children_without_default_designs = [] for cv in edit_schedule_children: if cv.child.default_invite is None: children_without_default_designs.append(cv) phone = request.user.get_profile().phone ctx.update( { 'edit_schedule_children':edit_schedule_children, 'places':places, 'children_without_default_designs': children_without_default_designs, 'phone':phone, 'single_child':single_child, 'activities':activities, 'fb_app_id':settings.FB_API_KEY, 'key':key, 'record':simplejson.dumps(record, cls=PDEncoder), 'oc':oc, 'start_date': start_date, 'start_time': start_time, 'end_time' : end_time, 'message': request.session.pop("message", None), }) return render_to_response(template, RequestContext(request, ctx))
def list_playdates(request, child_id=None): children = None child = None view_schedule_children = None cv = None if child_id is not None: if not re.match('^[0-9]+$', child_id): raise Exception('Invalid input') try: child = Child.objects.select_related('album', 'photo', 'school').get(id=child_id) cv = ChildView(user=request.user, child=child) if not cv.can_view_child_schedule: raise Exception("You do not have permissions for this") if cv.is_child_mine: my_child = True except Child.DoesNotExist: raise Exception("Invalid input") all_friends = [] children = [] avail_list_ini = [] if child is None or my_child == True: view_schedule_children = request.user.get_profile( ).view_schedule_children if child is None: for vsc in view_schedule_children: children.append(vsc.child) all_friends = all_friends + vsc.child.friends my_child = True else: all_friends = child.friends children.append(child) max = int(request.GET.get("view_more", 4)) more = None view_more = None pdis = [] avail_list_ini = [] pdis = list( PlaydateInviteUser.objects.select_related( 'playdate', 'playdate__event').cache().filter(to_child__in=children).all()) pdis = sorted(pdis, compare_pd) if all_friends: avail_list_ini = list( EventPlan.objects.select_related('child', 'event').cache().filter( event__start__gte=datetime.now(), status='2', child__in=all_friends).order_by('event__start').all()[:max + 1]) avail_list = [] iterator = 1 for avail in avail_list_ini: if iterator > max: more = True view_more = max + 4 break iterator = iterator + 1 avail_cv = ChildView(user=request.user, child=avail.child) if avail_cv.can_view_child_schedule: avail_list.append({'avail': avail, 'childview': avail_cv}) playdates = [] view_schedule_children = get_cv_list_from_ac(request.user, view_schedule_children) pd_seen = {} for pdi in pdis: if not str(pdi.playdate_id) in pd_seen: playdates.append({ 'playdate': pdi.playdate, 'invites': invites_cv(pdi.playdate, request) }) pd_seen[str(pdi.playdate_id)] = True ctx = { 'view_schedule_children': view_schedule_children, 'current_child': cv, 'my_child': my_child, 'playdates': playdates, 'avail_list': avail_list, 'cat_playdates': True, 'more': more, 'view_more': view_more, } template = 'playdates/list_playdates.html' return render_to_response(template, RequestContext(request, ctx))
def new_playdate(request, key=None, start=None, end=None, **kwargs): template = 'playdates/new_playdate.html' edit_schedule_children = get_cv_list_from_ac( request.user, request.user.get_profile().edit_schedule_children) single_child = False if len(edit_schedule_children) == 1: single_child = True ctx = {} record = None oc = None start_date = '' start_time = '' end_time = '' if start is not None: todebug("start is not none") start_dt = dt_from_epoch(start) end_dt = dt_from_epoch(end) start_date = start_dt.strftime("%m/%d/%Y") start_time = start_dt.strftime("%I:%M%p") end_time = end_dt.strftime("%I:%M%p") todebug(start_time) todebug(end_time) todebug(start_date) if key is not None: if re.match('^[0-9]+_[0-9]+_[0-9]+$', key): parts = key.split('_') # key = str(which_child_friend_id) + '_' + str(parent_id) + '_' + str(self.child.id) oc = parts[0] child_id = parts[2] child = Child.objects.get(id=child_id) cv = create_childview(user=request.user, child=child) name = cv.profile["name"] if len(name) > 15: name = name[:15] + '...' record = { 'name': name, 'tip': cv.profile["name"], 'small_profile_pic': cv.profile["small_profile_pic"], 'key': key } elif re.match('^fb_[0-9]+$', key): #fb id parts = key.split('_') fb_contact_id = parts[1] fbc = ContactFB.objects.get(owner=request.user, id=int(fb_contact_id)) name = fbc.name if len(name) > 15: name = name[:15] + '..' record = { 'key': key, 'name': name, 'tip': fbc.name, 'small_profile_pic': 'http://graph.facebook.com/' + str(fbc.facebook_id) + '/picture?type=square' } elif re.match('^ce_[0-9]+$', key): parts = key.split('_') contact_id = parts[1] c = ContactEmail.objects.get(owner=request.user, id=contact_id) name = c.email if len(name) > 15: name = name[:15] + '..' record = { 'key': c.email, 'name': name, 'tip': c.email, } else: todebug("not matching nothing") if request.method == "POST": post = request.POST errors = [] if (post.get(u'dropoff', None) == 'yes'): dropoff = True else: dropoff = False min_participation = None max_participation = None expire_option = None new_loc_name = post.get(u'new_loc_name') address = post.get(u'address') ctx.update({address: address}) details = post.get(u'details') # phone validation phone = post.get(u'phone') if not re.match('^[0-9\s\(\)\-]+$', phone): errors.append('phone contains invalid characters') ctx.update({phone: phone}) activity = post.get(u'activity') if not re.match('^[0-9]+$', activity): raise Exception('invalid playdate activity') activity = PDActivity.objects.get(id=activity) # figure out how to have multiple organizer children organizer_child = post.getlist(u'organizer_child') invitees = post.getlist(u'invitee') # TODO validate invitees, organizer_child # date manipulation date_str = post.get(u'date') time_start_str = post.get(u'time_start') time_end_str = post.get(u'time_end') date_good = True if not re.match('^\d{1,2}/\d{1,2}/\d{4}$', date_str): errors.append("date not selected or is invalid") date_good = False if not re.match('^\d{1,2}:\d{2}\w{2}$', time_start_str): errors.append("start time not selected or is invalid") date_good = False if not re.match('^\d{1,2}:\d{2}\w{2}$', time_end_str): errors.append("end time not selected or is invalid") date_good = False if date_good: when_str = date_str + time_start_str when = datetime.strptime(when_str, '%m/%d/%Y%I:%M%p') until_str = date_str + time_end_str until = datetime.strptime(until_str, '%m/%d/%Y%I:%M%p') child_id = organizer_child[0] child = Child.objects.get(id=child_id) child_invite_design = child.default_invite if len(errors) > 0: tolog(str(errors)) ctx.update({'errors': errors}) else: pd = Playdate() pd.organizer = request.user pd.phone = phone # save phone for later profile = request.user.get_profile() profile.phone = phone profile.save() pd.details = details pd.address = address pd.when_from = when pd.when_until = until pd.is_dropoff = dropoff pd.max_participation = max_participation pd.min_participation = min_participation pd.expire_option = expire_option pd.invite_design = child_invite_design pd.activity = activity pd.save() ev = create_event(pd.when_from, pd.when_until, pd) if ((new_loc_name is not None) and (len(new_loc_name) > 0)): nl = Place(owner=request.user, name=new_loc_name, address=address) nl.save() child = None for child_id in organizer_child: if re.match('^[0-9]+$', child_id): child = Child.objects.get(id=child_id) pdi = PlaydateInviteUser() pdi.playdate = pd pdi.organizer_child = child pdi.to_child = child pdi.to_user = request.user pdi.phone = phone pdi.accept() create_eventplan(pdi.to_child, ev, "4") for invitee in invitees: if re.match('^[0-9]+_[0-9]+_[0-9]+$', invitee): # user id data_parts = invitee.split('_') pdi = PlaydateInviteUser() pdi.playdate = pd pdi.organizer_child = Child.objects.get(id=data_parts[0]) pdi.to_user = User.objects.get(id=data_parts[1]) pdi.to_child = Child.objects.get(id=data_parts[2]) pdi.save_and_invite() create_eventplan(pdi.to_child, ev, "4") elif re.match('^fb_[0-9]+$', invitee): #fb id data_parts = invitee.split('_') pdf = PlaydateInviteFB() pdf.playdate = pd pdf.organizer_child = child fbc = ContactFB.objects.get(owner=request.user, id=int(data_parts[1])) fbc.invited = True fbc.save() pdf.facebook_contact_id = int(data_parts[1]) pdf.save_and_invite() elif is_valid_email(invitee): pde = PlaydateInviteEmail() pde.playdate = pd pde.organizer_child = child pde.email = invitee pde.token = pde.assign_token() pde.save_and_invite() try: obj = ContactEmail.objects.get(owner=request.user, email=invitee) obj.invited = True obj.save() except ContactEmail.DoesNotExist: obj = ContactEmail(owner=request.user, email=invitee, invited=True) obj.save() request.session["event"] = 'Created a Playdate' return HttpResponseRedirect( reverse("view_playdate", kwargs={"playdate_id": pd.id})) places = list(request.user.places.all()) activities = list(PDActivity.objects.all()) children_without_default_designs = [] for cv in edit_schedule_children: if cv.child.default_invite is None: children_without_default_designs.append(cv) phone = request.user.get_profile().phone ctx.update({ 'edit_schedule_children': edit_schedule_children, 'places': places, 'children_without_default_designs': children_without_default_designs, 'phone': phone, 'single_child': single_child, 'activities': activities, 'fb_app_id': settings.FB_API_KEY, 'key': key, 'record': simplejson.dumps(record, cls=PDEncoder), 'oc': oc, 'start_date': start_date, 'start_time': start_time, 'end_time': end_time, 'message': request.session.pop("message", None), }) return render_to_response(template, RequestContext(request, ctx))
def home(request, new_user=None): ctx = {} template = 'home/homepage.html' fb_user = False if new_user is not None: new_user = True else: new_user = False my_profile = request.user.get_profile() if new_user: fb_user = my_profile.get_facebook_user() if fb_user is not None: ctx.update({"fb_user": True}) else: ctx.update({"show_addr_book": True}) if "show_addr_book" in request.GET: ctx.update({ "fb_user": False, "show_addr_book": True, }) manage_playlist_children = get_cv_list_from_ac( request.user, my_profile.manage_playlist_children) ctx.update({ "manage_playlist_children": manage_playlist_children, }) start = datetime.now() end = start + timedelta(days=7) if not start.strftime('%B') == end.strftime('%B'): month = start.strftime('%b') + ' - ' + end.strftime('%b') else: month = start.strftime('%B') if not start.strftime('%Y') == end.strftime('%Y'): year = start.strftime('%Y') + ' - ' + end.strftime('%Y') else: year = start.strftime('%Y') # determine day list on homepage -- day_suffix = ['th'] + ['st', 'nd', 'rd'] + 17 * ['th'] + [ 'st', 'nd', 'rd' ] + 7 * ['th'] + ['st'] day_of_week = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ] current_day = start days = [] while not current_day.day == end.day: day = current_day.strftime('%d') days.append({ 'day': day, 'suffix': day_suffix[int(day)], 'dow': day_of_week[current_day.weekday()] }) current_day = current_day + timedelta(days=1) only_child = False view_schedule_children = get_cv_list_from_ac( request.user, my_profile.view_schedule_children) if len(view_schedule_children) == 1: only_child = True current_child_cv = view_schedule_children[0] manage_playlist_children = get_cv_list_from_ac( request.user, my_profile.manage_playlist_children) ctx.update({ 'manage_playlist_children': manage_playlist_children, 'current_child': current_child_cv, 'view_schedule_children': view_schedule_children, 'month': month, 'year': year, 'days': days, 'updates': request.user.updates.cache().select_related('update').filter( update__deleted='0')[:10], 'timestamp': int(time.time()), 'new_user': new_user, 'cat_home': True, 'fb_app_id': settings.FB_API_KEY, 'www_host': settings.WWW_HOST, 'only_child': only_child, }) return render_to_response(template, RequestContext(request, ctx))
def home(request, new_user = None): ctx = {} template = 'home/homepage.html' fb_user=False if new_user is not None: new_user = True else: new_user = False my_profile = request.user.get_profile() if new_user: fb_user = my_profile.get_facebook_user() if fb_user is not None: ctx.update({ "fb_user": True }) else: ctx.update({ "show_addr_book": True }) if "show_addr_book" in request.GET: ctx.update({ "fb_user": False, "show_addr_book": True, }) manage_playlist_children = get_cv_list_from_ac(request.user, my_profile.manage_playlist_children) ctx.update({ "manage_playlist_children": manage_playlist_children, }) start = datetime.now() end = start + timedelta(days=7) if not start.strftime('%B') == end.strftime('%B'): month = start.strftime('%b') + ' - ' + end.strftime('%b') else: month = start.strftime('%B') if not start.strftime('%Y') == end.strftime('%Y'): year = start.strftime('%Y') + ' - ' + end.strftime('%Y') else: year = start.strftime('%Y') # determine day list on homepage -- day_suffix = ['th'] + ['st','nd','rd'] + 17*['th'] + ['st','nd','rd'] + 7*['th'] + ['st'] day_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] current_day = start days = [] while not current_day.day == end.day: day = current_day.strftime('%d') days.append({ 'day': day, 'suffix':day_suffix[int(day)], 'dow':day_of_week[current_day.weekday()] }) current_day = current_day + timedelta(days=1) only_child = False view_schedule_children = get_cv_list_from_ac(request.user, my_profile.view_schedule_children) if len(view_schedule_children) == 1: only_child = True current_child_cv = view_schedule_children[0] manage_playlist_children = get_cv_list_from_ac(request.user, my_profile.manage_playlist_children) ctx.update({ 'manage_playlist_children':manage_playlist_children, 'current_child':current_child_cv, 'view_schedule_children':view_schedule_children, 'month':month, 'year':year, 'days':days, 'updates': request.user.updates.cache().select_related('update').filter(update__deleted='0')[:10], 'timestamp': int(time.time()), 'new_user':new_user, 'cat_home': True, 'fb_app_id': settings.FB_API_KEY, 'www_host': settings.WWW_HOST, 'only_child':only_child, }) return render_to_response(template, RequestContext(request, ctx))
def suggested_friends(request, child_id=None): children = None can_manage_child_playlist = False child = None manage_playlist_children = None cv = None if child_id: if not re.match("^[0-9]+$", child_id): raise Exception("Invalid input") try: child = Child.objects.select_related("photo", "album", "school").get(id=child_id) except Child.DoesNotExist: raise Exception("Invalid input") if child is not None: cv = ChildView(user=request.user, child=child) if not cv.can_edit_child_playlist: raise Exception("You do not have permissions for this") if cv.is_child_mine: my_child = True if child is None or my_child == True: manage_playlist_children = request.user.get_profile().manage_playlist_children if child is None: child = manage_playlist_children[0].child if manage_playlist_children is None: manage_playlist_children = request.user.get_profile().manage_playlist_children if cv is None: cv = ChildView(user=request.user, child=child) manage_playlist_children = get_cv_list_from_ac(request.user, manage_playlist_children) friend_suggestion_list = list( FriendSuggestion.objects.cache() .select_related( "child", "child__photo", "child__album", "suggested_child", "suggested_child__photo", "suggested_child__school", "suggested_child__album", ) .filter(child=child, active=True) .all()[:10] ) # child_list = [] # for sf in friend_suggestion_list: # child_list.append(sf.suggested_child) suggested_list = create_list_of_children_and_parents(request, friend_suggestion_list) # tolog(str(cv.get_profile())) ctx = { "suggested_list": suggested_list, "current_child": cv, "manage_playlist_children": manage_playlist_children, "profile": request.user.get_profile(), "cat_friends": True, } template = "friends/suggested_friends.html" return render_to_response(template, RequestContext(request, ctx))