Commits

Kevin Veroneau  committed 58cb78a Draft

Updated GameDB model to include tags, added some editing elements to the game_detail.html template.

  • Participants
  • Parent commits 6d5de34

Comments (0)

Files changed (7)

+.pyc

File gamedb/forms.py

     game_type = forms.ChoiceField(choices=Game.TYPE_LIST, required=False)
     genre = forms.ChoiceField(choices=Game.GENRE_LIST, required=False)
     style = forms.ChoiceField(choices=Game.STYLE_LIST, required=False)
+
+class GameForm(forms.ModelForm):
+    class Meta:
+        model = Game
+        fields = ('title', 'description',
+                  'game_type', 'genre', 'style',
+                  'storyline', 'scenario', 'graphics', 'music', 'sfx',
+                  'engine', 'tags',)

File gamedb/models.py

 from django.db import models
 from django.contrib.auth.models import User
 from django.utils.text import slugify
+from tagging.fields import TagField
 
 class CustomComment(models.Model):
     owner = models.ForeignKey(User)
 
 class Game(models.Model):
     TYPE_LIST = (
-        (10, 'RPG Game'),
+        (10, 'RPG'),
         (20, 'Platformer'),
         (30, 'Tech Demo'),
         (40, 'Simulation'),
     disliked_by = models.ManyToManyField(User, blank=True, null=True, related_name='games_disliked')
     date_added = models.DateField(auto_now_add=True)
     updated_on = models.DateField(auto_now=True)
+    tags = TagField()
     def __unicode__(self):
         return u"%s" % self.title
     def save(self, **kwargs):
             self.author = self.owner.username
         return super(Game, self).save(**kwargs)
     def first_screenshot(self):
-        return self.screenshots.all()[0].image.url
+        try:
+            return self.screenshots.all()[0].image.url
+        except IndexError:
+            return ''
     @models.permalink
     def get_absolute_url(self):
         return ('game_detail', [self.slug])

File gamedb/templates/gamedb/game_detail.html

 {% extends "base.html" %}
 {% load ohrrpgce %}
+{% load bs %}
 
 {% block content %}
 <div class="row-fluid">
         <img class="pull-left" src="{{screenshot.image.url}}"/>
         <h3>{{screenshot.title}}</h3>
       </li>
+    {% empty %}
+      No screenshots are currently available...
     {% endfor %}
+    {% if game.owner == user %}<p>{% modal_button 'Upload Screenshot' 'addScreenshot' 'upload' %}<p>{% endif %}
     </ul>
   </div>
   <div class="span3">
       {% for download in game.downloads.all %}
         <a href="#">{{download}}</a><br/>
         <i>Downloaded {{download.download_count}} times.</i>
-      {% endfor %}
+      {% empty %}
+        No Downloads currently available.
+      {% endfor %}{% if game.owner == user %}<p>
+        <div class="btn-group">
+          <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">{% icon 'plus' %}Add Download <span class="caret"></span></a>
+          <ul class="dropdown-menu">
+            <li><a href="#addGame" data-toggle="modal">{% icon 'upload' %}Upload Game</a></li>
+            <li class="nav-header">Link to other game list</li>
+            <li><a href="#linkSS" data-toggle="modal">{% icon 'globe' %}SlimeSalad</a></li>
+            <li><a href="#linkCP" data-toggle="modal">{% icon 'globe' %}CastleParadox</a></li>
+          </ul>
+        </div>
+      </p>{% endif %}
     <div class="alert alert-info">Player comments</div>
     <a href="#">View Comments</a>
     <div class="alert alert-info">Date Added</div>
     {{game.updated_on|date:'l F jS, Y'}}
     </div>
 </div>
+{% modal 'Add Screenshot' 'addScreenshot' game.get_absolute_url %}
+This should be in the modal!
+{% endmodal %}
+{% modal 'Upload Game' 'addGame' game.get_absolute_url %}
+Upload a game file form.
+{% endmodal %}
+{% modal 'Add SlimeSalad link' 'linkSS' game.get_absolute_url %}
+Upload a game file form.
+{% endmodal %}
+{% modal 'Add CastleParadox link' 'linkCP' game.get_absolute_url %}
+Upload a game file form.
+{% endmodal %}
 {% endblock %}

File gamedb/templates/gamedb/game_form.html

+{% extends "base.html" %}
+
+{% block jquery %}
+  $('#id_description').width(500);
+  $('#id_storyline').width(500);
+{% endblock %}
+
+{% block content %}
+          {% if game %}
+          <form class="form-horizontal" action="{% url 'game_edit' game.slug %}" method="post">{% csrf_token %}
+          {% else %}
+          <form class="form-horizontal" action="{% url 'game_add' %}" method="post">{% csrf_token %}
+          {% endif %}
+            <fieldset>
+              <legend>{% if game %}Update Game Details for {{game.title}}{% else %}Add Game to database{% endif %}</legend>
+              {% if game %}
+              <a class="btn btn-danger" href="{% url 'game_detail' game.slug %}">Cancel</a>
+              {% endif %}
+              {% include "bootstrap_form.html" %}
+              <button type="submit" class="btn btn-primary">{% if game %}Save Game{% else %}Add Game{% endif %}</button>
+            </fieldset>
+          </form>
+{% endblock %}

File gamedb/urls.py

 from django.conf.urls import patterns, url
 from django.views.generic.base import TemplateView
 from gamedb.views import ViewGame, GameList, ViewWriter, ViewArtist,\
-    ViewComposer
+    ViewComposer, AddGame
+from django.contrib.auth.decorators import login_required
 
 urlpatterns = patterns('',
     url(r'^$', TemplateView.as_view(template_name='gamedb/homepage.html'), name='gamedb_home'),
+    url(r'^Games/Add$', login_required(AddGame.as_view()), name='game_add'),
     url(r'^Games/$', GameList.as_view(), name='game_list'),
     url(r'^Games/(?P<slug>[\w-]+).html$', ViewGame.as_view(), name='game_detail'),
     url(r'^Writer/(?P<pk>\d+)$', ViewWriter.as_view(), name='writer_detail'),

File gamedb/views.py

 from django.views.generic.detail import DetailView
 from gamedb.models import Game, Writer, Artist, Composer
 from django.views.generic.list import ListView
-from gamedb.forms import FilterForm
+from gamedb.forms import FilterForm, GameForm
+from django.views.generic.edit import CreateView
+from django.shortcuts import redirect
 
 class ViewGame(DetailView):
     model = Game
 
 class ViewComposer(DetailView):
     model = Composer
+
+class AddGame(CreateView):
+    model = Game
+    form_class = GameForm
+    def form_valid(self, form):
+        self.object = form.save(commit=False)
+        self.object.owner = self.request.user
+        self.object.save()
+        return redirect(self.object)