Пример #1
0
def add_score(request):
  if request.method != 'POST':
    players = Player.gql("WHERE owner = :owner AND active = True ORDER BY name", owner=request.user)
    return render_to_response(request, 'pingpong/addscore.html',
      { 'players': players, })
  else:
    mode = 'singles' # Used when we re-direct back to the main view
    try:
      # Find players. Save teams. Save game using a ranking system.
      t1p1 = get_object(Player, request.POST['t1p1'])
      t1p2 = get_object(Player, request.POST['t1p2'])
      t2p1 = get_object(Player, request.POST['t2p1'])
      t2p2 = get_object(Player, request.POST['t2p2'])
      t1s = float(request.POST['t1s'])
      t2s = float(request.POST['t2s'])
      t1 = db_create(Team, player1=t1p1, player2=t1p2, points=t1s)
      t2 = db_create(Team, player1=t2p1, player2=t2p2, points=t2s)
      game = db_create(Game, team1=t1, team2=t2)
      save_player_games(game, t1p1, t1p2, t2p1, t2p2, t1s, t2s)
      doubles = (t1p1 != None and t1p2 != None and t2p1 != None and t2p2 != None)
      if doubles:
        mode = 'doubles'
      ranking_system = DefaultRankingSystem()
      ranking_system.save_game(t1p1=t1p1, t1p2=t1p2, t2p1=t2p1, t2p2=t2p2, 
        t1s=t1s, t2s=t2s, t1=t1, t2=t2, game=game, doubles=doubles)
      response_dict = { 'status': True, 'message': 'Scores successfully saved.', 
        'mode': mode, 'game': str(game.key()) }
    except:
      logging.exception('There was a problem adding scores')
      response_dict = { 'status': False, 'message' : 'Hmmm... There was a problem saving your scores - please have another go.', 'mode': mode }
    return HttpResponse(simplejson.dumps(response_dict), mimetype='application/json')
Пример #2
0
def get_user_settings_from_ipn(ipn):
  settings = None
  user_paying = get_object(User, ipn.custom) # custom parameter stores the user key
  if user_paying:
    key_name = '%s_settings' % str(user_paying.key())
    settings = UserSettings.get_by_key_name(key_name)
  return settings
Пример #3
0
def player_stats(request, key):
  player = get_object(Player, key)
  # Calculate the player's ranking on the fly
  singles_ranking = 0
  doubles_ranking = 0
  singles_players = Player.gql("WHERE owner = :owner AND active = True ORDER BY singles_ranking_points DESC, name",
                                owner=request.user)
  for sp in singles_players:
    singles_ranking += 1
    if sp.key == player.key:
      break
  doubles_players = Player.gql("WHERE owner = :owner AND active = True ORDER BY doubles_ranking_points DESC, name",
                                owner=request.user)
  for dp in doubles_players:
    doubles_ranking += 1
    if dp.key == player.key:
      break

  games = []
  pgs = PlayerGame.gql("WHERE player = :player ORDER BY date_played DESC LIMIT 20", player=player)
  for pg in pgs:
    games.append(pg)
  return render_to_response(request, 'pingpong/player_stats.html',
    { 'player': player, 'singles_ranking': singles_ranking, 
      'doubles_ranking': doubles_ranking, 'games': games })
def show_gallery(request, key):
    g = get_object(Gallery, key)

    images = None
    if g:
      images = get_object_list(Photo, "gallery =", g.key()).fetch(50)
    
    return render_to_response(request, 'gallery_detail.html', {'g': g, 'g_images': images})
Пример #5
0
 def get_object_for_this_type(self, *filters_or_key, **kwargs):
     """
     Returns an object of this type for the keyword arguments given.
     The parameters have the same format as ragendja's get_object_or_404().
     """
     if 'pk' in kwargs:
         filters_or_key = (kwargs['pk'],)
         del kwargs['pk']
     return get_object(self.model_class(), *filters_or_key, **kwargs)
Пример #6
0
def delete_todo(request, key):
    user = request.user
    if user.is_authenticated():
      try:
        todo = get_object(Todo, key)
        todo.delete()
        return HttpResponseRedirect('/todo/')
      except KeyError:
        pass
    else:
        return HttpResponseRedirect('/todo/')
Пример #7
0
def delete_player(request, key):
  if request.method == 'POST':
    player = get_object(Player, key)
    if player:
      player.active = False
      player.put()
      response_dict = { 'status': True, 'message' : 'Player successfully deleted.' }
      return HttpResponse(simplejson.dumps(response_dict), mimetype='application/json')
    else:
      response_dict = { 'status': False, 'message' : "Hmm... We couldn't find that player. Please have another go." }
      return HttpResponse(simplejson.dumps(response_dict), mimetype='application/json')
  else:
    return HttpResponseRedirect('/')
