示例#1
0
 def setUp(self):
     super( ApplicationActionsCase, self ).setUp()
     from camelot.admin.application_admin import ApplicationAdmin
     from camelot.core.files.storage import Storage
     from camelot.view.workspace import DesktopWorkspace
     self.app_admin = ApplicationAdmin()
     self.context = MockModelContext()
     self.storage = Storage()
     self.gui_context = application_action.ApplicationActionGuiContext()
     self.gui_context.admin = self.app_admin
     self.gui_context.workspace = DesktopWorkspace( self.app_admin, None )
示例#2
0
 def get_default_storage(cls):
     """
     :return: a camelot.core.files.storage.Storage object
     
     Returns the storage to be used to store default backups.
     
     By default, this will return a Storage that puts the backup files
     in the DataLocation as specified by the QDesktopServices
     """
     apps_folder = six.text_type(QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.DataLocation))
     
     from camelot.core.files.storage import Storage
     return Storage(upload_to='backups', root=apps_folder)
示例#3
0
def load_movie_fixtures():

    from camelot.model.fixture import Fixture
    from camelot.model.party import Person
    from camelot_example.model import Movie, VisitorReport
    from camelot.core.files.storage import Storage, StoredImage
    from camelot.core.resources import resource_filename

    storage = Storage(upload_to='covers',
                      stored_file_implementation = StoredImage)

    movies = [
        [
            u'The Shining',
            u'The tide of terror that swept America is here.',
            datetime.date(1980, 5, 23),
            (u'Stanley', u'Kubrick',),
            [
                u'Jack Nicholson',
                u'Shelley Duvall',
                u'Danny Lloyd',
                u'Scatman Crothers',
                u'Barry Nelson'
            ],
            [u'Horror',u'Mystery',u'Thriller'],
            u'thriller',
            4,
            u'shining.png',
            u'A family heads to an isolated hotel for the winter where an evil'
            ' and spiritual presence influences the father into violence,'
            ' while his psychic son sees horrific forebodings from the past'
            ' and of the future.'
        ],
        [
            u'The Bourne Identity',
            u'Matt Damon is Jason Bourne.',
            datetime.date(2002, 6, 14),
            (u'Doug', u'Liman'),
            [
                u'Matt Damon',
                u'Franka Potente',
                u'Chris Cooper',
                u'Clive Owen',
                u'Brian Cox'
            ],
            [u'Action',u'Adventure'],
            u'action',
            4,
            u'bourne.png',
            u'A man is picked up by a fishing boat, bullet-riddled and without'
            ' memory, then races to elude assassins and recover from amnesia.'
        ],
        [
            u'Casino Royale',
            u'Discover how James became Bond.',
            datetime.date(2006, 11, 17),
            (u'Martin', u'Campbell'),
            [
                u'Daniel Craig',
                u'Eva Green',
                u'Mads Mikkelsen',
                u'Judi Dench',
                u'Jeffrey',
                u'Wright'
            ],
            [u'Action',u'Adventure'],
            u'action',
            5,
            u'casino.png',
            u"In his first mission, James Bond must stop Le Chiffre, a banker"
            " to the world's terrorist organizations, from winning a"
            " high-stakes poker tournament at Casino Royale in Montenegro."
        ],
        [
            u'Toy Story',
            u'Oooh...3-D.',
            datetime.date(1995, 11, 22),
            (u'John', u'Lasseter'),
            [
                u'Tom Hanks',
                u'Tim Allen',
                u'Don Rickles',
                u'Jim Varney',
                u'Wallace Shawn'
            ],
            [u'Animation',u'Adventure'],
            u'animation',
            4,
            u'toystory.png',
            u"a cowboy toy is profoundly threatened and jealous when a fancy"
            " spaceman toy supplants him as top toy in a boy's room."
        ],
        [
            u"Harry Potter and the Sorcerer's Stone",
            u'Let The Magic Begin.',
            datetime.date(2001, 11, 16),
            (u'Chris', u'Columbus'),
            [
                u'Richard Harris',
                u'Maggie Smith',
                u'Daniel Radcliffe',
                u'Fiona Shaw',
                u'Richard Griffiths'
            ],
            [u'Family',u'Adventure'],
            u'family',
            3,
            u'potter.png',
            u'Rescued from the outrageous neglect of his aunt and uncle, a'
            ' young boy with a great destiny proves his worth while attending'
            ' Hogwarts School of Witchcraft and Wizardry.'
        ],
        [
            u'Iron Man 2',
            u'The world now becomes aware of the dual life of the Iron Man.',
            datetime.date(2010, 5, 17),
            (u'Jon', 'Favreau'),
            [
                u'Robert Downey Jr.',
                u'Gwyneth Paltrow',
                u'Don Cheadle',
                u'Scarlett Johansson',
                u'Mickey Rourke'
            ],
            [u'Action',u'Adventure',u'Sci-fi'],
            u'sci-fi',
            3,
            u'ironman.png',
            u'billionaire Tony Stark must contend with deadly issues involving'
            ' the government, his own friends, as well as new enemies due to'
            ' his superhero alter ego Iron Man.'
        ],
        [
            u'The Lion King',
            u"Life's greatest adventure is finding your place in the Circle of"
            " Life.",
            datetime.date(1994, 6, 24),
            (u'Roger', u'Allers'),
            [
                u'Matthew Broderick',
                u'Jeremy Irons',
                u'James Earl Jones',
                u'Jonathan Taylor Thomas',
                u'Nathan Lane'
            ],
            [u'Animation',u'Adventure'],
            u'animation',
            5,
            u'lionking.png',
            u'Tricked into thinking he killed his father, a guilt ridden lion'
            ' cub flees into exile and abandons his identity as the future'
            ' King.'
        ],
        [
            u'Avatar',
            u'Enter the World.',
            datetime.date(2009, 12, 18),
            (u'James', u'Cameron'),
            [
                u'Sam Worthington',
                u'Zoe Saldana',
                u'Stephen Lang',
                u'Michelle Rodriguez',
                u'Sigourney Weaver'
            ],
            [u'Action',u'Adventure',u'Sci-fi'],
            u'sci-fi',
            5,
            u'avatar.png',
            u'A paraplegic marine dispatched to the moon Pandora on a unique'
            ' mission becomes torn between following his orders and'
            ' protecting the world he feels is his home.'
        ],
        [
            u'Pirates of the Caribbean: The Curse of the Black Pearl',
            u'Prepare to be blown out of the water.',
            datetime.date(2003, 7, 9),
            (u'Gore', u'Verbinski'),
            [
                u'Johnny Depp',
                u'Geoffrey Rush',
                u'Orlando Bloom',
                u'Keira Knightley',
                u'Jack Davenport'
            ],
            [u'Action',u'Adventure'],
            u'action',
            5,
            u'pirates.png',
            u"Blacksmith Will Turner teams up with eccentric pirate \"Captain\""
            " Jack Sparrow to save his love, the governor's daughter, from"
            " Jack's former pirate allies, who are now undead."
        ],
        [
            u'The Dark Knight',
            u'Why so serious?',
            datetime.date(2008, 7, 18),
            (u'Christopher', u'Nolan'),
            [
                u'Christian Bale',
                u'Heath Ledger',
                u'Aaron Eckhart',
                u'Michael Caine',
                u'Maggie Gyllenhaal'
            ],
            [u'Action',u'Drama'],
            u'action',
            5,
            u'darkknight.png',
            u'Batman, Gordon and Harvey Dent are forced to deal with the chaos'
            ' unleashed by an anarchist mastermind known only as the Joker, as'
            ' it drives each of them to their limits.'
        ]
    ]

    visits = {
        u'The Shining': [
            (u'Washington D.C.', 10000, datetime.date(1980, 5, 23)),
            (u'Buesnos Aires', 4000,datetime.date(1980, 6, 12)),
            (u'California', 13000,datetime.date(1980, 5, 23)),
        ],
        u'The Dark Knight': [
            (u'New York', 20000, datetime.date(2008, 7, 18)),
            (u'London', 15000, datetime.date(2008, 7, 20)),
            (u'Tokyo', 3000, datetime.date(2008, 7, 24)),
        ],
        u'Avatar': [
            (u'Shangai', 6000, datetime.date(2010, 1, 5)),
            (u'Atlanta', 3000, datetime.date(2009, 12, 18)),
            (u'Boston', 5000, datetime.date(2009, 12, 18)),
        ],
    }

    for title, short_description, releasedate, (director_first_name, director_last_name), cast, tags, genre, rating, cover, description in movies:
        director = Fixture.insert_or_update_fixture(
            Person,
            fixture_key = u'%s_%s'%(director_first_name, director_last_name),
            values = {'first_name':director_first_name,
                      'last_name':director_last_name}
        )
        movie = Fixture.find_fixture( Movie, title )
        if not movie:
            # use resource_filename, since resource_string seems to mess either with encoding
            # or with line endings, when on windows
            image = resource_filename( 'camelot_example', os.path.join( 'media', 'covers', cover ) )
            stored_image = storage.checkin( image )
            movie = Fixture.insert_or_update_fixture(
                Movie,
                fixture_key = title,
                values = {
                    'title': title,
                    'director':director,
                    'short_description':short_description,
                    'releasedate':releasedate,
                    'rating':rating,
                    'genre':genre,
                    'description':description,
                    'cover':stored_image,
                },
            )
        rep = visits.get(title, None)
        if rep:
            for city, visitors, date in rep:
                Fixture.insert_or_update_fixture(
                    VisitorReport,
                    fixture_key = '%s_%s' % (title, city),
                    values = {
                        'movie': movie,
                        'date': date,
                        'visitors': visitors,
                    }
                )
示例#4
0
文件: model.py 项目: frandibar/m2000
class Beneficiaria(Entity):
    using_options(tablename='beneficiaria')
    barrio = ManyToOne('Barrio',
                       ondelete='cascade',
                       onupdate='cascade',
                       required=True)
    nombre = Field(Unicode(200), required=True)
    apellido = Field(Unicode(200), required=True)
    grupo = Field(Unicode(200), required=True)
    fecha_alta = Field(Date, default=datetime.date.today)
    activa = Field(Boolean, default=True)
    fecha_baja = Field(Date, nullable=True)
    comentarios = Field(Unicode(1000), nullable=True)
    dni = Field(Unicode(10))
    fecha_nac = Field(Date)
    domicilio = Field(Unicode(50))
    estado_civil = Field(
        camelot.types.Enumeration([(0, ''), (1, 'soltera'), (2, 'concubina'),
                                   (3, 'casada'), (4, 'separada'),
                                   (5, 'divorciada'), (6, 'viuda')]))
    telefono = Field(Unicode(50))
    email = Field(camelot.types.VirtualAddress(256))
    default_foto = StoredImage(Storage('fotos', StoredImage), 'sin-foto.jpg')
    foto = Field(camelot.types.Image(upload_to='fotos'), default=default_foto)
    creditos = OneToMany('Credito')

    def _get_activa(self):
        return self.activa

    def _set_activa(self, value):
        # impedir la baja si tiene creditos activos
        if not value:
            if self.creditos_activos == 0:
                fecha_ultimo_pago = sql.select(
                    [sql.func.max(Pago.fecha)],
                    and_(Pago.credito_id == Credito.id,
                         Credito.beneficiaria_id == Beneficiaria.id))
                self.fecha_baja = fecha_ultimo_pago
                self.activa = False
        else:
            self.fecha_baja = None
            self.activa = True

    _activa = property(_get_activa, _set_activa)

    @ColumnProperty
    def creditos_activos(self):
        return sql.select([sql.func.count(Credito.id)],
                          and_(Credito.beneficiaria_id == Beneficiaria.id,
                               sql.column('fecha_finalizacion') == sql.null()))

    @ColumnProperty
    def nombre_completo(self):
        return self.nombre + ' ' + self.apellido

    def __unicode__(self):
        if self.nombre and self.apellido:
            return '%s %s' % (self.nombre, self.apellido)
        return UNDEFINED

    class Admin(EntityAdmin):
        verbose_name = 'Beneficiaria'
        delete_mode = 'on_confirm'
        list_columns_frozen = 1
        lines_per_row = 1  # lo especifico por la foto
        delete_mode = 'on_confirm'
        list_display = [
            'nombre',
            'apellido',
            'grupo',
            'fecha_alta',
            '_activa',
            'fecha_baja',
            'comentarios',
            'dni',
            'fecha_nac',
            'domicilio',
            'estado_civil',
            'telefono',
            'email',
            'barrio',
        ]
        form_display = TabForm([
            ('Beneficiaria',
             Form([
                 HBoxForm([[
                     'nombre',
                     'apellido',
                     'barrio',
                     'grupo',
                     '_activa',
                     'fecha_alta',
                     'fecha_baja',
                     'comentarios',
                     'dni',
                     'fecha_nac',
                 ],
                           [
                               WidgetOnlyForm('foto'), 'estado_civil',
                               'domicilio', 'telefono', 'email',
                               'creditos_activos'
                           ]])
             ])),
            (u'Créditos', WidgetOnlyForm('creditos')),
        ])
        list_filter = [
            GroupBoxFilter('activa', default=True),
            ComboBoxFilter('barrio.nombre'),
        ]
        search_all_fields = False
        list_search = [
            'id',
            'nombre_completo',
            'comentarios',
            'dni',
            'grupo',
            'barrio.nombre',
        ]
        expanded_list_search = [
            'nombre',
            'apellido',
            'grupo',
            'fecha_alta',
            'fecha_baja',
            'comentarios',
            'dni',
            'fecha_nac',
            'barrio.nombre',
        ]
        field_attributes = dict(
            fecha_alta=dict(name='Fecha Alta'),
            _activa=dict(
                name='Activa',
                delegate=BoolDelegate,
                # to_string = lambda x:{True:'Si', False:'No'}[x], # TODO no lo toma
                editable=True,
                tooltip=
                u'No se puede dar de baja una beneficiaria si tiene créditos activos.'
            ),
            fecha_baja=dict(
                name='Fecha Baja',
                tooltip=
                u'Al desactivar la beneficiaria, este campo toma la última fecha de pago'
            ),
            dni=dict(name='DNI'),
            fecha_nac=dict(name='Fecha Nac.'),
            estado_civil=dict(name='Estado Civil'),
            telefono=dict(name=u'Teléfono'),
            email=dict(address_type='email'),
            creditos=dict(admin=CreditoAdminEmbedded),
            creditos_activos=dict(name=u'Créditos activos', editable=False),
        )
        form_size = (850, 400)
