示例#1
0
    def get(self):
        """Handler user request

        The edit category name HTML page would list all items belonging to
        the specified category.
        """
        category_name = self.request.get("category_name")
        if not category_name:
            self.redirect("/{path}?".format(path=edit_page_path) + urllib.urlencode({"select_category": "Nothing"}))
            return

        invalid_name = self.request.get("invalid_name")
        user = users.get_current_user()
        url = users.create_logout_url(self.request.uri)
        items = item.get_items(author=user, category_name=category_name)

        template_values = {
            "category_name": category_name,
            "items": items,
            "url": url,
            "user": user,
            "invalid_name": invalid_name,
        }
        template = jinja_environment.get_template("{path}.html".format(path=edit_category_path))
        self.response.out.write(template.render(template_values))
示例#2
0
def get_categories(author=None, order="-create_time", item_number=0):
    """Returns categories of specified author, order and the number of
       item in category is equals to or greater than the specified item
       number

    :param author the specified author. The default value is None,
                  if so, the all categories would be returned
    :param order the specified order. The default value is ordering by
                 create time field in descending
    :param item_number the specified item number. The default value is 0
    :returns: categories of specified author, order and the number of
              item in category is euqlas to or greater than the specified
              item number
    """
    category_query = (
        rankdata.Category.all().filter("author = ", author).order(order)
        if author
        else rankdata.Category.all().order(order)
    )
    return (
        [
            category
            for category in category_query.run()
            if item.get_items(author=category.author, category_name=category.name, count_or_not=True) >= item_number
        ]
        if item_number
        else category_query.run()
    )
示例#3
0
    def get(self):
        """Handle user request

        The select item HTML page would list all items in category. The
        user should select one of them to comment
        """
        category_key = self.request.get('category_key')
        if not category_key:
            self.redirect('/{path}?'.format(path=select_category_page_path) +
                          urllib.urlencode({'select_category': 'Nothing'}))
            return

        invalid_select = self.request.get('select_item')
        user = users.get_current_user()
        url = users.create_logout_url(self.request.uri) if user else users.create_login_url(self.request.uri)
        category_data = category.get_category_by_key(key=category_key)
        items = item.get_items(author=category_data.author, category_name=category_data.name)

        template_values = {
            'category': category_data,
            'items': items,
            'url': url,
            'user': user,
            'invalid_select': invalid_select,
        }
        template = jinja_environment.get_template('{path}.html'.format(path=select_item_page_path))
        self.response.out.write(template.render(template_values))
示例#4
0
def update_category(author, category_name, item_names=[]):
    """Update category of specified author, category name. and item name

    If te category name does not exist in the specified author, it would
    add the category and all items in the item name list and belongs to
    that category. Otherwise, delete all items as well as comments belonging
    to that does not exist in the item name list, then add all new items
    in the item name list.
    :param author the specified author
    :param category_name the specified category name
    :param item_names the specified item name list
    """
    if category.get_category(author=author, name=category_name):
        old_items = item.get_items(author=author, category_name=category_name)
        delete_item_names = [old_item.name for old_item in old_items if old_item.name not in item_names]
        item.delete_items(author=author, category_name=category_name, item_names=delete_item_names)
        for item_name in item_names:
            if not item.get_item(author=author, category_name=category_name, item_name=item_name):
                new_item = rankdata.Item(key_name='{author}/{category}/{name}'.format(author=author, category=category_name, name=item_name),
                                         parent=item.get_ancestor_key(author=author, category_name=category_name),
                                         name=item_name, number_of_win=0, number_of_lose=0, percentage=-1.0)
                new_item.put()
    else:
        new_category = rankdata.Category(key_name='{author}/{name}'.format(author=author, name=category_name), author=author, name=category_name)
        new_category.put()
        for item_name in item_names:
            new_item = rankdata.Item(key_name='{author}/{category}/{name}'.format(author=author, category=category_name, name=item_name),
                                     parent=item.get_ancestor_key(author=author, category_name=category_name),
                                     name=item_name, number_of_win=0, number_of_lose=0, percentage=-1.0)
            new_item.put()
示例#5
0
def get_category_dict(catalog_id, category_id):
    """Returns a dict representation of a category of given catalog and category id"""
    category_dict = get_category_by_id(catalog_id, category_id).to_dict()
    items = []
    for item_entity in item.get_items(catalog_id, category_id):
        items.append(item_entity.to_dict())
    category_dict['items'] = items
    return category_dict
示例#6
0
文件: crate.py 项目: nhandler/cs429
    def from_json(self, json):
        '''
        Restore this object from the passed in json object

        @param json - the json object
        '''
        EntitySprite.from_json(self, json)
        self.health = json['health']
        self.item = get_items()[json['item']]
