Commits

Kevin Veroneau committed 515d482

Added email notification for genre watching, updated how the latest movie list is generated.

Comments (0)

Files changed (7)

collection/models.py

             if omdb['Response'] == 'True':
                 self.imdb = omdb['imdbID']
                 self.poster = omdb['Poster'] if omdb['Poster'] != 'N/A' else None
-                self.year = int(omdb['Year'])
+                try:
+                    self.year = int(omdb['Year'])
+                except:
+                    pass
                 self.released = datetime.datetime.strptime(omdb['Released'], "%d %b %Y") if omdb['Released'] != 'N/A' else None
                 self.length = get_length(omdb['Runtime']) if omdb['Runtime'] != 'N/A' else None
                 self.plot = omdb['Plot']

collection/templates/collection/fragments/movie_posters.html

 <ul class="thumbnails">
     {% for movie in movie_list %}
-    <li class="span{{span|default:'4'}}"><a href="{{movie.get_absolute_url}}" class="thumbnail"><img src="{% if movie.poster_img %}{{movie.poster_img.url}}{% endif %}" alt="{{movie.title}}"/></a></li>
+    <li class="span{{span|default:'4'}}"><a href="{{movie.get_absolute_url}}" class="thumbnail"><img width="300" height="445" src="{% if movie.poster_img %}{{movie.poster_img.url}}{% endif %}" alt="{{movie.title}}"/></a></li>
     {% endfor %}
 </ul>

collection/templates/collection/genre_list.html

   <tbody>
     {% cache 3600 genre_list %}
     {% for genre in genre_list %}
-    <tr><td>{{genre|link}}</td><td>{{genre.movie_set.count}}</td><td>{{genre.movie_set.highest_rated|link}}</td></tr>
+    <tr><td>{{genre|link}}{% if user.is_authenticated %}<a class="btn" href="{% url 'genre_watchlist' genre.slug %}"><i class="icon-thumbs-up"></i></a>{% endif %}</td><td>{{genre.movie_set.count}}</td><td>{{genre.movie_set.highest_rated|link}}</td></tr>
     {% endfor %}
     {% endcache %}
   </tbody>

collection/templates/collection/notifications/new_movie.txt

+Hey {{user.get_full_name}}!
+
+  Nick just added a {{movie.genre}} movie!  A little bird told me that you like these kind of movies.
+  
+  Movie title: {{movie}}
+  URL: {{movie.get_absolute_url}}
+
+See you at Nick's for the next exciting {{movie.genre}} movie!

collection/templatetags/moviedb.py

 from django import template
 from collection.models import Movie
+import datetime
 
 register = template.Library()
 
 @register.inclusion_tag('collection/fragments/movie_posters.html')
 def latest_movies():
-    movie_list = Movie.objects.order_by('-added_on')[:9]
+    daycheck = datetime.date.today()-datetime.timedelta(days=30)
+    movie_list = Movie.objects.filter(added_on__gte=daycheck).order_by('-added_on')
     return {'movie_list':movie_list, 'span':'4'}
 
 @register.simple_tag

collection/views.py

 from django.http.response import HttpResponseRedirect, Http404
 from django.contrib.auth.models import User
 from django.contrib.auth import authenticate, login
+from django.template.loader import get_template
+from django.template.context import Context
 
 LENGTH_STAMP = datetime.datetime(1983, 05, 10)  # This is used to determine the length of a movie title. Trivia, what date is this from?
 
 class AddMovie(OnlyNickMixin, CreateView):
     model = Movie
     form_class = MovieForm
+    def form_valid(self, form):
+        self.object = form.save()
+        for watchlist in self.object.genre.watchlist_set.all():
+            body = get_template("collection/notifications/new_movie.txt").render(Context({'user':watchlist.owner, 'movie':self.object}))
+            watchlist.owner.email_user('Nick added a new %s movie' % self.object.genre, body)
+        return redirect(self.object)
 
 class MovieDetail(DetailView):
     model = Movie

templates/base.html

       {% endif %}
 {% block base_content %}{% endblock %}
     <footer>
-      <p>&copy; 2013 Cinema Nick. All rights reserved. &middot; Website development by <a href="https://www.veroneau.net/">Kevin Veroneau</a> &middot; 
+      <p>&copy; 2013-2014 Cinema Nick. All rights reserved. &middot; Website development by <a href="https://www.veroneau.net/">Kevin Veroneau</a> &middot; 
       <a href="https://www.veroneau.net/SourceCode/cinemanick/trunk/collection/views.py/cat">Source Code</a> licensed under the GPLv2.</p>
     </footer>
     </div> <!-- /container -->