Repository: dotkom/onlineweb4

Issue:
Flow with accepting mark rules
The first time a user tries to attend an event with marks, the rules should be presented, and the user must accept these. If they are accepted, the flag for accepting marks should be checked in the user object. 

The next time the user tries to attend an event with marks, he or she does not need to accept the terms again.

However, if the mark rules changes, we must have some way to propagate this through all users so they need to accept the terms changed.



Discussion:
It should go through all users and set False on accepted mark rules.

Perhaps we should also have some way to alert users that they should go accept the mark rules when they log in, so they save time when registering for events and such in the future. This should be a separate ticket if we decide to do it, but I say it's pretty simple.

Some notification widget which extends the dashboard solution we want in the future might be a cool thing. Facebook all the things!


Resolving patch:
diff --git a/apps/events/forms.py b/apps/events/forms.py
--- a/apps/events/forms.py
+++ b/apps/events/forms.py
@@ -2,4 +2,11 @@
 from captcha.fields import CaptchaField
 
 class CaptchaForm(forms.Form):
-    captcha = CaptchaField()
\ No newline at end of file
+    def __init__(self, *args, **kwargs):
+        user = kwargs.pop('user', None)
+        super(CaptchaForm, self).__init__(*args, **kwargs)
+        # Removing mark rules field if user has already accepted the rules
+        if user and  user.mark_rules:
+            del self.fields['mark_rules']
+    mark_rules = forms.BooleanField(label=u'Jeg godtar <a href="/profile/#marks" target="_blank">prikkreglene</a>')
+    captcha = CaptchaField()
diff --git a/apps/events/views.py b/apps/events/views.py
--- a/apps/events/views.py
+++ b/apps/events/views.py
@@ -36,7 +36,7 @@ def details(request, event_id):
     try:
         attendance_event = AttendanceEvent.objects.get(pk=event_id)
         is_attendance_event = True
-        form = CaptchaForm()
+        form = CaptchaForm(user=request.user)
 
         if attendance_event.rule_bundles:
             for rule_bundle in attendance_event.rule_bundles.all():
@@ -86,11 +86,14 @@ def attendEvent(request, event_id):
     if not request.POST:
         messages.error(request, _(u'Vennligst fyll ut skjemaet.'))
         return HttpResponseRedirect(reverse(details, args=[event_id]))
-
-    form = CaptchaForm(request.POST)
+    form = CaptchaForm(request.POST, user=request.user)
 
     if not form.is_valid():
-        messages.error(request, _(u'Du klarte ikke captcha-en. Er du en bot?'))
+        if not 'mark_rules' in request.POST:
+            error_message = u'Du må godta prikkreglene for å melde deg på.'
+        else:
+            error_message = u'Du klarte ikke captcha-en. Er du en bot?'
+        messages.error(request, _(error_message))
         return HttpResponseRedirect(reverse(details, args=[event_id]))
 
     # Check if the user is eligible to attend this event.
@@ -101,6 +104,10 @@ def attendEvent(request, event_id):
     user_eligible = event.is_eligible_for_signup(request.user);
 
     if user_eligible['status']:   
+        # First time accepting mark rules
+        if 'mark_rules' in form.cleaned_data:
+            request.user.mark_rules = True
+            request.user.save()
         Attendee(event=attendance_event, user=request.user).save()
         messages.success(request, _(u"Du er nå påmeldt på arrangementet!"))
         return HttpResponseRedirect(reverse(details, args=[event_id]))


Test patch: