from ee.influences.models import Influence
from django import newforms as forms
-class AddInfluenceForm(forms.Form):
- contact = forms.CharField(max_length=255, help_text='Which contact will you ask?')
- description = forms.CharField(help_text='What do you want to achieve')
+class InfluenceForm(forms.ModelForm):
+ class Meta:
+ model = Influence
+ fields = ('character', 'contact', 'description')
-def addinfluence(request, character_id):
- character = get_object_or_404(Character, id=character_id)
+def add(request, character_id):
message = None
+
if (request.method == "POST"):
- f = AddInfluenceForm(request.POST)
+ f = InfluenceForm(request.POST)
if (f.is_valid()):
- inf = character.influence_set.create(contact = f.clean_data['contact'], description = f.clean_data['description'])
+ f.save()
message = "Influence added"
f = None
else:
- f = AddInfluenceForm()
+ f = InfluenceForm()
+
+ if f:
+ # Only allow characters of the current user
+ f.fields['character']._set_queryset(request.user.character_set.all())
- return render_to_response('influences/character_addinfluence.html', {'character' : character, 'message' : message, 'form' : f})
+ return render_to_response('influences/character_addinfluence.html', {'message' : message, 'form' : f})
(r'^admin/', include('django.contrib.admin.urls')),
(r'^events/event/(?P<event_id>\d+)/$', 'ee.events.views.event.detail'),
(r'^events/event/(?P<event_id>\d+)/regs$', 'ee.events.views.event.regs'),
+ (r'^influences/add/(\d+)?/?$', 'ee.influences.views.add'),
(r'^influences/$', 'django.views.generic.list_detail.object_list', chars_dict),
(r'^influences/character/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', chars_dict),
- (r'^influences/character/(?P<character_id>\d+)/addinfluence/$', 'ee.influences.views.addinfluence'),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'base/login.html'}),
- (r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login', {'template_name': 'base/login.html'}),
+ (r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login'),
)