Ejemplo n.º 1
0
def grab_collections(user):
    from models.MovieCollection import MovieCollection
    collections = MovieCollection.get(user.movie_collections)
    assert not None in collections
    i = 0
    for key in user.movie_collections:
        user.movie_collections[i].title = collections[i].title
        user.movie_collections[i].description = collections[i].description
        user.movie_collections[i].id = collections[i].key().id()
        i = i + 1
Ejemplo n.º 2
0
def grab_collections(user):
    from models.MovieCollection import MovieCollection
    collections = MovieCollection.get(user.movie_collections)
    assert not None in collections
    i = 0
    for key in user.movie_collections:
        user.movie_collections[i].title = collections[i].title
        user.movie_collections[i].description = collections[i].description
        user.movie_collections[i].id = collections[i].key().id()
        i = i + 1
Ejemplo n.º 3
0
 def get(self, user):
     templ_vars = { 'user':user }
     url_ending = url_last_part(self.request.url)
     if (url_ending.isdigit()):
         collection = MovieCollection.get_by_id(int(url_ending))
         if collection:
             movies = Movie.get(collection.movies)
             assert not None in movies
             i = 0
             collection.movies = list()
             for key in movies:
                 collection.movies[i] = movies[i]
                 i = i + 1
         templ_vars['collection'] = collection
         return self.render_template('collection.html', templ_vars)
     
     return self.render_template('my_collections.html', templ_vars)
Ejemplo n.º 4
0
    def post(self):
        session = get_current_session()
        user = session.get('user')
        arg_title = self.request.get('title')
        arg_descr = self.request.get('description')
        if (arg_title is None) or (not arg_title):
            return self.response.out.write('need to enter title')

        if not arg_descr:
            return self.response.out.write('need to enter descr, can be empty')

        new_collection = MovieCollection(title=arg_title,
                                         description=arg_descr).put()
        user.movie_collections.append(new_collection)
        user.put()
        update_user_session(user)
        return self.redirect('/')
Ejemplo n.º 5
0
    def get(self, user):
        templ_vars = {'user': user}
        url_ending = url_last_part(self.request.url)
        if (url_ending.isdigit()):
            collection = MovieCollection.get_by_id(int(url_ending))
            if collection:
                movies = Movie.get(collection.movies)
                assert not None in movies
                i = 0
                collection.movies = list()
                for key in movies:
                    collection.movies[i] = movies[i]
                    i = i + 1
            templ_vars['collection'] = collection
            return self.render_template('collection.html', templ_vars)

        return self.render_template('my_collections.html', templ_vars)
Ejemplo n.º 6
0
    def get(self):
        arg_method = self.request.get('method')
        user = get_current_user()
        if user:
            grab_collections(user)

        templ_vars = {'user': user}
        if not arg_method:
            return self.response.out.write(
                render_template('root.html', templ_vars))

        if arg_method == 'delete':
            arg_what = self.request.get('what')
            if not arg_what:
                return self.request.out.write('no what specified.')

            if arg_what == 'users':
                all_users = User.all()
                for user in all_users:
                    user.delete()
                return self.redirect('/')

            if arg_what == 'collections':
                all_colls = MovieCollection.all()
                for col in all_colls:
                    col.delete()
                return self.redirect('/')

            if arg_what == 'movies':
                movies = Movie.all()
                for movie in movies:
                    movie.delete()
                return self.redirect('/')

            if arg_what == 'user_session':
                get_current_session().terminate()
                return self.redirect('/')
            return self.response.out.write(' no valid what')

        return self.response.out.write(' no valid method')
Ejemplo n.º 7
0
 def get(self):
   arg_method = self.request.get('method')
   user = get_current_user()
   if user:
       grab_collections(user)
   
   templ_vars = { 'user':user }
   if not arg_method:
     return self.response.out.write(render_template('root.html', templ_vars))
   
   if arg_method == 'delete':
     arg_what = self.request.get('what')
     if not arg_what:
       return self.request.out.write('no what specified.')
     
     if arg_what == 'users':
       all_users = User.all()
       for user in all_users:
         user.delete()
       return self.redirect('/')
       
     if arg_what == 'collections':
       all_colls = MovieCollection.all()
       for col in all_colls:
         col.delete()
       return self.redirect('/')
     
     if arg_what == 'movies':
       movies = Movie.all()
       for movie in movies:
         movie.delete()
       return self.redirect('/')
     
     if arg_what == 'user_session':
         get_current_session().terminate()
         return self.redirect('/')
     return self.response.out.write(' no valid what')
   
   return self.response.out.write(' no valid method')