def claim_atpostspud(request, spud_id): try: spud = SpudFromSocialMedia.objects.get(id=spud_id) except SpudFromSocialMedia.DoesNotExist: spud = None if spud.state == SpudFromSocialMedia.STATE_ACCEPTED: # Don't allow dupes! spud = None template_data = { 'spud': spud.expanded_data if spud else None, 'spud_id': spud.id if spud else None } if request.method == "POST": action = request.POST.get('action', None) if action == "change_twitter" or action == "set_twitter": new_username = spud.expanded_data['user']['username'] fan = request.current_role.entity fan.twitter = new_username fan.save() controller = SpudsController(request.current_role) controller.add_spud_from_fan(spud) template_data['username_changed'] = action == "change_twitter" template_data['username_set'] = action == "set_twitter" return render_to_response('spudderspuds/pages/claim_atpostspud.html', template_data, context_instance=RequestContext(request))
def claim_atpostspud(request, spud_id): try: spud = SpudFromSocialMedia.objects.get(id=spud_id) except SpudFromSocialMedia.DoesNotExist: spud = None if spud.state == SpudFromSocialMedia.STATE_ACCEPTED: # Don't allow dupes! spud = None template_data = { 'spud': spud.expanded_data if spud else None, 'spud_id': spud.id if spud else None } if request.method == "POST": action = request.POST.get('action', None) if action == "change_twitter" or action == "set_twitter": new_username = spud.expanded_data['user']['username'] fan = request.current_role.entity fan.twitter = new_username fan.save() controller = SpudsController(request.current_role) controller.add_spud_from_fan(spud) template_data['username_changed'] = action == "change_twitter" template_data['username_set'] = action == "set_twitter" return render_to_response( 'spudderspuds/pages/claim_atpostspud.html', template_data, context_instance=RequestContext(request))
def test_spuds(request): template_data = {} if is_fan(request.current_role): stream = SpudsController(request.current_role).get_spud_stream( ) + SpudsController.GetSpudsForFan(request.current_role.entity) # shuffle(stream) template_data['spuds'] = stream return render(request, 'spudderspuds/pages/test_spuds.html', template_data)
def is_signin_claiming_spud(request, fan, twitter, spud_id): if twitter: fan.twitter = twitter fan.save() if spud_id: controller = SpudsController(RoleFan(fan)) spud = SpudFromSocialMedia.objects.get(id=spud_id) controller.add_spud_from_fan(spud) messages.success( request, "You twitter name to <b>%s</b> and you claimed your SPUD!" % twitter)
def view(request, venue_id): venue = Venue.objects.get(pk=venue_id) if request.method == "POST": venue.name = request.POST.get('name', '') venue.aka_name = request.POST.get('aka_name', '') venue.save() role = request.current_role splitted_address = venue.medical_address.split(', ') medical_address = { 'address': splitted_address.pop(0) if splitted_address else '', 'city': splitted_address.pop(0) if splitted_address else '', 'state': splitted_address.pop(0) if splitted_address else '', 'zip': splitted_address.pop(0) if splitted_address else '' } try: student = Student.objects.get(id=role.entity.id) except Student.DoesNotExist: student = False except TypeError: student = False except AttributeError: student = False is_recipient = VenueRecipient.objects.filter(groundskeeper=student) rent_venue_url = False can_edit = request.user.is_authenticated() and ( venue.is_groundskeeper(role) or venue.is_renter(role)) if venue.is_available() and not venue.is_renter(role): rent_venue_url = get_rent_venue_cbui_url(venue) sponsor = venue.renter sponsor_info = False if sponsor: if sponsor.name != "": sponsor_info = True venue_spuds = SpudsController.GetSpudsForVenue(venue) teams = [ team.team_page for team in TeamVenueAssociation.objects.filter(venue=venue) ] return render( request, 'spuddercern/pages/venues_view.html', { 'venue': venue, 'teams': teams, 'medical_address': medical_address, 'is_recipient': is_recipient, 'rent_venue_url': rent_venue_url, 'sponsor': sponsor, 'sponsor_info': sponsor_info, 'is_sponsor': venue.is_renter(role), 'student': student, 'venue_spuds': venue_spuds, 'base_url': 'spuddercern/base.html' })
def get_instagram_stream(request, venue_id): controller = SpudsController(request.current_role) filters = request.GET.get('filter', None) results = controller.get_unapproved_spuds(venue_id, filters=filters) ven = Venue.objects.get(id=venue_id) template_data = {'results': results, 'venue': ven} if filters == "day-0": template_data['filter_message'] = "Showing posts from today" elif filters == "day-1": template_data['filter_message'] = "Showing posts from yesterday" elif filters == "day-7": template_data['filter_message'] = "Showing older posts" elif filters: template_data[ 'filter_message'] = "Showing posts from %s days ago" % filters.replace( 'day-', '') return render(request, 'spuddercern/pages/venue_instagram_stream.html', template_data)
def get_instagram_stream(request, venue_id): controller = SpudsController(request.current_role) filters = request.GET.get('filter', None) results = controller.get_unapproved_spuds(venue_id, filters=filters) ven = Venue.objects.get(id=venue_id) template_data = {'results': results, 'venue': ven} if filters == "day-0": template_data['filter_message'] = "Showing posts from today" elif filters == "day-1": template_data['filter_message'] = "Showing posts from yesterday" elif filters == "day-7": template_data['filter_message'] = "Showing older posts" elif filters: template_data['filter_message'] = "Showing posts from %s days ago" % filters.replace('day-', '') return render( request, 'spuddercern/pages/venue_instagram_stream.html', template_data)
def affiliate_splash(request, affiliate_url_name): """ Gives affiliate splash page :param request: any request :param affiliate_url_name: any string without the \ character, formatted to lowercase for URL matching :return: an affiliate's splash page, or a 404 error if not a valid affiliate URL """ if affiliate_url_name: affiliate_url_name = affiliate_url_name.lower() if affiliate_url_name and affiliate_url_name == 'nays' and feature_is_enabled( 'nays_survey'): return _nays_survey(request) try: aff = Affiliate.objects.get(url_name=affiliate_url_name) except Affiliate.DoesNotExist: raise Http404 else: template_data = { 'find_teams': TeamPage.objects.filter(affiliate=aff)[:10], 'find_fans': FanPage.objects.filter(affiliate=aff)[:10], 'find_clubs': Club.objects.filter(affiliate=aff)[:10], 'affiliate': aff } if is_fan(request.current_role): spud_stream = SpudsController( request.current_role).get_spud_stream() fan_spuds = SpudsController.GetSpudsForFan( request.current_role.entity) stream = SpudsController.MergeSpudLists(spud_stream, fan_spuds) template_data['spuds'] = stream krowdio_response = get_following(request.current_role) template_data['teams'] = krowdio_users_to_links( request.can_edit, request.current_role, krowdio_response['data'], EntityController.ENTITY_TEAM) template_data['fans'] = krowdio_users_to_links( request.can_edit, request.current_role, krowdio_response['data'], RoleController.ENTITY_FAN) template_data['fan_nav_active'] = "explore" return render(request, 'spudderaffiliates/pages/landing_page.html', template_data)
def fan_profile_view(request, page_id): return redirect('/fan') page = get_object_or_404(FanPage, pk=page_id) fan_role = RoleFan(page) krowdio_response = get_following(fan_role) template_data = { 'page': page, 'role': fan_role, 'fan_spuds': SpudsController.GetSpudsForFan(page), 'base_url': 'spudderspuds/base.html', 'following_teams': krowdio_users_to_links(request.can_edit, fan_role, krowdio_response['data'], EntityController.ENTITY_TEAM), 'following_fans': krowdio_users_to_links(request.can_edit, fan_role, krowdio_response['data'], RoleController.ENTITY_FAN) } if request.can_edit: template_data[ 'following_teams_title'] = "<img src='/static/img/spudderspuds/button-teams-tiny.png' /> Teams You Follow" template_data[ 'following_fans_title'] = "<img src='/static/img/spudderspuds/button-fans-tiny.png' /> Fans You Follow" else: template_data[ 'following_teams_title'] = "<img src='/static/img/spudderspuds/button-teams-tiny.png' /> Teams %s Follows" % page.name template_data[ 'following_fans_title'] = "<img src='/static/img/spudderspuds/button-fans-tiny.png' /> Fans %s Follows" % page.name template_data['fan_nav_active'] = 'profile' template_data['challenges'] = { 'created': [ _format_challenge('created', c) for c in Challenge.objects.filter( creator_entity_id=fan_role.entity.id, creator_entity_type=RoleController.ENTITY_FAN) ], 'waiting': [ _format_challenge('waiting', c) for c in ChallengeParticipation.objects.filter( participating_entity_id=fan_role.entity.id, participating_entity_type=RoleController.ENTITY_FAN, state=ChallengeParticipation.PRE_ACCEPTED_STATE). select_related('challenge') ] } return render(request, 'spudderspuds/fans/pages/fan_page_view.html', template_data)
def public_view(request, page_id): page = get_object_or_404(TeamPage, pk=page_id) is_associated, associated_venues = _check_if_team_is_associated(page) template_data = { 'page': page, 'is_associated': is_associated, 'venues': associated_venues, 'base_url': 'spudderspuds/base.html', 'team_spuds': SpudsController.GetSpudsForTeam(page) } return render(request, 'spudderspuds/teams/pages/team_page_view.html', template_data)
def landing_page(request): template_data = { 'find_teams': TeamPage.objects.all()[:10], 'find_fans': FanPage.objects.all()[:10], 'find_venues': Venue.objects.all()[:10] } if is_fan(request.current_role): spud_stream = SpudsController(request.current_role).get_spud_stream() fan_spuds = SpudsController.GetSpudsForFan(request.current_role.entity) stream = SpudsController.MergeSpudLists(spud_stream, fan_spuds) template_data['spuds'] = stream entity = { 'id': request.current_role.entity.id, 'type': request.current_role.entity_type } participating_challenges = ChallengeParticipation.objects.filter( participating_entity_id=entity['id'], participating_entity_type=entity['type']) template_data['challenge_participations'] = participating_challenges template_data['state_engine_states'] = _StateEngineStates template_data['my_challenges'] = Challenge.objects.filter( creator_entity_id=request.current_role.entity.id, creator_entity_type=request.current_role.entity_type) # participating_ids = [c.challenge.id for c in participating_challenges] # # template_data['challenges'] = [_format_challenge('dash participating', c, entity) # for c in participating_challenges] + \ # [_format_challenge('dash created', c, participating_ids) # for c in Challenge.objects.filter(creator_entity_id=entity['id'], # creator_entity_type=entity['type'])] # template_data['fan_nav_active'] = "explore" return render(request, 'spudderspuds/pages/landing_page.html', template_data)
def reject_spud_from_social_media(request, venue_id, spud_from_social_media_id): controller = SpudsController(request.current_role) controller.reject_spuds([spud_from_social_media_id]) return HttpResponse(json.dumps({'status': 'ok'}), content_type='application/json')