示例#7
0
def delete_catalog(catalog_id):
    """Deletes the catalog with the specified integer id, as well as any categories
    or items in the catalog"""
    catalog_entity = get_catalog_by_id(catalog_id)
    if not catalog_entity:
        raise ValueError('Catalog not found!')

    for category_entity in category.get_categories(catalog_entity.key.id()):
        category_entity.key.delete()
    for item_entity in item.get_items(catalog_entity.key.id()):
        item_entity.key.delete()

    catalog_entity.key.delete()
示例#8
0
def delete_category(catalog_id, category_id):
    """Deletes a category of a given catalog id and category id, as well as any
    items in that category"""
    if not catalog_id or not category_id:
        raise ValueError('Must pass a valid catalog!')
    category_entity = get_category_by_id(catalog_id, category_id)
    if not category_entity:
        raise ValueError('Category not found!')

    catalog_entity = catalog.get_catalog_by_id(catalog_id)

    for item_entity in item.get_items(catalog_entity.key.id(),
                                      category_entity.key.id()):
        item_entity.key.delete()
    category_entity.key.delete()
示例#9
0
    def get(self):
        """Handle user request

        Construct category information in XML web page
        """
        category_key = self.request.get("category_key")
        if not category_key:
            self.redirect(
                "/{path}?".format(path=select_category_page_path) + urllib.urlencode({"select_category": "Nothing"})
            )
            return

        category_data = category.get_category_by_key(key=category_key)
        items = item.get_items(author=category_data.author, category_name=category_data.name)

        template_values = {"category": category_data, "items": items}
        template = jinja_environment.get_template("{path}.xml".format(path=result_page_path))
        self.response.headers["Content-Type"] = "text/xml"
        self.response.out.write(template.render(template_values))
示例#10
0
文件: player.py 项目: nhandler/cs429
    def from_json(self, json):
        '''
        Restore this object from the passed in json object

        @param json - the json object
        '''

        CreatureSprite.from_json(self, json)
        self.health = json['health']
        self.count = json['count']
        self.weapon_tier = json['wep_tier']
        self.lives = json['lives']
        self.bullets = json['bullets']
        items = get_items()
        for name, num in json['inventory'].items():
            for i in range(0, num):
                self.addItemToInventory(items[name])
        for name in json['final inventory']:
            self.addItemToInventory(items[name])
示例#11
0
    def get(self):
        """Handle user request

        The vote result HTML page would list statistics of vote ordered by
        wining percentage in descending.
        """
        category_key = self.request.get('category_key')
        user = users.get_current_user()
        url = users.create_logout_url(self.request.uri) if user else users.create_login_url(self.request.uri)

        category_data = category.get_category_by_key(key=category_key)
        items = item.get_items(author=category_data.author, category_name=category_data.name, order='-percentage')
        template_values = {
            'category': category_data,
            'items': items,
            'url': url,
            'user': user,
        }
        template = jinja_environment.get_template('{path}.html'.format(path=result_page_path))
        self.response.out.write(template.render(template_values))
示例#12
0
文件: tile.py 项目: nhandler/cs429
    def _initialize_entities(self, data):
        '''
        Takes the data json from the .json file and uses it to intialize
        the objects and enemies for that tile

            @data - the json data from the .json file
        '''
        items = get_items() 
        for crate in data['crates']:
            self.crates.append(
                ObjectSprite(json=crate)
            )

        for button in data['buttons']:
            self.buttons.append(
                ButtonSprite(json=button)
            )

        for gate in data['gates']:
            self.gates.append(
                GateSprite(json=gate)
            )

        for boss in data['bosses']:
            self.bosses.append(
                BossSprite(json=boss)
            )

        for shooter in data['shooters']:
            self.shooters.append(
                ShooterSprite(json=shooter)
            )

        for enemy in data['enemies']:
            self.enemies.append(
                EnemySprite(json=enemy)
            )
示例#13
0
 def get_items(self):
     """Returns a query of the items in the category"""
     return item.get_items(self.catalog.id(), self.key.id())
示例#14
0
 def test_get_items (self):
     #not a whole lot of variance here, just looking for a list and no MySQL errors.
     assert get_items() != None
     assert len(get_items()) >= 0
示例#15
0
# -*- coding: utf-8 -*-

from item import get_items

import heroine
import place
import script

import random

import os
import pygame

import conch

items = get_items()

class Player:
    def __init__(self, name):
        self.name = name

        self.balance = 100000
        self.items   = list()

class LoveEE:
    def __init__(self, player):
        self.player = player
        
        self.jukebox = conch.Jukebox()
        
        pygame.mixer.music.load(os.path.join('..', 'bgm', "bgm.ogg"))