Пример #8
0
def settings(request):
  if request.method != 'POST':
    players = Player.gql("WHERE owner = :owner AND active = True ORDER BY name", owner=request.user)
    return render_to_response(request, 'pingpong/settings.html',
      { 'players': players, 'email': request.user.email })
  else:
    errors = {}
    try:
      # Save email address
      email = request.POST['email']
      if is_valid_email(email.strip()):
        user = request.user
        user.email = email.strip()
        user.save()
      else:
        errors['email'] = 'Invalid email address'

      # Add any new players
      new_players = request.POST['newplayers']
      if new_players:
        players = new_players.splitlines()
        for p in players:
          if len(p.strip()) > 0:
            db_create(Player, name=p.strip(), owner=request.user)

      # Update player names based on posted values
      for k, v in request.POST.items():
        if str(k).endswith('_player'): # Expected key format: <key>_player
          player = get_object(Player, str(k)[:-7])
          if player:
            if len(v.strip()) > 0:
              player.name = v # Value is the updated player name
              player.put()
            else:
              errors[str(k)[:-7]] = 'Invalid name'

      if len(errors) == 0:
        response_dict = { 'status': True, 'message': 'Settings successfully saved.' }
      else:
        response_dict = { 'status': False, 'message': 'Hmmm... There was a problem saving your settings - please have another go.',
          'errors': errors }
      return HttpResponse(simplejson.dumps(response_dict), mimetype='application/json')
    except:
      logging.exception('There was a problem saving settings')
      response_dict = { 'status': False, 'message': 'Hmmm... There was a problem saving your settings - please have another go.',
        'errors': errors }
    return HttpResponse(simplejson.dumps(response_dict), mimetype='application/json')
Пример #9
0
def undo_score(request, key):
  if request.method == 'POST':
    try:
      game = get_object(Game, key)
      if game:
        mode = 'doubles' if game.doubles() else 'singles'
        delete_player_games(game)
        ranking_system = DefaultRankingSystem()
        ranking_system.undo_save_game(game)
        response_dict = { 'status': True, 'message': 'Done.', 'mode': mode }
      else:
        response_dict = { 'status': False, 'message': "Hmmm... We couldn't find that game - sorry." }
    except:
      logging.exception('There was a problem undoing the addition of the game')
      response_dict = { 'status': False, 'message' : 'Hmmm... There was a problem undoing your game - sorry.' }
    return HttpResponse(simplejson.dumps(response_dict), mimetype='application/json')
  else:
    return HttpResponseRedirect('/')
Пример #10
0
def get_event_by_id(id):
    return get_object(Event, id=int(id))
Пример #11
0
def subscribe_service(request, key):
    service = Service.get(key)
    form = SubscribeForm()
    person_email_content = ''

    if request.method == 'POST':
        form = SubscribeForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            type_email = form.cleaned_data['type_email']
            if service.person_mail == True:
                person_email_content = request.POST['person_mail']

            person = Person.all().filter("person_email =", email).get()
            if person == None:
                person = Person(person_first_name=first_name,
                                person_last_name=last_name,
                                person_email=email,
                                person_is_activ=True,
                                person_type_email=type_email)
                person.put()
            else:
                person.person_is_activ = True
                person.put()

            subscr_query = Subscribe.all().filter("subscribe_user ="******""
                for dest in service.responsable:
                    user = get_object(User, dest)
                    to += render_to_string('service/subscribe_email_to.txt',
                                           {'user': user})
                message.to = to
                message.send()

            return render_to_response(request, 'service/subscribe_ok.html',
                                      {'service': service})

    return render_to_response(request, 'service/subscribe_form.html', {
        'service': service,
        'form': form
    })
Пример #12
0
	def clean_username(self):
		username = self.cleaned_data.get('username')
		user = dbutils.get_object(User, 'username ='******'This username is already in use.'))
Пример #13
0
	def get_user(self, user_id):
		obj = get_object(User, user_id)
		return obj
Пример #14
0
def get_venue_by_key(key):
    return get_object(Venue, key)
Пример #15
0
def get_tags_from_keylist(keylist):
    return [get_object(Tag, tag) for tag in keylist]
Пример #16
0
def get_article_by_id(id):
    article = get_object(Article, id=int(id))
    return article, get_tags_from_keylist(article.tags)
Пример #17
0
def profile_detail(request, username, public_profile_field=None,
                   template_name='profiles/profile_detail.html',
                   extra_context=None):
    """
    Detail view of a user's profile.
    
    If no profile model has been specified in the
    ``AUTH_PROFILE_MODULE`` setting,
    ``django.contrib.auth.models.SiteProfileNotAvailable`` will be
    raised.
    
    If the user has not yet created a profile, ``Http404`` will be
    raised.
    
    **Required arguments:**
    
    ``username``
        The username of the user whose profile is being displayed.
    
    **Optional arguments:**

    ``extra_context``
        A dictionary of variables to add to the template context. Any
        callable object in this dictionary will be called to produce
        the end result which appears in the context.

    ``public_profile_field``
        The name of a ``BooleanField`` on the profile model; if the
        value of that field on the user's profile is ``False``, the
        ``profile`` variable in the template will be ``None``. Use
        this feature to allow users to mark their profiles as not
        being publicly viewable.
        
        If this argument is not specified, it will be assumed that all
        users' profiles are publicly viewable.
    
    ``template_name``
        The name of the template to use for displaying the profile. If
        not specified, this will default to
        :template:`profiles/profile_detail.html`.
    
    **Context:**
    
    ``profile``
        The user's profile, or ``None`` if the user's profile is not
        publicly viewable (see the description of
        ``public_profile_field`` above).
    
    **Template:**
    
    ``template_name`` keyword argument or
    :template:`profiles/profile_detail.html`.
    
    """
    user = get_object(User, 'username ='******'profile': profile_obj },
                              context_instance=context)
Пример #18
0
	def authenticate(self, identity=None):
		obj = get_object(OpenIDProfile, "identity = ", identity)
		if obj: return obj.user
		else: return None
Пример #19
0
	def authenticate(self, twitter_id=None):
		obj = get_object(TwitterProfile, "twitter_id = ", twitter_id)
		if obj:
			return obj.user
		else:
			return None
Пример #20
0
	def authenticate(self, uid=None):
		obj = get_object(FacebookProfile, "uid =", uid)
		if obj: return obj.user
		else: return None