def accept_invitation(invite): """ Accept an invitation """ if invite.rsvp_referrer != None: if invite.rsvp_type != "Accepted": if invite.rsvp_event.deadlineOkay(): if invite.rsvp_event.moreOkay(): invite.rsvp_type = "Accepted" invite.rsvp_reminder_enabled = True invite.rsvp_event.event_attendee_count = invite.rsvp_event.event_attendee_count + 1 invite.rsvp_event.save() invite.save() MsgMgr.sendmsg( invite.rsvp_referrer, "%s has accepted your invitation to '%s.'" % (invite.rsvp_user.full_name(), invite.rsvp_event.displayname()), ) return Msg("You've accepted %s's invitation." % (invite.rsvp_referrer.casual_name()), 1) else: return Msg("We're sorry, but the maximum attendance for this event has been reached.", 0) else: return Msg("We're sorry, but the deadline for confirming attendance to this event has passed.", 0) else: return Msg("You've already accepted %s's invitation." % (invite.rsvp_referrer.casual_name()), 2) else: return Msg("You can't accept an invitation without a sender.", 0)
def accept_invitation(invite): """ Accept an invitation """ if invite.rsvp_referrer != None: if invite.rsvp_type != 'Accepted': if invite.rsvp_event.deadlineOkay(): if invite.rsvp_event.moreOkay(): invite.rsvp_type = 'Accepted' invite.rsvp_reminder_enabled = True invite.rsvp_event.event_attendee_count = invite.rsvp_event.event_attendee_count + 1 invite.rsvp_event.save() invite.save() MsgMgr.sendmsg( invite.rsvp_referrer, '%s has accepted your invitation to \'%s.\'' % (invite.rsvp_user.full_name(), invite.rsvp_event.displayname())) return Msg( 'You\'ve accepted %s\'s invitation.' % (invite.rsvp_referrer.casual_name()), 1) else: return Msg( 'We\'re sorry, but the maximum attendance for this event has been reached.', 0) else: return Msg( 'We\'re sorry, but the deadline for confirming attendance to this event has passed.', 0) else: return Msg( 'You\'ve already accepted %s\'s invitation.' % (invite.rsvp_referrer.casual_name()), 2) else: return Msg('You can\'t accept an invitation without a sender.', 0)
def logout(request): """ Log out the user (but keep other session info) """ try: del request.session['user_data'] except: pass MsgMgr.push(request, 'You have successfully been logged out.', 1) lurl = cas_url + 'logout?' + urlencode({'service': our_site}) return HttpResponseRedirect(lurl)
def notify_other_posters(message): """ Notify other users who posted on a message board previously that there's a new post """ cluster = message.boardmessage_eventcluster messages = BoardMessage.objects.filter(boardmessage_eventcluster=cluster) posters = [] for msg in messages: posters.append(msg.boardmessage_poster) posterset = set(posters) for usr in posterset: if usr != message.boardmessage_poster: MsgMgr.sendmsg( usr, '%s has just posted a reply to "%s."' % (message.boardmessage_poster.full_name(), cluster.cluster_title))
def notify_other_posters(message): """ Notify other users who posted on a message board previously that there's a new post """ cluster = message.boardmessage_eventcluster messages = BoardMessage.objects.filter(boardmessage_eventcluster=cluster) posters = [] for msg in messages: posters.append(msg.boardmessage_poster) posterset = set(posters) for usr in posterset: if usr != message.boardmessage_poster: MsgMgr.sendmsg( usr, '%s has just posted a reply to "%s."' % (message.boardmessage_poster.full_name(), cluster.cluster_title), )
def render_to_response(request, template, out_dict): """ Load context with common parts of each page. Includes: - User data for top bar - Hot/new events for bottom spotlight """ user = current_user(request) if user: out_dict['user_data'] = user # Top menu out_dict['n_my_events'] = query.count_rsvps(user, 'Accepted') out_dict['n_my_invites'] = query.count_rsvps(user, 'Pending') out_dict['unread_msgs'] = UserMessage.objects.filter(um_user=user, um_date_read=None) # Bottom spotlight out_dict['my_viewed'] = query.events_myviewed(user, limit=3, group=False) # ??? out_dict['v_messages'] = MsgMgr.iterable(request) # Bottom spotlight out_dict['hot_events'] = query.events_hot(limit=3, group=False) out_dict['new_events'] = query.events_new(limit=3, group=False) #out_dict['our_site'] = our_site #Msg('This site will be undergoing planned maintenance tonight. Sorry for any inconvenience.',1).push(request) return shortcuts.render_to_response(template, out_dict)
def send_invite(sender, recipient, event): """ Send an invitation to a user """ if sender and recipient and event: try: dup = RSVP.objects.get(rsvp_user=recipient, rsvp_event=event) except: dup = None if dup == None: invite = RSVP(rsvp_user=recipient, rsvp_event=event, rsvp_referrer=sender, rsvp_reminder_enabled=False, rsvp_type='Pending') invite.save() email_invite(recipient, sender, event, invite) MsgMgr.sendmsg( recipient, '%s just invited you to %s' % (sender.full_name(), event.displayname())) if sender == recipient: return Msg( 'You\'ve successfully sent an invitation to yourself. Lonely, huh?', 1) else: return Msg( 'You\'ve successfully sent an invitation to %s.' % (recipient.casual_name()), 1) elif dup.rsvp_referrer == sender: return Msg( '''You have already sent an identical invitation to %s.''' % (recipient.casual_name()), 0) elif dup.rsvp_referrer != sender: if dup.rsvp_type == 'Accepted': return Msg( '''%s is already going to this event. No new invitation was sent.''' % (recipient.casual_name()), 0) else: return Msg( '''Someone else has already invited %s to this event. No new invitation was sent.''' % (recipient.casual_name()), 0) else: return Msg('Malformed invitation.', 0)
def send_invite(sender, recipient, event): """ Send an invitation to a user """ if sender and recipient and event: try: dup = RSVP.objects.get(rsvp_user=recipient, rsvp_event=event) except: dup = None if dup == None: invite = RSVP( rsvp_user=recipient, rsvp_event=event, rsvp_referrer=sender, rsvp_reminder_enabled=False, rsvp_type="Pending", ) invite.save() email_invite(recipient, sender, event, invite) MsgMgr.sendmsg(recipient, "%s just invited you to %s" % (sender.full_name(), event.displayname())) if sender == recipient: return Msg("You've successfully sent an invitation to yourself. Lonely, huh?", 1) else: return Msg("You've successfully sent an invitation to %s." % (recipient.casual_name()), 1) elif dup.rsvp_referrer == sender: return Msg("""You have already sent an identical invitation to %s.""" % (recipient.casual_name()), 0) elif dup.rsvp_referrer != sender: if dup.rsvp_type == "Accepted": return Msg( """%s is already going to this event. No new invitation was sent.""" % (recipient.casual_name()), 0 ) else: return Msg( """Someone else has already invited %s to this event. No new invitation was sent.""" % (recipient.casual_name()), 0, ) else: return Msg("Malformed invitation.", 0)
def render_to_response(request, template, dict): """ Process every page's common parts """ if 'user_data' in request.session: dict['user_data'] = request.session['user_data'] #My Events Rightcol user_rsvps = RSVP.objects.filter(rsvp_user=dict['user_data'],rsvp_event__event_date_time_start__gte=datetime.now(),rsvp_type='Accepted').order_by('rsvp_event__event_date_time_start')[0:2] first_events = [] for rsvp in user_rsvps: first_events.append(rsvp.rsvp_event) dict['my_events'] = first_events views = View.objects.filter(view_viewer = dict['user_data']).order_by('view_date_time')[0:3].reverse() recently_viewed = [] for view in views: recently_viewed.append(view.view_event) # dict['recently_viewed'] = dict['user_data'].user_recently_viewed_events.all()[0:3] dict['recently_viewed'] = recently_viewed #My Invitations Righcol user_invites = RSVP.objects.filter(rsvp_user=dict['user_data'],rsvp_event__event_date_time_start__gte=datetime.now(),rsvp_type='Pending').order_by('rsvp_event__event_date_time_start') # upcoming_invites = [] # for rsvp in user_invites: # upcoming_invites.append(rsvp.rsvp_event) dict['my_invites'] = user_invites dict['my_invites_right'] = user_invites[0:2] umsgs = UserMessage.objects.filter(um_user = dict['user_data'], um_date_read = None) dict['umsgs'] = umsgs dict['n_ur_messages'] = umsgs.count() else: dict['showrightcol'] = False path = request.path if path == '/': dict['front'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' elif path == '/today': dict['today'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' elif path == '/week': dict['week'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' elif path == '/weekend': dict['weekend'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' elif path == '/all': dict['all'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' else: dict['lavanone'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' #Hot Events Spotlight hot_events = Event.objects.exclude(event_date_time_start=dtdeleteflag).filter(event_date_time_end__gte=datetime.now()).order_by('event_attendee_count')[0:3].reverse() dict['hot_events'] = hot_events #Recently Added Spotlight recently_added = Event.objects.exclude(event_date_time_start=dtdeleteflag).order_by('event_date_time_created')[0:3].reverse() dict['recently_added'] = recently_added dict['v_messages'] = MsgMgr.iterable(request) if not 'showrightcol' in dict: dict['showrightcol'] = True dict['our_site'] = our_site # Msg('This site will be undergoing planned maintenance tonight. Sorry for any inconvenience.',1).push(request) return shortcuts.render_to_response(template, dict)
def render_to_response(request, template, dict): """ Process every page's common parts """ if 'user_data' in request.session: dict['user_data'] = request.session['user_data'] #My Events Rightcol user_rsvps = RSVP.objects.filter( rsvp_user=dict['user_data'], rsvp_event__event_date_time_start__gte=datetime.now(), rsvp_type='Accepted').order_by( 'rsvp_event__event_date_time_start')[0:2] first_events = [] for rsvp in user_rsvps: first_events.append(rsvp.rsvp_event) dict['my_events'] = first_events views = View.objects.filter(view_viewer=dict['user_data']).order_by( 'view_date_time')[0:3].reverse() recently_viewed = [] for view in views: recently_viewed.append(view.view_event) # dict['recently_viewed'] = dict['user_data'].user_recently_viewed_events.all()[0:3] dict['recently_viewed'] = recently_viewed #My Invitations Righcol user_invites = RSVP.objects.filter( rsvp_user=dict['user_data'], rsvp_event__event_date_time_start__gte=datetime.now(), rsvp_type='Pending').order_by('rsvp_event__event_date_time_start') # upcoming_invites = [] # for rsvp in user_invites: # upcoming_invites.append(rsvp.rsvp_event) dict['my_invites'] = user_invites dict['my_invites_right'] = user_invites[0:2] umsgs = UserMessage.objects.filter(um_user=dict['user_data'], um_date_read=None) dict['umsgs'] = umsgs dict['n_ur_messages'] = umsgs.count() else: dict['showrightcol'] = False path = request.path if path == '/': dict['front'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' elif path == '/today': dict['today'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' elif path == '/week': dict['week'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' elif path == '/weekend': dict['weekend'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' elif path == '/all': dict['all'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' else: dict['lavanone'] = ' class="current"' dict['uses_lava'] = ' id="topmenu"' #Hot Events Spotlight hot_events = Event.objects.exclude( event_date_time_start=dtdeleteflag).filter( event_date_time_end__gte=datetime.now()).order_by( 'event_attendee_count')[0:3].reverse() dict['hot_events'] = hot_events #Recently Added Spotlight recently_added = Event.objects.exclude( event_date_time_start=dtdeleteflag).order_by( 'event_date_time_created')[0:3].reverse() dict['recently_added'] = recently_added dict['v_messages'] = MsgMgr.iterable(request) if not 'showrightcol' in dict: dict['showrightcol'] = True dict['our_site'] = our_site # Msg('This site will be undergoing planned maintenance tonight. Sorry for any inconvenience.',1).push(request) return shortcuts.render_to_response(template, dict)
def login(request): """ Conduct login of user using a CAS system """ if request.method == 'GET' and 'ticket' in request.GET: if request.session.test_cookie_worked(): request.session.delete_test_cookie() try: ticket = request.GET.get('ticket', None) params = urllib.urlencode({'service':our_site_validate,'ticket':ticket}) validation = urllib2.urlopen(cas_url+'/validate?'+params).readlines() if len(validation) == 2 and re.match('yes', validation[0]) != None: netid = validation[1].strip() request.session['user_data'] = login_user(netid) if not request.session['user_data'].user_last_login: request.session['user_data'].set_logged_in() MsgMgr.push(request, 'It looks like you\'re new here. Please confirm the information below, and then we\'ll send you along.', 1) #Future Feature: For new users, add tips to top of page for first-time visit MsgMgr.push(request, 'This page will show you updates.',2,msg_to_page='/user/messages') MsgMgr.push(request, 'This page will show you events you\'ve added to your calendar.',2,msg_to_page='/user/events') return HttpResponseRedirect('/user?newbie=True') request.session['user_data'].set_logged_in() MsgMgr.push(request, 'Welcome back, %s!' % (request.session['user_data'].casual_name()), 1) else: MsgMgr.push(request, 'You could not be logged in.', 0) return HttpResponseRedirect("/") if 'login_redirect' in request.session: referrer = request.session['login_redirect'] del request.session['login_redirect'] return HttpResponseRedirect(referrer) else: return HttpResponseRedirect(our_site) except: MsgMgr.push(request, 'Login failed.', 0) return HttpResponseRedirect(our_site) else: return HttpResponseRedirect('/nocookie') else: return login_redirect(request)