Exemple #1
0
def evesch_login(request, template_name=None):
    if request.POST:
        form = EveschLoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect(reverse("home"))
                    # Redirect to a success page.
                else:
                    template_name = "core/message.html"
                    message = Message(title=_("Disabled Account"), text=_("Disabled Account"))
                    message.addlink(_("Back"), reverse("account_auth_login"))
                    context = {"message": message}
            else:
                template_name = "core/message.html"
                message = Message(title=_("Invalid Login"), text=_("Invalid Login"))
                message.addlink(_("Back"), reverse("account_auth_login"))
                context = {"message": message}
        else:
            context = {"form": form}
    else:
        form = EveschLoginForm()
        context = {"form": form}
    return render_to_response(template_name, context, context_instance=RequestContext(request))
Exemple #2
0
def org_remove(request,org_short_name=None,template_name=None):
    """ Removes an organization """
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Remove Org"), text=_("You cannot remove an organization that you do not belong to."))
            message.addlink(_("Continue"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_remove_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Remove Org"), text=_("You cannot remove this organization because you do not have permission to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        context = {'current_org':current_org}
        if request.method == 'POST':
            current_org.org_active = False
            current_org.save()
            return HttpResponseRedirect(reverse('org_orgs_list',))
        else:
            pass
    else:
        template_name = "core/message.html"
        context = {'message':message }     
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #3
0
def org_add(request,template_name=None):
    """ Adds an organization """
    
    current_user, message = get_current_user(request.user)
    if not message:
        show_dialog=False        
        if request.method == 'POST':
            form = OrganizationForm(request.POST)
            if form.is_valid():
                current_org = form.save()
                current_org.save()
                groups = UserGroup.objects.init_org_groups(current_org, current_user)
                eventtypes = EventType.objects.init_event_types(current_org)
    
                message = Message(title=_("Organization Added"), text=_("Organization Added"))
                message.addlink(_("View"),current_org.get_absolute_url())
                message.addlink(_("Edit"),reverse('org_org_edit',kwargs={'org_short_name':current_org.org_short_name,}))
                if request.POST.get("dialog",'') == "False":
                    template_name = "core/message.html"
                    show_dialog=False
                else:
                    show_dialog=True
                context = {'message':message,'current_org':current_org,'form':form,'show_dialog':show_dialog,}                    
            else:
                context = { 'form':form,'show_dialog':show_dialog,}
        else:
            form = OrganizationForm()
            context = { 'form':form } 
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))    
Exemple #4
0
def groupuser_remove(request, org_short_name, group_hash, group_user, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message: 
        current_usergroup, message = UserGroup.objects.get_current_usergroup(group_hash)
    if not message:
        group_user, message = get_current_user(group_user)
    if not message:
        operms = current_org.org_perms(current_user) 
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove Group"), text=_("You cannot remove a group member in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_remove_groupmember']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove Event Type"), text=_("You do not have permission to remove a group member in this organization."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        #raise AssertionError(group_user)
        if group_user.get_user_groups().filter(id=current_usergroup.id):
            group_user.user_groups.remove(current_usergroup)
            return HttpResponseRedirect(reverse('egroup_group_edit',kwargs={'org_short_name':current_org.org_short_name,'group_hash':current_usergroup.group_hash,} ) )
        context  = {'current_org':current_org,'current_group':current_usergroup,}
    else:
        template_name = "core/message.html"
        context = {'message':message,'current_org':current_org,}
    return render_to_response(template_name,context, context_instance=RequestContext(request))
Exemple #5
0
def org_member_remove(request,org_short_name=None, username=None, template_name=None):
    current_user, message = get_current_user(request.user)
    if not message:
        current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_member, message = get_current_user(username)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Remove User"), text=_("You cannot remove a user in an organization that you do not belong to."))
            message.addlink(_("Continue"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_remove_users']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Remove Member"), text=_("You cannot remove this member because you do not have permission to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if request.method == 'POST':
            current_member.user_organizations.remove(current_org)
            return HttpResponseRedirect(current_org.get_absolute_url())
        else:
            pass
        context = {'current_org':current_org, 'current_member':current_member, }
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))    
Exemple #6
0
def evesch_password_reset(request, template_name=None):
    if request.user.is_authenticated():
        template_name = "core/message.html"
        message = Message(
            title=_("Cannot Reset"),
            text=_("You cannot reset your password while logged in."))
        message.addlink(_("Back"), reverse('home'))
        context = {
            'message': message,
        }
    else:
        if request.POST:
            session_captcha = request.session.get('signup_captcha', '-1')
            form = PasswordResetForm(session_captcha, request.POST)
            if form.is_valid():
                post_email = form.cleaned_data['email']
                post_username = form.cleaned_data['username']
                if post_email:
                    message, user = get_current_user_by_email(post_email,
                                                              message=None)
                else:
                    message, user = get_current_user(post_username,
                                                     message=None)

                return HttpResponseRedirect(
                    reverse('account_password_reset_sent'))
        else:
            form = PasswordResetForm(None)
        context = {
            'form': form,
        }
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #7
0
def user_settings(request, template_name=None):
    quick_message = ""
    current_user, message = get_current_user(request.user)
    if not message:
        show_dialog=False
        if request.method == 'POST':
                form = UserForm(request.POST, instance=current_user)
                if form.is_valid():
                    form.save()
                    message = Message(title=_("Settings Saved"), text=_("Settings Saved"))
                    message.addlink(_("View"),reverse('euser_user_view',kwargs={'username':current_user.username,}))
                    message.addlink(_("Edit"),reverse('euser_user_settings'))
                    quick_message = _("Saved")
                    if request.POST.get("dialog",'') == "False":
                        template_name = "core/message.html"
                        show_dialog=False
                    else:
                        show_dialog=True
        else:
                form = UserForm(instance=current_user)
        context = {'current_user':current_user,'form':form,'quick_message':quick_message,'message':message,'show_dialog':show_dialog,}
    else:
        template_name = "core/message.html"
        context = {'message':message,}

    return render_to_response(template_name,context, context_instance=RequestContext(request))
Exemple #8
0
def org_members(request,org_short_name,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Edit Org"), text=_("You cannot view members of an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        members_page = ePage(1)
        if request.GET.__contains__("members_page"): 
            try:
                members_page.curr  = int(request.GET['members_page'])
            except:
                members_page.curr = 1
        members = current_org.get_members()
        members_page.set_pages(Paginator(members, 48))
        context = {'current_org':current_org,'members':members_page,'ajax_page_members': reverse('org_org_user_list_ajax', kwargs={'org_short_name':current_org.org_short_name,})}
    else:
        template_name = "core/message.html"
        context = {'message':message }  
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #9
0
def event_remove(request,org_short_name,event_hash,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(event_hash, message) 
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:
        eperms = current_event.event_perms(current_user)
        if not eperms['can_remove_event']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Delete Event"), text=_("You do not have permission to delete this event"))        
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:    
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove Event"), text=_("You cannot remove an event in an organization that you do not belong to."))
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,'current_event':current_event}
    if not message:
        if request.method == 'POST':
            current_event.event_active = False
            current_event.save()
            return HttpResponseRedirect(reverse('event_events_list',kwargs={'org_short_name':current_org.org_short_name,}))
        else:
            context = {'current_org':current_org,'current_event':current_event }
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #10
0
def eventtype_remove(request, org_short_name,eventtype_hash,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_remove_type']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove Event Type"), text=_("You do not have permission to remove an event type in this organization."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:    
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove Event Type"), text=_("You cannot remove an event type in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        try:
            event_type = current_org.eventtype_set.get(type_hash=eventtype_hash)
            if request.method == 'POST':
                event_type.type_active = False
                event_type.save()
                return HttpResponseRedirect(current_org.get_absolute_url())
            else:
                context = {'current_org':current_org,'event_type':event_type }
        except ObjectDoesNotExist:
            template_name = "error.html"
            context = {'error':_("Event Type does not exist ")} 
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #11
0
def evesch_signup_success(request, template_name=None):
    template_name = "core/message.html"
    message = Message(
        title=_("Success"),
        text=_("Congratulations! You have successfully registered for Evesch.com.  Please proceed to the login page."),
    )
    message.addlink(_("Login"), reverse("account_auth_login"))
    context = {"message": message}
    return render_to_response(template_name, context, context_instance=RequestContext(request))
Exemple #12
0
def eventtype_remove(request,
                     org_short_name,
                     eventtype_hash,
                     template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_remove_type']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove Event Type"),
                text=
                _("You do not have permission to remove an event type in this organization."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove Event Type"),
                text=
                _("You cannot remove an event type in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        try:
            event_type = current_org.eventtype_set.get(
                type_hash=eventtype_hash)
            if request.method == 'POST':
                event_type.type_active = False
                event_type.save()
                return HttpResponseRedirect(current_org.get_absolute_url())
            else:
                context = {
                    'current_org': current_org,
                    'event_type': event_type
                }
        except ObjectDoesNotExist:
            template_name = "error.html"
            context = {'error': _("Event Type does not exist ")}
    else:
        template_name = "core/message.html"
        context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #13
0
def evesch_signup(request, template_name=None):
    if request.user.is_authenticated():
        template_name = "core/message.html"
        message = Message(title=_("Cannot Signup"), text=_("You cannot signup for a new user account while logged in."))
        message.addlink(_("Back"), reverse("home"))
        context = {"message": message}
    else:
        if request.POST:
            session_captcha = request.session.get("signup_captcha", "-1")
            # raise AssertionError(session_captcha)
            form = SignupForm(session_captcha, request.POST)
            if form.is_valid():
                post_email = form.cleaned_data["email"]
                post_username = form.cleaned_data["username"]
                post_password = form.cleaned_data["password"]
                user = get_user_model()(username=post_username, email=post_email)
                user.first_name = post_username
                user.last_name = ""
                user.is_superuser = False
                user.is_staff = False
                user.is_active = False
                user.set_password(post_password)
                user.security_hash = "".join(random.sample(KEYS, 24))
                user.save()

                host = request.META["HTTP_HOST"]
                subject = "Evesch Registration Confirmation"
                email_body = render_to_string(
                    "core/email_registration_confirmation.html",
                    {
                        "username": user.username,
                        "link": "http://"
                        + host
                        + reverse("account_signup_confirm")
                        + "?registration_confirmation="
                        + user.security_hash,
                        "registration_confirmation": user.security_hash,
                    },
                )
                email_from = ""
                email_recipients = [post_email]
                # Create a new thread in Daemon mode to send message
                t = threading.Thread(
                    target=send_mail,
                    args=[subject, email_body, email_from, email_recipients],
                    kwargs={"fail_silently": True},
                )
                t.setDaemon(True)
                t.start()
                return HttpResponseRedirect(reverse("account_signup_confirm"))
        else:
            form = SignupForm(None)
        context = {"form": form}
    return render_to_response(template_name, context, context_instance=RequestContext(request))
Exemple #14
0
def org_member_invite(request,org_short_name=None, template_name=None):
    current_user, message = get_current_user(request.user)
    invited_users = get_user_model().objects.none()
    if not message:
        current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Invite User"), text=_("You cannot invite a user to an organization that you do not belong to."))
            message.addlink(_("Continue"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_invite_users']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Invite Member"), text=_("You cannot invite people to this organization because you do not have permission to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        invited_users_page = ePage(1)
        org_invites = current_org.invite_set.all()
        invited_users = get_user_model().objects.filter(user_invites_set__in=org_invites)       
        if request.method == 'POST':
            form = OrganizationInviteMember(request.POST)
            if form.is_valid():
                user_list = form.cleaned_data['invite_list'].strip().strip(',').split(',')
                new_user_list = []
                for user in user_list:
                    new_user_list.append(user.strip().strip(','))
                new_invited_users = get_user_model().objects.filter(username__in=new_user_list).exclude(user_invites_set__in=org_invites)
                for user in new_invited_users:
                    i = OrgInvite()
                    i.user = user
                    i.org = current_org
                    i.direction = True
                    i.save()
                invited_users = invited_users | new_invited_users  
        else:
            form = OrganizationInviteMember()

            if request.GET.__contains__("members_page"): 
                try:
                    members_page.curr = int(request.GET['members_page'])
                except:
                    members_page.curr = 1 
                
        invited_users_page.set_pages(Paginator(invited_users, 5))

        context = {'current_org':current_org,'form':form,'invited_users':invited_users_page,'ajax_page_members':reverse('org_org_invites_list_ajax', kwargs={'org_short_name':current_org.org_short_name,})}
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))   
Exemple #15
0
def evesch_signup_success(request, template_name=None):
    template_name = "core/message.html"
    message = Message(
        title=_("Success"),
        text=
        _("Congratulations! You have successfully registered for Evesch.com.  Please proceed to the login page."
          ))
    message.addlink(_("Login"), reverse('account_auth_login'))
    context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #16
0
def event_remove(request, org_short_name, event_hash, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(
            event_hash, message)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message:
        eperms = current_event.event_perms(current_user)
        if not eperms['can_remove_event']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Delete Event"),
                text=_("You do not have permission to delete this event"))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove Event"),
                text=
                _("You cannot remove an event in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {'message': message, 'current_event': current_event}
    if not message:
        if request.method == 'POST':
            current_event.event_active = False
            current_event.save()
            return HttpResponseRedirect(
                reverse('event_events_list',
                        kwargs={
                            'org_short_name': current_org.org_short_name,
                        }))
        else:
            context = {
                'current_org': current_org,
                'current_event': current_event
            }
    else:
        template_name = "core/message.html"
        context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #17
0
def delete(request, org_short_name, extra_context={}, next_override=None):
    message = None
    current_org, message = Organization.objects.get_current_org(org_short_name, message)
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Edit Org Photo"), text=_("You cannot edit an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_edit_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Edit Org Photo"), text=_("You cannot edit this organization because you do not have permission to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:        
        avatars = Avatar.objects.filter(org=current_org).order_by('-primary')
        if avatars.count() > 0:
            avatar = avatars[0]
        else:
            avatar = None
        delete_avatar_form = DeleteAvatarForm(request.POST or None, org=current_org)
        if request.method == 'POST':
            if delete_avatar_form.is_valid():
                ids = delete_avatar_form.cleaned_data['choices']
                if unicode(avatar.id) in ids and avatars.count() > len(ids):
                    for a in avatars:
                        if unicode(a.id) not in ids:
                            a.primary = True
                            a.save()
                            break
                Avatar.objects.filter(id__in=ids).delete()
                messages.add_message(request, messages.INFO, _("Successfully deleted the requested avatars."))
                return HttpResponseRedirect(next_override or _get_next(request))
        return render_to_response('avatar/confirm_delete.html',extra_context,
            context_instance = RequestContext(request,
                { 'avatar': avatar, 'avatars': avatars,'current_org':current_org,
                  'delete_avatar_form': delete_avatar_form,'next': next_override or _get_next(request), }
            )
        )
    else:
        template_name = "core/message.html"
        context = {'message':message } 
    return render_to_response('avatar/confirm_delete.html',context,context_instance=RequestContext(request))
Exemple #18
0
def user_settings(request, template_name=None):
    quick_message = ""
    current_user, message = get_current_user(request.user)
    if not message:
        show_dialog = False
        if request.method == 'POST':
            form = UserForm(request.POST, instance=current_user)
            if form.is_valid():
                form.save()
                message = Message(title=_("Settings Saved"),
                                  text=_("Settings Saved"))
                message.addlink(
                    _("View"),
                    reverse('euser_user_view',
                            kwargs={
                                'username': current_user.username,
                            }))
                message.addlink(_("Edit"), reverse('euser_user_settings'))
                quick_message = _("Saved")
                if request.POST.get("dialog", '') == "False":
                    template_name = "core/message.html"
                    show_dialog = False
                else:
                    show_dialog = True
        else:
            form = UserForm(instance=current_user)
        context = {
            'current_user': current_user,
            'form': form,
            'quick_message': quick_message,
            'message': message,
            'show_dialog': show_dialog,
        }
    else:
        template_name = "core/message.html"
        context = {
            'message': message,
        }

    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #19
0
def event_attendee_remove(request,org_short_name,event_hash,att_name,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(event_hash, message)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:    
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove User from Event"), text=_("You cannot remove a user from  an event in an organization that you do not belong to."))
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:
        try:
            current_attendee = current_event.attendee_set.get(att_name=get_user_model().objects.get(username=att_name))
        except ObjectDoesNotExist:
            message = Message(title=_("Cannot Remove User from Event"), text=_("This user is not attending this event."))
            context = {'error':_("Attendee does not exist"),'org_short_name':org_short_name}
            return render_to_response("error.html",context,context_instance=RequestContext(request))
    if not message:
        aperms = current_attendee.att_perms(current_user)
        #raise AssertionError(str(current_user.id) + " - " + str(current_attendee.att_name.id))
        if current_user.id == current_attendee.att_name.id:
            if current_event.event_date  < datetime.today():
                if not aperms['can_remove_attendee_after_event']:
                    template_name = "core/message.html"
                    message = Message(title=_("Cannot Remove User from Event"), text=_("You cannot remove yourself from the event after the event has taken place."))
                    message.addlink(_("Back"),current_event.get_absolute_url())
                    context = {'message':message,}
        else:  
            if not aperms['can_remove_attendee']:
                template_name = "core/message.html"
                message = Message(title=_("Cannot Remove User from Event"), text=_("You do not have permission to remove this attendee."))
                message.addlink(_("Back"),current_event.get_absolute_url())
                context = {'message':message,}
    if not message:         
        if request.method == 'POST':
            current_attendee.delete()
            template_name = "core/message.html"
            message = Message(title=_("Attendee Removed"), text=_("Attendee Removed"))          
            message.addlink(_("Continue"),current_event.get_absolute_url())
            context = {'message':message,}  
        else:
            #raise AssertionError('GOT HERE ' + str(aperms))
            template_name="event/event_attendee_remove.html"
            context = {'current_org':current_org,'event':current_event,'current_attendee':current_attendee}
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #20
0
def org_leave(request, org_short_name, template_name=None):
    current_user, message = get_current_user(request.user)
    if not message:
        current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        operms = current_org.org_perms(current_user)
        if operms['is_memberof_org']:
            if request.method == 'POST':
                current_user.user_organizations.remove(current_org)
                template_name = "core/message.html"
                message = Message(title=_("Left Organization"), text=_("You have left the Organization"))          
                message.addlink(_("Continue"),reverse('org_orgs_list',kwargs={}))
        else:
            template_name = "core/message.html"
            message = Message(title=_("Not a Member"), text=_("You cannot leave this organization because you are not a member of the organization."))      
            message.addlink(_("Back"),reverse('org_orgs_list',kwargs={}))               
        context = {'message':message, 'current_org':current_org, } 
    else:
        template_name = "core/message.html"
        context = {'message':message }      
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #21
0
def org_join(request, org_short_name, template_name=None):
    current_user, message = get_current_user(request.user)
    if not message:
        current_org, message = Organization.objects.get_current_org(org_short_name, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Already a Member"), text=_("You are already a member of this organization." ))          
            message.addlink(_("Continue"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_join_org']:
            template_name = "core/message.html"
            message = Message(title=_("Approval Needed"), text=_("In order to join this organization, you need approval from the organization admin."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:  
        if request.method == 'POST':                    
            current_user.user_organizations.add(current_org)
            current_user.user_invites_set.filter(org=current_org).delete()

            template_name = "core/message.html"
            #message = Message(title="You have Joined the organization", text="Org Join Successful: " + org_user_group.group_name )
            message = Message(title=_("You have Joined the organization"), text=_("Org Join Successful: %s" % (current_org.org_name,)) )            
            message.addlink(_("Continue"),current_org.get_absolute_url())
            context = {'message':message,}
        else:  
            form = OrganizationJoinForm()
            context = {'form':form,'current_org':current_org}
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #22
0
def evesch_login(request, template_name=None):
    if request.POST:
        form = EveschLoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect(reverse('home'))
                    # Redirect to a success page.
                else:
                    template_name = "core/message.html"
                    message = Message(title=_("Disabled Account"),
                                      text=_("Disabled Account"))
                    message.addlink(_("Back"), reverse('account_auth_login'))
                    context = {
                        'message': message,
                    }
            else:
                template_name = "core/message.html"
                message = Message(title=_("Invalid Login"),
                                  text=_("Invalid Login"))
                message.addlink(_("Back"), reverse('account_auth_login'))
                context = {
                    'message': message,
                }
        else:
            context = {
                'form': form,
            }
    else:
        form = EveschLoginForm()
        context = {'form': form}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #23
0
def evesch_password_reset(request, template_name=None):
    if request.user.is_authenticated():
        template_name = "core/message.html"
        message = Message(title=_("Cannot Reset"), text=_("You cannot reset your password while logged in."))
        message.addlink(_("Back"), reverse("home"))
        context = {"message": message}
    else:
        if request.POST:
            session_captcha = request.session.get("signup_captcha", "-1")
            form = PasswordResetForm(session_captcha, request.POST)
            if form.is_valid():
                post_email = form.cleaned_data["email"]
                post_username = form.cleaned_data["username"]
                if post_email:
                    message, user = get_current_user_by_email(post_email, message=None)
                else:
                    message, user = get_current_user(post_username, message=None)

                return HttpResponseRedirect(reverse("account_password_reset_sent"))
        else:
            form = PasswordResetForm(None)
        context = {"form": form}
    return render_to_response(template_name, context, context_instance=RequestContext(request))
Exemple #24
0
def event_add(request,org_short_name,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:    
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Add Event"), text=_("You cannot add an event in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message: 
        if not operms['can_add_event']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Add Event"), text=_("You do not have permission to add an event in this organization."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        show_dialog=False
        if request.method == 'POST':
            form = EventForm(current_org,request.POST)
            if form.is_valid():
                current_event = form.save(commit=False)
                current_event.event_creator_name = current_user
                current_event.event_org = current_org
                current_event.save()
                message = Message(title=_("Event Add Successful"), text=_("Event Add Successful"))
                message.addlink(_("Attend"),reverse('event_attendee_add',kwargs={'org_short_name':current_org.org_short_name,'event_hash':current_event.event_hash}))      
                message.addlink(_("View"),reverse('event_event_view',kwargs={'org_short_name':current_org.org_short_name,'event_hash':current_event.event_hash}))
                message.addlink(_("Edit"),reverse('event_event_edit',kwargs={'org_short_name':current_org.org_short_name,'event_hash':current_event.event_hash}))
                if request.POST.get("dialog",'') == "False":
                    template_name = "core/message.html"
                    show_dialog=False
                else:
                    show_dialog=True
                context = {'message':message,'form':form,'current_org':current_org,'current_event':current_event,'show_dialog':show_dialog,}                            
            else:
                context = {'form':form,'current_org':current_org,'org_short_name':org_short_name,'error':"update",'show_dialog':show_dialog,}
        else:
            form = EventForm(current_org)
            context = {'form':form,'current_org':current_org,'org_short_name':org_short_name}
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name, context, context_instance=RequestContext(request))
Exemple #25
0
def group_add(request,org_short_name,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:
        if not current_org.is_member(request.user):
            template_name = "core/message.html"
            message = Message(title=_("Cannot Add Group"), text=_("You cannot add a group in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_add_group']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Add Group"), text=_("You do not have permission to add a group in this organization."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        show_dialog=False
        if request.method == 'POST':
            form = UserGroupForm(request.POST)
            if form.is_valid():
                new_group= form.save(commit=False)
                new_group.org_name = current_org
                new_group.group_removable=True
                new_group.save()
                
                message = Message(title=_("Group Added"), text=_("You have added a group"))
                message.addlink(_("View"),new_group.get_absolute_url())
                message.addlink(_("Edit"),reverse('egroup_group_edit',kwargs={'org_short_name':current_org.org_short_name,'group_hash':new_group.group_hash}))
                if request.POST.get("dialog",'') == "False":
                    template_name = "core/message.html"
                    show_dialog=False
                else:
                    show_dialog=True
                context = {'current_org':current_org,'form':form,'message':message,'show_dialog':show_dialog,}
            else:
                context = {'current_org':current_org,'form':form,}
        else:
            form = UserGroupForm()
            #context = {'error':"User Add", 'form':form, }
            context = {'current_org':current_org, 'form':form,}
    else:
        template_name = "core/message.html"
        context = {'message':message,}
    return render_to_response(template_name,context, context_instance=RequestContext(request))
Exemple #26
0
def eventtype_edit(request, org_short_name,eventtype_hash,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_edit_type']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Edit Event Type"), text=_("You do not have permission to edit an event type in this organization."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:    
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Edit Event Type"), text=_("You cannot edit a event type in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        try:
            event_type = current_org.eventtype_set.get(type_hash=eventtype_hash, type_active=True)
            show_dialog=False
            if request.method == 'POST':
                form = EventTypeForm(current_org, request.POST, instance=event_type)
                if form.is_valid():
                    form.save()
                    message = Message(title=_("Event Type Save Successful"), text=_("Event Type Edit Successful"))
                    message.addlink(_("Continue"),current_org.get_absolute_url())
                    message.addlink(_("Edit"),reverse('event_eventtype_edit',kwargs={'org_short_name':current_org.org_short_name,'eventtype_hash':event_type.type_hash}))
                    if request.POST.get("dialog",'') == "False":
                        template_name = "core/message.html"
                        show_dialog=False
                    else:
                        show_dialog=True
                    context = {'message':message,'form':form,'message':message,'current_org':current_org,'show_dialog':show_dialog,}                     
                else:
                    context = {'current_org':current_org,'event_type':event_type,'form':form}
            else:
                form = EventTypeForm(current_org, auto_id=False,instance=event_type)
                context = {'current_org':current_org,'event_type':event_type,'form':form}
        except ObjectDoesNotExist:
            template_name = "error.html"
            context = {'error':_("Event Type does not exist") }
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name, context,context_instance=RequestContext(request))
Exemple #27
0
def event_attendees_message(request,org_short_name,event_hash,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(event_hash, message)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Message Users"), text=_("You cannot message users in an organization that you do not belong to."))
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:
        eperms = current_event.event_perms(current_user)
        if not eperms['can_message_event']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Message Users"), text=_("You cannot message users unless you are attending the event."))
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:
        attendees = current_event.get_attendees()  #attendee_set.all()
        if not attendees:
            message = Message(title=_("No attendees"), text=_("No attendees are signed up for this event."))
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:
        if request.method == 'POST':
            form = MessageForm(request.POST)
            if form.is_valid():
                subject = form.cleaned_data['subject']
                body = form.cleaned_data['body']
                template_name = "core/message.html"
                message = Message(title=_("Message Sent"), text=_("Message Sent"))          
                message.addlink("Continue",current_event.get_absolute_url())
                context = {'message':message,}
            else:
                context = {'attendees':attendees,'form':form, 'current_event':current_event }
        else:
            form = MessageForm()
            context = {'attendees':attendees,'form':form, 'current_event':current_event }
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #28
0
def eventtype_add(request,org_short_name,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:    
        if not current_org.is_member(request.user):
            template_name = "core/message.html"
            message = Message(title=_("Cannot Add Event Type"), text=_("You cannot add an event type in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_add_type']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Add Event Type"), text=_("You do not have permission to add an event type in this organization."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        show_dialog=False
        if request.method == 'POST':
            form = EventTypeForm(current_org, request.POST)
            if form.is_valid():
                event_type = form.save(commit=False)
                event_type.org_name = current_org
                event_type.save()
                message = Message(title=_("Add Event Type Successful"), text=_("Add Event Type Successful"))          
                message.addlink(_("Continue"),current_org.get_absolute_url())
                message.addlink(_("Edit"),reverse('event_eventtype_edit',kwargs={'org_short_name':current_org.org_short_name,'eventtype_hash':event_type.type_hash,})) 
                if request.POST.get("dialog",'') == "False":
                    template_name = "core/message.html"
                    show_dialog=False
                else:
                    show_dialog=True
                context = {'message':message,'form':form,'message':message,'current_org':current_org,'show_dialog':show_dialog,}                     
                                          
            else:
                context = {'form':form, 'current_org':current_org}
        else:    
            form = EventTypeForm(current_org)
            context = {'form':form, 'org_short_name':org_short_name,'current_org':current_org}
                #raise AssertionError        
    else:
        context = {'message':message,} 
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #29
0
def event_edit(request,org_short_name,event_hash,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(event_hash, message) 
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:
        eperms = current_event.event_perms(current_user)
        if not eperms['can_edit_event']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Edit Event"), text=_("You do not have permission to edit this event"))        
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Edit Event"), text=_("You cannot edit an event in an organization that you do not belong to."))
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:
        show_dialog=False
        if request.method == 'POST':
            form = EventForm(current_org, request.POST, instance=current_event)
            if form.is_valid():
                form.save()
                message = Message(title=_("Event Saved"), text=_("Event Saved"))
                message.addlink(_("View"),current_event.get_absolute_url())
                message.addlink(_("Edit"),reverse('event_event_edit',kwargs={'org_short_name':current_org.org_short_name,'event_hash':current_event.event_hash}))
                if request.POST.get("dialog",'') == "False":
                    template_name = "core/message.html"
                    show_dialog=False
                else:
                    show_dialog=True
            context = {'form':form,'current_org':current_org,'event':current_event,'message':message,'show_dialog':show_dialog}
        else:
            form = EventForm(current_org,auto_id=False,instance=current_event)
            context = {'form':form,'current_org':current_org,'event':current_event,}
    else:
        template_name = "core/message.html"
        context =  {'message':message }
    return render_to_response(template_name, context, context_instance=RequestContext(request))  
Exemple #30
0
def org_edit(request,org_short_name=None,template_name=None):
    """ Edits an organization """
    
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Edit Org"), text=_("You cannot edit an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_edit_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Edit Org"), text=_("You cannot edit this organization because you do not have permission to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        show_dialog=False
        if request.method == 'POST':
            form = OrganizationFormEdit(request.POST, instance=current_org)
            if form.is_valid():
                form.save()
                message = Message(title=_("Organization Changes Saved"), text=_("Organization Changes Saved"))
                message.addlink(_("View"),current_org.get_absolute_url())
                message.addlink(_("Edit"),reverse('org_org_edit',kwargs={'org_short_name':current_org.org_short_name,}))
                if request.POST.get("dialog",'') == "False":
                    template_name = "core/message.html"
                    show_dialog=False
                else:
                    show_dialog=True
            context = {'org_short_name':org_short_name,'form':form,'current_org':current_org,'message':message,'show_dialog':show_dialog,}                
        else:
            form = OrganizationFormEdit(auto_id=False,instance=current_org)
            context = {'org_short_name':org_short_name,'form':form,'current_org':current_org}
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name, context,context_instance=RequestContext(request))
Exemple #31
0
def group_remove(request, org_short_name, group_hash, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message: 
        current_usergroup, message = UserGroup.objects.get_current_usergroup(group_hash)
    if not message:
        if not current_usergroup.group_removable:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove Default Group"), text=_("You cannot remove this group since it is a default group."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}            
    if not message:
        operms = current_org.org_perms(current_user) 
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove Group"), text=_("You cannot remove a group in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_remove_group']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Remove Event Type"), text=_("You do not have permission to remove a group in this organization."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if request.method == 'POST':
            current_usergroup.delete()
            return HttpResponseRedirect(current_org.get_absolute_url())
        else:
            pass
        context = {'current_org':current_org,'current_usergroup':current_usergroup}
    else:
        template_name = "core/message.html"
        context = {'message':message,'current_org':current_org,}
    return render_to_response(template_name,context, context_instance=RequestContext(request))
Exemple #32
0
def event_attendee_add(request,org_short_name,event_hash,template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(event_hash, message)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:    
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Attend Event"), text=_("You cannot register for an event in an organization that you do not belong to."))
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not current_event.event_open:
            template_name = "core/message.html"
            text = _("This event is closed.  Contact the event coordinator with comments or concerns.")
            message = Message(title=_("Event Closed"), text=text)
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,} 
    if not message:
        if not current_event.is_within_signup_deadline():
            template_name = "core/message.html"
            #raise AssertionError()
            text = _("You may not register for this event after %s" ) % (current_event.event_signup_deadline.strftime("%A %m/%d/%Y"))
            message = Message(title=_("Attendee Add Error"), text=text)
            message.addlink(_("Back"),current_event.get_absolute_url())
            context = {'message':message,}
    if not message:
        if Attendee.objects.filter(att_name=current_user,att_event=current_event):
            template_name = "core/message.html"
            message = Message(title=_("Already Registered"), text=_("Attendee is already registered"))           
            message.addlink(_("Continue"),current_event.get_absolute_url())
            context = {'message':message,}  
    if not message:
        if request.method == 'POST':
            form = AttendeeForm(current_event,request.POST)

            #raise AssertionError(form.data)
            if form.is_valid(): 
                attendee = form.save(commit=False)
                attendee.att_name = current_user
                attendee.att_event = current_event
                attendee.att_ip = request.META['REMOTE_ADDR'] 
                attendee.att_added_date = datetime.now()
                if current_event.event_track_hours:
                    attendee.att_hours = form.cleaned_data["att_hours"]
                if current_event.att_header_col1:
                    attendee.att_col1 = form.cleaned_data["att_col1"]
                if current_event.att_header_col2:
                    attendee.att_col2 = form.cleaned_data["att_col2"]
                if current_event.att_header_col3:
                    attendee.att_col3 = form.cleaned_data["att_col3"]
                if current_event.att_header_col4:
                    attendee.att_col4 = form.cleaned_data["att_col4"]
                if current_event.att_header_col5:
                    attendee.att_col5 = form.cleaned_data["att_col5"]
                if current_event.att_header_col6:
                    attendee.att_col6 = form.cleaned_data["att_col6"]                
                attendee.save()
                #context = {'current_org':current_org,'current_event':current_event,'current_user':current_user,'form':form }
                template_name = "core/message.html"
                message = Message(title=_("Registration Complete"), text=_("You have Registered for this event"))           
                message.addlink(_("Continue"),current_event.get_absolute_url())
                context = {'message':message,}
            else:                                    
                context = {'current_org':current_org,'current_event':current_event,'current_user':current_user,'form':form }
        else:
            form = AttendeeForm(current_event)
            context = {'current_org':current_org,'current_event':current_event,'current_user':current_user,'form':form }
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #33
0
def event_attendees_message(request,
                            org_short_name,
                            event_hash,
                            template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(
            event_hash, message)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Message Users"),
                text=
                _("You cannot message users in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        eperms = current_event.event_perms(current_user)
        if not eperms['can_message_event']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Message Users"),
                text=
                _("You cannot message users unless you are attending the event."
                  ))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        attendees = current_event.get_attendees()  #attendee_set.all()
        if not attendees:
            message = Message(
                title=_("No attendees"),
                text=_("No attendees are signed up for this event."))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if request.method == 'POST':
            form = MessageForm(request.POST)
            if form.is_valid():
                subject = form.cleaned_data['subject']
                body = form.cleaned_data['body']
                template_name = "core/message.html"
                message = Message(title=_("Message Sent"),
                                  text=_("Message Sent"))
                message.addlink("Continue", current_event.get_absolute_url())
                context = {
                    'message': message,
                }
            else:
                context = {
                    'attendees': attendees,
                    'form': form,
                    'current_event': current_event
                }
        else:
            form = MessageForm()
            context = {
                'attendees': attendees,
                'form': form,
                'current_event': current_event
            }
    else:
        template_name = "core/message.html"
        context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #34
0
def group_remove(request, org_short_name, group_hash, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message:
        current_usergroup, message = UserGroup.objects.get_current_usergroup(
            group_hash)
    if not message:
        if not current_usergroup.group_removable:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove Default Group"),
                text=_(
                    "You cannot remove this group since it is a default group."
                ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove Group"),
                text=
                _("You cannot remove a group in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if not operms['can_remove_group']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove Event Type"),
                text=
                _("You do not have permission to remove a group in this organization."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if request.method == 'POST':
            current_usergroup.delete()
            return HttpResponseRedirect(current_org.get_absolute_url())
        else:
            pass
        context = {
            'current_org': current_org,
            'current_usergroup': current_usergroup
        }
    else:
        template_name = "core/message.html"
        context = {
            'message': message,
            'current_org': current_org,
        }
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #35
0
def group_edit(request, org_short_name, group_hash, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message: 
        current_usergroup, message = UserGroup.objects.get_current_usergroup(group_hash)
    if not message:
        if not current_org.is_member(request.user):
            template_name = "core/message.html"
            message = Message(title=_("Cannot Edit Group"), text=_("You cannot edit a group in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_edit_group']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Edit Group"), text=_("You do not have permission to edit a group in this organization."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        groupuser_page = ePage(1)
        if request.GET.__contains__("members_page"): 
            try:
                groupuser_page.curr  = int(request.GET['members_page'])
            except:
                groupuser_page.curr = 1
        groupusers = current_usergroup.get_members()
        groupuser_page.set_pages(Paginator(groupusers, 48))
        
        group_add_member_form = GroupAddMemberForm()
        edit_form = UserGroupEditForm(instance=current_usergroup)
        show_dialog=False
        if request.method == 'POST':
            action = request.POST.get('action','')
            p = re.compile('^[\w]{1,20}$')
            if not p.match(action):
                action = ""
            if action == 'group_edit':
                edit_form = UserGroupEditForm(request.POST,instance=current_usergroup)
                if edit_form.is_valid():
                    edit_form.save()
                    message = Message(title=_("Group Changes Saved"), text=_("Group Changes Saved"))
                    message.addlink(_("View"),reverse('egroup_group_view',kwargs={'org_short_name':current_org.org_short_name,'group_hash':current_usergroup.group_hash}))
                    message.addlink(_("Edit"),reverse('egroup_group_edit',kwargs={'org_short_name':current_org.org_short_name,'group_hash':current_usergroup.group_hash}))
                    #return HttpResponseRedirect(current_org.get_absolute_url())
                    if request.POST.get("dialog",'') == "False":
                        template_name = "core/message.html"
                        show_dialog=False
                    else:
                        show_dialog=True
            elif action == 'group_member_add':
                group_add_member_form = GroupAddMemberForm(request.POST)
                if group_add_member_form.is_valid():             
                    user_list = group_add_member_form.cleaned_data['user_list'].strip().strip(',').split(',')
                    new_user_list = []
                    for user in user_list:
                        new_user_list.append(user.strip().strip(','))
                    new_group_users = get_user_model().objects.filter(username__in=new_user_list)
                    for user in new_group_users:
                        user.user_groups.add(current_usergroup)
                        return HttpResponseRedirect(reverse('egroup_group_edit', kwargs={'org_short_name':current_org.org_short_name,'group_hash':current_usergroup.group_hash}))
            else:
                pass
        else:
            pass
        context = {'current_org':current_org,'edit_form':edit_form, 'group_add_member_form':group_add_member_form, 'current_usergroup':current_usergroup, 'groupusers':groupuser_page,'message':message,'show_dialog':show_dialog, 'ajax_page_members': reverse('egroup_group_user_list_ajax', kwargs={'org_short_name':current_org.org_short_name,'group_hash':current_usergroup.group_hash}) }
    else:
        template_name = "core/message.html"
        context = {'message':message,'current_org':current_org,}
    return render_to_response(template_name,context, context_instance=RequestContext(request))
Exemple #36
0
def event_attendee_remove(request,
                          org_short_name,
                          event_hash,
                          att_name,
                          template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(
            event_hash, message)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove User from Event"),
                text=
                _("You cannot remove a user from  an event in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        try:
            current_attendee = current_event.attendee_set.get(
                att_name=get_user_model().objects.get(username=att_name))
        except ObjectDoesNotExist:
            message = Message(title=_("Cannot Remove User from Event"),
                              text=_("This user is not attending this event."))
            context = {
                'error': _("Attendee does not exist"),
                'org_short_name': org_short_name
            }
            return render_to_response("error.html",
                                      context,
                                      context_instance=RequestContext(request))
    if not message:
        aperms = current_attendee.att_perms(current_user)
        #raise AssertionError(str(current_user.id) + " - " + str(current_attendee.att_name.id))
        if current_user.id == current_attendee.att_name.id:
            if current_event.event_date < datetime.today():
                if not aperms['can_remove_attendee_after_event']:
                    template_name = "core/message.html"
                    message = Message(
                        title=_("Cannot Remove User from Event"),
                        text=
                        _("You cannot remove yourself from the event after the event has taken place."
                          ))
                    message.addlink(_("Back"),
                                    current_event.get_absolute_url())
                    context = {
                        'message': message,
                    }
        else:
            if not aperms['can_remove_attendee']:
                template_name = "core/message.html"
                message = Message(
                    title=_("Cannot Remove User from Event"),
                    text=_(
                        "You do not have permission to remove this attendee."))
                message.addlink(_("Back"), current_event.get_absolute_url())
                context = {
                    'message': message,
                }
    if not message:
        if request.method == 'POST':
            current_attendee.delete()
            template_name = "core/message.html"
            message = Message(title=_("Attendee Removed"),
                              text=_("Attendee Removed"))
            message.addlink(_("Continue"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
        else:
            #raise AssertionError('GOT HERE ' + str(aperms))
            template_name = "event/event_attendee_remove.html"
            context = {
                'current_org': current_org,
                'event': current_event,
                'current_attendee': current_attendee
            }
    else:
        template_name = "core/message.html"
        context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #37
0
def group_add(request, org_short_name, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message:
        if not current_org.is_member(request.user):
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Add Group"),
                text=
                _("You cannot add a group in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_add_group']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Add Group"),
                text=
                _("You do not have permission to add a group in this organization."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        show_dialog = False
        if request.method == 'POST':
            form = UserGroupForm(request.POST)
            if form.is_valid():
                new_group = form.save(commit=False)
                new_group.org_name = current_org
                new_group.group_removable = True
                new_group.save()

                message = Message(title=_("Group Added"),
                                  text=_("You have added a group"))
                message.addlink(_("View"), new_group.get_absolute_url())
                message.addlink(
                    _("Edit"),
                    reverse('egroup_group_edit',
                            kwargs={
                                'org_short_name': current_org.org_short_name,
                                'group_hash': new_group.group_hash
                            }))
                if request.POST.get("dialog", '') == "False":
                    template_name = "core/message.html"
                    show_dialog = False
                else:
                    show_dialog = True
                context = {
                    'current_org': current_org,
                    'form': form,
                    'message': message,
                    'show_dialog': show_dialog,
                }
            else:
                context = {
                    'current_org': current_org,
                    'form': form,
                }
        else:
            form = UserGroupForm()
            #context = {'error':"User Add", 'form':form, }
            context = {
                'current_org': current_org,
                'form': form,
            }
    else:
        template_name = "core/message.html"
        context = {
            'message': message,
        }
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #38
0
def event_attendee_add(request,
                       org_short_name,
                       event_hash,
                       template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(
            event_hash, message)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Attend Event"),
                text=
                _("You cannot register for an event in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if not current_event.event_open:
            template_name = "core/message.html"
            text = _(
                "This event is closed.  Contact the event coordinator with comments or concerns."
            )
            message = Message(title=_("Event Closed"), text=text)
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if not current_event.is_within_signup_deadline():
            template_name = "core/message.html"
            #raise AssertionError()
            text = _("You may not register for this event after %s") % (
                current_event.event_signup_deadline.strftime("%A %m/%d/%Y"))
            message = Message(title=_("Attendee Add Error"), text=text)
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if Attendee.objects.filter(att_name=current_user,
                                   att_event=current_event):
            template_name = "core/message.html"
            message = Message(title=_("Already Registered"),
                              text=_("Attendee is already registered"))
            message.addlink(_("Continue"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if request.method == 'POST':
            form = AttendeeForm(current_event, request.POST)

            #raise AssertionError(form.data)
            if form.is_valid():
                attendee = form.save(commit=False)
                attendee.att_name = current_user
                attendee.att_event = current_event
                attendee.att_ip = request.META['REMOTE_ADDR']
                attendee.att_added_date = datetime.now()
                if current_event.event_track_hours:
                    attendee.att_hours = form.cleaned_data["att_hours"]
                if current_event.att_header_col1:
                    attendee.att_col1 = form.cleaned_data["att_col1"]
                if current_event.att_header_col2:
                    attendee.att_col2 = form.cleaned_data["att_col2"]
                if current_event.att_header_col3:
                    attendee.att_col3 = form.cleaned_data["att_col3"]
                if current_event.att_header_col4:
                    attendee.att_col4 = form.cleaned_data["att_col4"]
                if current_event.att_header_col5:
                    attendee.att_col5 = form.cleaned_data["att_col5"]
                if current_event.att_header_col6:
                    attendee.att_col6 = form.cleaned_data["att_col6"]
                attendee.save()
                #context = {'current_org':current_org,'current_event':current_event,'current_user':current_user,'form':form }
                template_name = "core/message.html"
                message = Message(title=_("Registration Complete"),
                                  text=_("You have Registered for this event"))
                message.addlink(_("Continue"),
                                current_event.get_absolute_url())
                context = {
                    'message': message,
                }
            else:
                context = {
                    'current_org': current_org,
                    'current_event': current_event,
                    'current_user': current_user,
                    'form': form
                }
        else:
            form = AttendeeForm(current_event)
            context = {
                'current_org': current_org,
                'current_event': current_event,
                'current_user': current_user,
                'form': form
            }
    else:
        template_name = "core/message.html"
        context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #39
0
def groupuser_remove(request,
                     org_short_name,
                     group_hash,
                     group_user,
                     template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message:
        current_usergroup, message = UserGroup.objects.get_current_usergroup(
            group_hash)
    if not message:
        group_user, message = get_current_user(group_user)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove Group"),
                text=
                _("You cannot remove a group member in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if not operms['can_remove_groupmember']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Remove Event Type"),
                text=
                _("You do not have permission to remove a group member in this organization."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        #raise AssertionError(group_user)
        if group_user.get_user_groups().filter(id=current_usergroup.id):
            group_user.user_groups.remove(current_usergroup)
            return HttpResponseRedirect(
                reverse('egroup_group_edit',
                        kwargs={
                            'org_short_name': current_org.org_short_name,
                            'group_hash': current_usergroup.group_hash,
                        }))
        context = {
            'current_org': current_org,
            'current_group': current_usergroup,
        }
    else:
        template_name = "core/message.html"
        context = {
            'message': message,
            'current_org': current_org,
        }
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #40
0
def change(request, org_short_name, extra_context={}, next_override=None):
    message = None
    current_org, message = Organization.objects.get_current_org(org_short_name, message)
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Edit Org Photo"), text=_("You cannot edit an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        if not operms['can_edit_org']:
            template_name = "core/message.html"
            message = Message(title=_("Can Not Edit Org Photo"), text=_("You cannot edit this organization because you do not have permission to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        avatars = Avatar.objects.filter(org=current_org).order_by('-primary')
        if avatars.count() > 0:
            avatar = avatars[0]
            kwargs = {'initial': {'choice': avatar.id}}
        else:
            avatar = None
            kwargs = {}
        primary_avatar_form = PrimaryAvatarForm( None, org=current_org, **kwargs)
        upload_avatar_form = UploadAvatarForm()
        if request.method == "POST":
            updated = False
            if 'avatar' in request.FILES:
                if avatars.count() >= 4:
                    template_name = "core/message.html"
                    message = Message(title=_("Max uploads reached"), text=_("You cannot upload more than 4 photos."))
                    message.addlink(_("Back"),reverse('org_org_edit_photo',kwargs={'org_short_name':current_org.org_short_name}))
                    message.addlink(_("Delete Photos"),reverse('org_org_delete_photo',kwargs={'org_short_name':current_org.org_short_name}))
                if not message:
                    upload_avatar_form = UploadAvatarForm(request.POST, request.FILES)
                    if upload_avatar_form.is_valid():
                        path = avatar_file_path(org_short_name=current_org.org_short_name,filename="".join(sample(KEYS,12)) + ".jpg")
                        avatar = Avatar(org=current_org, primary=True, avatar=path,)
                        new_file = avatar.avatar.storage.save(path, request.FILES['avatar'])
                        avatar.save()
                        updated = True
                        messages.add_message(request, messages.INFO, _("Successfully uploaded a new organization photo."))
                        return HttpResponseRedirect(next_override or _get_next(request))
                else:
                    template_name = "core/message.html"
                    context = {'message':message }
                    return render_to_response(template_name,context,context_instance=RequestContext(request))                     
            if 'choice' in request.POST:
                primary_avatar_form = PrimaryAvatarForm(request.POST or None, org=current_org, **kwargs)
                if primary_avatar_form.is_valid():
                    avatar = Avatar.objects.get(id=primary_avatar_form.cleaned_data['choice'])
                    avatar.primary = True
                    avatar.save()
                    updated = True
                    messages.add_message(request, messages.INFO, _("Successfully updated the organization photo."))
                    return HttpResponseRedirect(next_override or _get_next(request))
        
        template_name='avatar/change.html'
        context = { 'current_org':current_org, 'avatar': avatar, 'avatars': avatars,'primary_avatar_form': primary_avatar_form,
                  'upload_avatar_form':upload_avatar_form,'next': next_override or _get_next(request), }
    else:
        template_name = "core/message.html"
        context = {'message':message } 
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #41
0
def event_edit(request, org_short_name, event_hash, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_event, message = current_org.get_current_event(
            event_hash, message)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message:
        eperms = current_event.event_perms(current_user)
        if not eperms['can_edit_event']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Edit Event"),
                text=_("You do not have permission to edit this event"))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Edit Event"),
                text=
                _("You cannot edit an event in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_event.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        show_dialog = False
        if request.method == 'POST':
            form = EventForm(current_org, request.POST, instance=current_event)
            if form.is_valid():
                form.save()
                message = Message(title=_("Event Saved"),
                                  text=_("Event Saved"))
                message.addlink(_("View"), current_event.get_absolute_url())
                message.addlink(
                    _("Edit"),
                    reverse('event_event_edit',
                            kwargs={
                                'org_short_name': current_org.org_short_name,
                                'event_hash': current_event.event_hash
                            }))
                if request.POST.get("dialog", '') == "False":
                    template_name = "core/message.html"
                    show_dialog = False
                else:
                    show_dialog = True
            context = {
                'form': form,
                'current_org': current_org,
                'event': current_event,
                'message': message,
                'show_dialog': show_dialog
            }
        else:
            form = EventForm(current_org,
                             auto_id=False,
                             instance=current_event)
            context = {
                'form': form,
                'current_org': current_org,
                'event': current_event,
            }
    else:
        template_name = "core/message.html"
        context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #42
0
def org_reports(request,org_short_name, type='generic', template_name=None):
    min_event_date = datetime.today() - timedelta(120)
    max_event_date = datetime.date
    if request.method == 'POST': 
        form = ReportFilterForm(initial=request.POST)
        if form.is_valid():
            min_event_date = form.cleaned_data['min_event_date']
            max_event_date = form.cleaned_data['max_event_date']
        raise AssertionError(str(min_event_date) + " " + str(max_event_date) )
    else:
        form = ReportFilterForm()
    
    class OrgWrapper(object):
        def __init__(self):
            eventtypes = []
            users = []
            
    class EventTypeWrapper(object):
        def __init__(self):
            eventtype = None
            events = []
    
    class UserWrapper(object):
        def __init__(self):
            user = None
            events = []
            attending = []
            
    org_w = None
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:    
        current_user, message = get_current_user(request.user)
    if not message:    
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(title=_("Cannot Add Event"), text=_("You cannot add an event in an organization that you do not belong to."))
            message.addlink(_("Back"),current_org.get_absolute_url())
            context = {'message':message,}
    if not message:
        
        if type == 'user':
            type_display = _("Report grouped by User")
            org_w = OrgWrapper()
            org_w.users = []
            for user in current_org.get_members():
                user_w = UserWrapper()
                user_w.user = user
                user_w.attending = []
                user_w.events = []
                for att in user.get_attending_events():
                    user_w.attending.append(att)
                    user_w.events.append(att.att_event)
                org_w.users.append(user)
            
                # needs more code here
                
        elif type == 'eventtype':            
            type_display = _("Report grouped by Event Type")
            org_w = OrgWrapper()
            org_w.eventtypes = []
            for event_type in current_org.get_eventtypes():
                et_w = EventTypeWrapper()
                et_w.events = []
                et_w.eventtype = event_type
                for event in event_type.get_events().filter():
                    et_w.events.append(event)
                #raise AssertionError(et_w.events)
                org_w.eventtypes.append(et_w)
                del et_w

        elif type == 'event':
            type_display = _("Report grouped by Event")
        else:
            type_display = _("Report Types")
        
        # report code here
        context = {'current_org':current_org,'org_w':org_w,'type':type,'type_display':type_display,'form':form}
    else:
        template_name = "core/message.html"
        context = {'message':message }
    return render_to_response(template_name,context,context_instance=RequestContext(request))
Exemple #43
0
def eventtype_edit(request,
                   org_short_name,
                   eventtype_hash,
                   template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_edit_type']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Edit Event Type"),
                text=
                _("You do not have permission to edit an event type in this organization."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Edit Event Type"),
                text=
                _("You cannot edit a event type in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        try:
            event_type = current_org.eventtype_set.get(
                type_hash=eventtype_hash, type_active=True)
            show_dialog = False
            if request.method == 'POST':
                form = EventTypeForm(current_org,
                                     request.POST,
                                     instance=event_type)
                if form.is_valid():
                    form.save()
                    message = Message(title=_("Event Type Save Successful"),
                                      text=_("Event Type Edit Successful"))
                    message.addlink(_("Continue"),
                                    current_org.get_absolute_url())
                    message.addlink(
                        _("Edit"),
                        reverse('event_eventtype_edit',
                                kwargs={
                                    'org_short_name':
                                    current_org.org_short_name,
                                    'eventtype_hash': event_type.type_hash
                                }))
                    if request.POST.get("dialog", '') == "False":
                        template_name = "core/message.html"
                        show_dialog = False
                    else:
                        show_dialog = True
                    context = {
                        'message': message,
                        'form': form,
                        'message': message,
                        'current_org': current_org,
                        'show_dialog': show_dialog,
                    }
                else:
                    context = {
                        'current_org': current_org,
                        'event_type': event_type,
                        'form': form
                    }
            else:
                form = EventTypeForm(current_org,
                                     auto_id=False,
                                     instance=event_type)
                context = {
                    'current_org': current_org,
                    'event_type': event_type,
                    'form': form
                }
        except ObjectDoesNotExist:
            template_name = "error.html"
            context = {'error': _("Event Type does not exist")}
    else:
        template_name = "core/message.html"
        context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #44
0
def evesch_signup(request, template_name=None):
    if request.user.is_authenticated():
        template_name = "core/message.html"
        message = Message(
            title=_("Cannot Signup"),
            text=_(
                "You cannot signup for a new user account while logged in."))
        message.addlink(_("Back"), reverse('home'))
        context = {
            'message': message,
        }
    else:
        if request.POST:
            session_captcha = request.session.get('signup_captcha', '-1')
            #raise AssertionError(session_captcha)
            form = SignupForm(session_captcha, request.POST)
            if form.is_valid():
                post_email = form.cleaned_data['email']
                post_username = form.cleaned_data['username']
                post_password = form.cleaned_data['password']
                user = get_user_model()(username=post_username,
                                        email=post_email)
                user.first_name = post_username
                user.last_name = ''
                user.is_superuser = False
                user.is_staff = False
                user.is_active = False
                user.set_password(post_password)
                user.security_hash = "".join(random.sample(KEYS, 24))
                user.save()

                host = request.META['HTTP_HOST']
                subject = "Evesch Registration Confirmation"
                email_body = render_to_string(
                    "core/email_registration_confirmation.html", {
                        'username':
                        user.username,
                        'link':
                        "http://" + host + reverse('account_signup_confirm') +
                        "?registration_confirmation=" + user.security_hash,
                        'registration_confirmation':
                        user.security_hash,
                    })
                email_from = ""
                email_recipients = [
                    post_email,
                ]
                # Create a new thread in Daemon mode to send message
                t = threading.Thread(
                    target=send_mail,
                    args=[subject, email_body, email_from, email_recipients],
                    kwargs={'fail_silently': True})
                t.setDaemon(True)
                t.start()
                return HttpResponseRedirect(reverse('account_signup_confirm'))
        else:
            form = SignupForm(None)
        context = {
            'form': form,
        }
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #45
0
def eventtype_add(request, org_short_name, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        if not current_org.is_member(request.user):
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Add Event Type"),
                text=
                _("You cannot add an event type in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_add_type']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Add Event Type"),
                text=
                _("You do not have permission to add an event type in this organization."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        show_dialog = False
        if request.method == 'POST':
            form = EventTypeForm(current_org, request.POST)
            if form.is_valid():
                event_type = form.save(commit=False)
                event_type.org_name = current_org
                event_type.save()
                message = Message(title=_("Add Event Type Successful"),
                                  text=_("Add Event Type Successful"))
                message.addlink(_("Continue"), current_org.get_absolute_url())
                message.addlink(
                    _("Edit"),
                    reverse('event_eventtype_edit',
                            kwargs={
                                'org_short_name': current_org.org_short_name,
                                'eventtype_hash': event_type.type_hash,
                            }))
                if request.POST.get("dialog", '') == "False":
                    template_name = "core/message.html"
                    show_dialog = False
                else:
                    show_dialog = True
                context = {
                    'message': message,
                    'form': form,
                    'message': message,
                    'current_org': current_org,
                    'show_dialog': show_dialog,
                }

            else:
                context = {'form': form, 'current_org': current_org}
        else:
            form = EventTypeForm(current_org)
            context = {
                'form': form,
                'org_short_name': org_short_name,
                'current_org': current_org
            }
            #raise AssertionError
    else:
        context = {
            'message': message,
        }
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #46
0
def event_add(request, org_short_name, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['is_memberof_org']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Add Event"),
                text=
                _("You cannot add an event in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        if not operms['can_add_event']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Add Event"),
                text=
                _("You do not have permission to add an event in this organization."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        current_user, message = get_current_user(request.user, message)
    if not message:
        show_dialog = False
        if request.method == 'POST':
            form = EventForm(current_org, request.POST)
            if form.is_valid():
                current_event = form.save(commit=False)
                current_event.event_creator_name = current_user
                current_event.event_org = current_org
                current_event.save()
                message = Message(title=_("Event Add Successful"),
                                  text=_("Event Add Successful"))
                message.addlink(
                    _("Attend"),
                    reverse('event_attendee_add',
                            kwargs={
                                'org_short_name': current_org.org_short_name,
                                'event_hash': current_event.event_hash
                            }))
                message.addlink(
                    _("View"),
                    reverse('event_event_view',
                            kwargs={
                                'org_short_name': current_org.org_short_name,
                                'event_hash': current_event.event_hash
                            }))
                message.addlink(
                    _("Edit"),
                    reverse('event_event_edit',
                            kwargs={
                                'org_short_name': current_org.org_short_name,
                                'event_hash': current_event.event_hash
                            }))
                if request.POST.get("dialog", '') == "False":
                    template_name = "core/message.html"
                    show_dialog = False
                else:
                    show_dialog = True
                context = {
                    'message': message,
                    'form': form,
                    'current_org': current_org,
                    'current_event': current_event,
                    'show_dialog': show_dialog,
                }
            else:
                context = {
                    'form': form,
                    'current_org': current_org,
                    'org_short_name': org_short_name,
                    'error': "update",
                    'show_dialog': show_dialog,
                }
        else:
            form = EventForm(current_org)
            context = {
                'form': form,
                'current_org': current_org,
                'org_short_name': org_short_name
            }
    else:
        template_name = "core/message.html"
        context = {'message': message}
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))
Exemple #47
0
def group_edit(request, org_short_name, group_hash, template_name=None):
    current_org, message = Organization.objects.get_current_org(org_short_name)
    if not message:
        current_user, message = get_current_user(request.user)
    if not message:
        current_usergroup, message = UserGroup.objects.get_current_usergroup(
            group_hash)
    if not message:
        if not current_org.is_member(request.user):
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Edit Group"),
                text=
                _("You cannot edit a group in an organization that you do not belong to."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
    if not message:
        operms = current_org.org_perms(current_user)
        if not operms['can_edit_group']:
            template_name = "core/message.html"
            message = Message(
                title=_("Cannot Edit Group"),
                text=
                _("You do not have permission to edit a group in this organization."
                  ))
            message.addlink(_("Back"), current_org.get_absolute_url())
            context = {
                'message': message,
            }
    if not message:
        groupuser_page = ePage(1)
        if request.GET.__contains__("members_page"):
            try:
                groupuser_page.curr = int(request.GET['members_page'])
            except:
                groupuser_page.curr = 1
        groupusers = current_usergroup.get_members()
        groupuser_page.set_pages(Paginator(groupusers, 48))

        group_add_member_form = GroupAddMemberForm()
        edit_form = UserGroupEditForm(instance=current_usergroup)
        show_dialog = False
        if request.method == 'POST':
            action = request.POST.get('action', '')
            p = re.compile('^[\w]{1,20}$')
            if not p.match(action):
                action = ""
            if action == 'group_edit':
                edit_form = UserGroupEditForm(request.POST,
                                              instance=current_usergroup)
                if edit_form.is_valid():
                    edit_form.save()
                    message = Message(title=_("Group Changes Saved"),
                                      text=_("Group Changes Saved"))
                    message.addlink(
                        _("View"),
                        reverse('egroup_group_view',
                                kwargs={
                                    'org_short_name':
                                    current_org.org_short_name,
                                    'group_hash': current_usergroup.group_hash
                                }))
                    message.addlink(
                        _("Edit"),
                        reverse('egroup_group_edit',
                                kwargs={
                                    'org_short_name':
                                    current_org.org_short_name,
                                    'group_hash': current_usergroup.group_hash
                                }))
                    #return HttpResponseRedirect(current_org.get_absolute_url())
                    if request.POST.get("dialog", '') == "False":
                        template_name = "core/message.html"
                        show_dialog = False
                    else:
                        show_dialog = True
            elif action == 'group_member_add':
                group_add_member_form = GroupAddMemberForm(request.POST)
                if group_add_member_form.is_valid():
                    user_list = group_add_member_form.cleaned_data[
                        'user_list'].strip().strip(',').split(',')
                    new_user_list = []
                    for user in user_list:
                        new_user_list.append(user.strip().strip(','))
                    new_group_users = get_user_model().objects.filter(
                        username__in=new_user_list)
                    for user in new_group_users:
                        user.user_groups.add(current_usergroup)
                        return HttpResponseRedirect(
                            reverse('egroup_group_edit',
                                    kwargs={
                                        'org_short_name':
                                        current_org.org_short_name,
                                        'group_hash':
                                        current_usergroup.group_hash
                                    }))
            else:
                pass
        else:
            pass
        context = {
            'current_org':
            current_org,
            'edit_form':
            edit_form,
            'group_add_member_form':
            group_add_member_form,
            'current_usergroup':
            current_usergroup,
            'groupusers':
            groupuser_page,
            'message':
            message,
            'show_dialog':
            show_dialog,
            'ajax_page_members':
            reverse('egroup_group_user_list_ajax',
                    kwargs={
                        'org_short_name': current_org.org_short_name,
                        'group_hash': current_usergroup.group_hash
                    })
        }
    else:
        template_name = "core/message.html"
        context = {
            'message': message,
            'current_org': current_org,
        }
    return render_to_response(template_name,
                              context,
                              context_instance=RequestContext(request))