Example #1
0
def finalize_pending_rentals(pending_rentals, role):
    """
    Finalizes pending Venue rentals.

    :param pending_rentals: string representing list of pending rentals, separated by comma
    :return: number of finalized rentals
    """
    if not pending_rentals:
        return 0

    venues = pending_rentals.split(',')
    count = 0

    for venue_id in venues:
        pending_venue = get_object_or_none(PendingVenueRental, pk=venue_id)
        if pending_venue:
            count += 1

            venue = pending_venue.venue
            venue.renter = role.entity
            venue.save()

            rent_venue = RentVenue.objects.get(venue=venue)
            rent_venue.donor = role.user
            rent_venue.state = DonationState.FINISHED
            rent_venue.save()

            pending_venue.delete()

    return count
Example #2
0
 def process_request(self, request):
     path = str(request.path)
     can_edit = False
     if request.user.is_authenticated and request.current_role:
         if re.match(r'^/cern/student/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 if str(request.current_role.entity.id) == str.split(
                         path, '/')[-1]:
                     can_edit = True
         elif re.match(r'^/cern/\w{2}/\d+/\w+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 sch = School.objects.get(id=str.split(path, '/')[-3])
                 if request.current_role.entity == sch.get_head_student():
                     can_edit = True
         elif re.match(r'^/venues/view/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 ven = Venue.objects.get(id=str.split(path, '/')[-1])
                 if request.current_role.entity == ven.student:
                     can_edit = True
         elif re.match(r'^/cern/venues/temp_view/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 ven = TempVenue.objects.get(id=str.split(path, '/')[-1])
                 if request.current_role.entity == ven.student:
                     can_edit = True
         elif re.match(r'^/team/\d+', path):
             entity_id = request.current_role.entity.id
             entity_type = request.current_role.entity_type
             page = TeamPage.objects.get(id=path.split('/')[2])
             if TeamAdministrator.objects.filter(team_page=page,
                                                 entity_type=entity_type,
                                                 entity_id=entity_id):
                 can_edit = True
         elif re.match(r'^/cern/\w{2}/\d+/\w+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 sch = School.objects.get(id=str.split(path, '/')[-1])
                 if request.current_role.entity == sch.get_head_student():
                     can_edit = True
         elif re.match(r'^/fan/\d+/edit', path):
             if request.current_role.entity_type == RoleController.ENTITY_FAN:
                 if str(request.current_role.entity.id) == str.split(
                         path, '/')[2]:
                     can_edit = True
         elif re.match(r'^/fan/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_FAN:
                 if str(request.current_role.entity.id) == str.split(
                         path, '/')[-1]:
                     can_edit = True
         elif re.match(r'^/sponsor/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_SPONSOR:
                 if str(request.current_role.entity.id) == str.split(
                         path, '/')[-1]:
                     can_edit = True
         elif re.match(r'^/club/\d+$', path):
             page = get_object_or_none(Club, id=str.split(path, '/')[-1])
             admins = ClubAdministrator.objects.filter(club=page,
                                                       admin=request.user)
             if len(admins) > 0:
                 can_edit = True
     request.can_edit = can_edit
Example #3
0
 def process_request(self, request):
     path = str(request.path)
     can_edit = False
     if request.user.is_authenticated and request.current_role:
         if re.match(r'^/cern/student/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 if str(request.current_role.entity.id) == str.split(path, '/')[-1]:
                     can_edit = True
         elif re.match(r'^/cern/\w{2}/\d+/\w+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 sch = School.objects.get(id=str.split(path, '/')[-3])
                 if request.current_role.entity == sch.get_head_student():
                     can_edit = True
         elif re.match(r'^/venues/view/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 ven = Venue.objects.get(id=str.split(path, '/')[-1])
                 if request.current_role.entity == ven.student:
                     can_edit = True
         elif re.match(r'^/cern/venues/temp_view/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 ven = TempVenue.objects.get(id=str.split(path, '/')[-1])
                 if request.current_role.entity == ven.student:
                     can_edit = True
         elif re.match(r'^/team/\d+', path):
             entity_id = request.current_role.entity.id
             entity_type = request.current_role.entity_type
             page = TeamPage.objects.get(id=path.split('/')[2])
             if TeamAdministrator.objects.filter(team_page=page, entity_type=entity_type, entity_id=entity_id):
                 can_edit = True
         elif re.match(r'^/cern/\w{2}/\d+/\w+', path):
             if request.current_role.entity_type == RoleController.ENTITY_STUDENT:
                 sch = School.objects.get(id=str.split(path, '/')[-1])
                 if request.current_role.entity == sch.get_head_student():
                     can_edit = True
         elif re.match(r'^/fan/\d+/edit', path):
             if request.current_role.entity_type == RoleController.ENTITY_FAN:
                 if str(request.current_role.entity.id) == str.split(path, '/')[2]:
                     can_edit = True
         elif re.match(r'^/fan/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_FAN:
                 if str(request.current_role.entity.id) == str.split(path, '/')[-1]:
                     can_edit = True
         elif re.match(r'^/sponsor/\d+', path):
             if request.current_role.entity_type == RoleController.ENTITY_SPONSOR:
                 if str(request.current_role.entity.id) == str.split(path, '/')[-1]:
                     can_edit = True
         elif re.match(r'^/club/\d+$', path):
             page = get_object_or_none(Club, id=str.split(path, '/')[-1])
             admins = ClubAdministrator.objects.filter(club=page, admin=request.user)
             if len(admins) > 0:
                 can_edit = True
     request.can_edit = can_edit
Example #4
0
 def is_admin(self, entity_id, entity_type):
     from spudderdomain.models import TeamAdministrator
     return get_object_or_none(TeamAdministrator,
                               entity_type=entity_type,
                               entity_id=entity_id,
                               team_page=self.entity) is not None
Example #5
0
 def is_admin(self, entity_id, entity_type):
     from spudderdomain.models import TeamAdministrator
     return get_object_or_none(TeamAdministrator, entity_type=entity_type,
                               entity_id=entity_id, team_page=self.entity) is not None
Example #6
0
def public_page(request, club_id):
    club = get_object_or_none(Club, pk=club_id)

    if not club or not club.is_fully_activated or club.is_hidden():
        return HttpResponseRedirect('/club/not_found')

    team_ids = list(TeamClubAssociation.objects.filter(club=club).values_list('team_page', flat=True))
    teams = TeamPage.objects.filter(id__in=team_ids)
    return render(request, 'spudderspuds/clubs/_old/public/view.html', {
        'base_url': 'spudderspuds/base.html',
        'profile': club,
        'teams': teams,
        # 'stripe_publishable_key': settings.STRIPE_PUBLISHABLE_KEY
    })
    #
    #
    # def donate(request, club_id):
    #     club = get_object_or_none(Club, pk=club_id)
    #
    #     if not club or not club.is_fully_activated or club.is_hidden():
    #         return HttpResponseRedirect('/club/not_found')
    #
    #     stripe_token = request.POST.get('stripeToken')
    #     stripe_user = StripeUser.objects.get(club=club)
    #
    #     import stripe
    #     stripe.api_key = settings.STRIPE_CLIENT_ID
    #
    #     stripe.Charge.create(
    #         amount=2000,
    #         currency="usd",
    #         card=stripe_token,  # obtained with Stripe.js
    #         description="Simple donation for %s club" % club.name,
    #         application_fee=123, # amount incents
    #         api_key=stripe_user.access_token # user's access token from the Stripe Connect flow
    #     )
    #
    #     return HttpResponseRedirect('/club/%s' % club_id)
    #
    #
    # def not_found(request):
    #     clubs = Club.objects.filter(hidden=False)[:5]
    #
    #     return render(request, 'spudderspuds/clubs/_old/public/not_found.html', {
    #         'clubs': clubs
    #     })
    #
    #
    # @club_admin_required
    # def edit_cover(request):
    #     club = request.current_role.entity.club
    #
    #     return render(request, 'components/coverimage/edit_cover_image.html', {
    #         'name': 'Fan Page',
    #         'return_url': "/club/%s" % club.id,
    #         'post_url': '/club/save_cover',
    #         'reset_url': '/club/reset_cover'
    #     })
    #
    #
    # @club_admin_required
    # def save_cover(request):
    #     club = request.current_role.entity.club
    #     save_cover_image_from_request(club, request)
    #
    #     return HttpResponse()
    #
    #
    # @club_admin_required
    # def reset_cover(request):
    #     club = request.current_role.entity.club
    #     reset_cover_image(club)
    #
    #     return HttpResponse('OK')
    #
    #
    # @club_admin_required
    # def save_thumbnail(request):
    #     club = request.current_role.entity.club
    #     request_logo = request.POST.getlist('thumbnail[]')
    #
    #     if len(request_logo):
    #         thumbnail_id = request_logo[0].split('/')[3]
    #         thumbnail = UploadedFile.objects.get(pk=thumbnail_id)
    #         club.thumbnail = thumbnail
    #         club.save()
    #
    #     return HttpResponse('OK')
    #
    #
    # def send_message(request, club_id):
    #     """
    #     Sends a message to the club manager
    #     :param request: a POST request with message body
    #     :param team_id: a valid ID of a Club object
    #     :return: a blank HttpResponse on success
    #     """
    #     if request.method != 'POST':
    #         return HttpResponseNotAllowed(['POST'])
    #
    #     club = get_object_or_404(Club, pk=club_id)
    #     message = request.POST.get('message', '')
    #
    #     if not message:
    #         return HttpResponse()
    #
    #     admin = ClubAdministrator.objects.filter(club=club)[0]
    #     entity = RoleController.GetRoleForEntityTypeAndID(
    #         RoleController.ENTITY_CLUB_ADMIN,
    #         admin.id,
    #         RoleBase.RoleWrapperByEntityType(RoleController.ENTITY_CLUB_ADMIN)
    #     )
    #     email = entity.user.email
    #
    #     if message:
    #         to = ['*****@*****.**', email]
    #         mail.send_mail(
    #             subject='Message from Spudder about Club: %s' % club.name,
    #             body=message,
    #             sender=settings.SERVER_EMAIL,
    #             to=to
    #         )
    #
    #     return HttpResponse()
    #
    #
    # @club_admin_required
    # def stripe(request):
    #     club = request.current_role.entity.club
    #
    #     params = urllib.urlencode({
    #         'client_secret': settings.STRIPE_SECRET_KEY,
    #         'code': request.GET.get('code', ''),
    #         'grant_type': 'authorization_code'
    #     })
    #     url = '/oauth/token?%s' % params
    #
    #     connection = httplib.HTTPSConnection('connect.stripe.com')
    #     connection.connect()
    #     connection.request('POST', url)
    #
    #     resp = connection.getresponse()
    #     resp_data = resp.read()
    #
    #     json_data = json.loads(resp_data)
    #
    #     StripeUser(
    #         club=club,
    #         access_token=json_data['access_token'],
    #         refresh_token=json_data['refresh_token'],
    #         publishable_key=json_data['stripe_publishable_key'],
    #         user_id=json_data['stripe_user_id'],
    #         scope=json_data['scope'],
    #         token_type=json_data['token_type'],
    #     ).save()
    #
    #
    #     return HttpResponseRedirect('/club/dashboard')