示例#5
0
def load_movie_fixtures():

    from camelot.model.fixture import Fixture
    from camelot.model.party import Person
    from camelot_example.model import Movie, VisitorReport
    from camelot.core.files.storage import Storage, StoredImage
    from camelot.core.resources import resource_filename

    storage = Storage(upload_to='covers',
                      stored_file_implementation = StoredImage)

    movies = [
        [
            u'The Shining',
            u'The tide of terror that swept America is here.',
            datetime.date(1980, 5, 23),
            (u'Stanley', u'Kubrick',),
            [
                u'Jack Nicholson',
                u'Shelley Duvall',
                u'Danny Lloyd',
                u'Scatman Crothers',
                u'Barry Nelson'
            ],
            [u'Horror',u'Mystery',u'Thriller'],
            u'thriller',
            4,
            u'shining.png',
            u'A family heads to an isolated hotel for the winter where an evil'
            ' and spiritual presence influences the father into violence,'
            ' while his psychic son sees horrific forebodings from the past'
            ' and of the future.'
        ],
        [
            u'The Bourne Identity',
            u'Matt Damon is Jason Bourne.',
            datetime.date(2002, 6, 14),
            (u'Doug', u'Liman'),
            [
                u'Matt Damon',
                u'Franka Potente',
                u'Chris Cooper',
                u'Clive Owen',
                u'Brian Cox'
            ],
            [u'Action',u'Adventure'],
            u'action',
            4,
            u'bourne.png',
            u'A man is picked up by a fishing boat, bullet-riddled and without'
            ' memory, then races to elude assassins and recover from amnesia.'
        ],
        [
            u'Casino Royale',
            u'Discover how James became Bond.',
            datetime.date(2006, 11, 17),
            (u'Martin', u'Campbell'),
            [
                u'Daniel Craig',
                u'Eva Green',
                u'Mads Mikkelsen',
                u'Judi Dench',
                u'Jeffrey',
                u'Wright'
            ],
            [u'Action',u'Adventure'],
            u'action',
            5,
            u'casino.png',
            u"In his first mission, James Bond must stop Le Chiffre, a banker"
            " to the world's terrorist organizations, from winning a"
            " high-stakes poker tournament at Casino Royale in Montenegro."
        ],
        [
            u'Toy Story',
            u'Oooh...3-D.',
            datetime.date(1995, 11, 22),
            (u'John', u'Lasseter'),
            [
                u'Tom Hanks',
                u'Tim Allen',
                u'Don Rickles',
                u'Jim Varney',
                u'Wallace Shawn'
            ],
            [u'Animation',u'Adventure'],
            u'animation',
            4,
            u'toystory.png',
            u"a cowboy toy is profoundly threatened and jealous when a fancy"
            " spaceman toy supplants him as top toy in a boy's room."
        ],
        [
            u"Harry Potter and the Sorcerer's Stone",
            u'Let The Magic Begin.',
            datetime.date(2001, 11, 16),
            (u'Chris', u'Columbus'),
            [
                u'Richard Harris',
                u'Maggie Smith',
                u'Daniel Radcliffe',
                u'Fiona Shaw',
                u'Richard Griffiths'
            ],
            [u'Family',u'Adventure'],
            u'family',
            3,
            u'potter.png',
            u'Rescued from the outrageous neglect of his aunt and uncle, a'
            ' young boy with a great destiny proves his worth while attending'
            ' Hogwarts School of Witchcraft and Wizardry.'
        ],
        [
            u'Iron Man 2',
            u'The world now becomes aware of the dual life of the Iron Man.',
            datetime.date(2010, 5, 17),
            (u'Jon', 'Favreau'),
            [
                u'Robert Downey Jr.',
                u'Gwyneth Paltrow',
                u'Don Cheadle',
                u'Scarlett Johansson',
                u'Mickey Rourke'
            ],
            [u'Action',u'Adventure',u'Sci-fi'],
            u'sci-fi',
            3,
            u'ironman.png',
            u'billionaire Tony Stark must contend with deadly issues involving'
            ' the government, his own friends, as well as new enemies due to'
            ' his superhero alter ego Iron Man.'
        ],
        [
            u'The Lion King',
            u"Life's greatest adventure is finding your place in the Circle of"
            " Life.",
            datetime.date(1994, 6, 24),
            (u'Roger', 'Allers'),
            [
                u'Matthew Broderick',
                u'Jeremy Irons',
                u'James Earl Jones',
                u'Jonathan Taylor Thomas',
                u'Nathan Lane'
            ],
            [u'Animation',u'Adventure'],
            u'animation',
            5,
            u'lionking.png',
            u'Tricked into thinking he killed his father, a guilt ridden lion'
            ' cub flees into exile and abandons his identity as the future'
            ' King.'
        ],
        [
            u'Avatar',
            u'Enter the World.',
            datetime.date(2009, 12, 18),
            (u'James', u'Cameron'),
            [
                u'Sam Worthington',
                u'Zoe Saldana',
                u'Stephen Lang',
                u'Michelle Rodriguez',
                u'Sigourney Weaver'
            ],
            [u'Action',u'Adventure',u'Sci-fi'],
            u'sci-fi',
            5,
            u'avatar.png',
            u'A paraplegic marine dispatched to the moon Pandora on a unique'
            ' mission becomes torn between following his orders and'
            ' protecting the world he feels is his home.'
        ],
        [
            u'Pirates of the Caribbean: The Curse of the Black Pearl',
            u'Prepare to be blown out of the water.',
            datetime.date(2003, 7, 9),
            (u'Gore', u'Verbinski'),
            [
                u'Johnny Depp',
                u'Geoffrey Rush',
                u'Orlando Bloom',
                u'Keira Knightley',
                u'Jack Davenport'
            ],
            [u'Action',u'Adventure'],
            u'action',
            5,
            u'pirates.png',
            u"Blacksmith Will Turner teams up with eccentric pirate \"Captain\""
            " Jack Sparrow to save his love, the governor's daughter, from"
            " Jack's former pirate allies, who are now undead."
        ],
        [
            u'The Dark Knight',
            u'Why so serious?',
            datetime.date(2008, 7, 18),
            (u'Christopher', u'Nolan'),
            [
                u'Christian Bale',
                u'Heath Ledger',
                u'Aaron Eckhart',
                u'Michael Caine',
                u'Maggie Gyllenhaal'
            ],
            [u'Action',u'Drama'],
            u'action',
            5,
            u'darkknight.png',
            u'Batman, Gordon and Harvey Dent are forced to deal with the chaos'
            ' unleashed by an anarchist mastermind known only as the Joker, as'
            ' it drives each of them to their limits.'
        ]
    ]

    visits = {
        u'The Shining': [
            (u'Washington D.C.', 10000, datetime.date(1980, 5, 23)),
            (u'Buesnos Aires', 4000,datetime.date(1980, 6, 12)),
            (u'California', 13000,datetime.date(1980, 5, 23)),
        ],
        u'The Dark Knight': [
            (u'New York', 20000, datetime.date(2008, 7, 18)),
            (u'London', 15000, datetime.date(2008, 7, 20)),
            (u'Tokyo', 3000, datetime.date(2008, 7, 24)),
        ],
        u'Avatar': [
            (u'Shangai', 6000, datetime.date(2010, 1, 5)),
            (u'Atlanta', 3000, datetime.date(2009, 12, 18)),
            (u'Boston', 5000, datetime.date(2009, 12, 18)),
        ],
    }

    for title, short_description, releasedate, (director_first_name, director_last_name), cast, tags, genre, rating, cover, description in movies:
        director = Fixture.insert_or_update_fixture(
            Person,
            fixture_key = u'%s_%s'%(director_first_name, director_last_name),
            values = {'first_name':director_first_name,
                      'last_name':director_last_name}
        )
        movie = Fixture.find_fixture( Movie, title )
        if not movie:
            # use resource_filename, since resource_string seems to mess either with encoding
            # or with line endings, when on windows
            image = resource_filename( 'camelot_example', os.path.join( 'media', 'covers', cover ) )
            stored_image = storage.checkin( image )
            movie = Fixture.insert_or_update_fixture(
                Movie,
                fixture_key = title,
                values = {
                    'title': title,
                    'director':director,
                    'short_description':short_description,
                    'releasedate':releasedate,
                    'rating':rating,
                    'genre':genre,
                    'description':description,
                    'cover':stored_image,
                },
            )
        rep = visits.get(title, None)
        if rep:
            for city, visitors, date in rep:
                Fixture.insert_or_update_fixture(
                    VisitorReport,
                    fixture_key = '%s_%s' % (title, city),
                    values = {
                        'movie': movie,
                        'date': date,
                        'visitors': visitors,
                    }
                )