def resend_key(request): """Display a form allowing user to request a new key. It checks to see if the user is already activated. It also checks to see if the user had been activated before, in which case he/she is not allowed to re-activate (perhaps he's been "banned".""" if request.method == 'POST': form = ResendKeyForm(request.POST) if form.is_valid(): email = form.cleaned_data["email"] try: user = User.objects.get(email=email) except User.DoesNotExist: return handle_privilege( request, "There is no user associated with that email address!", reverse('registration_register')) if user.is_active: return handle_privilege( request, message= "The user associated with that email address has already been activated!", redirect_url=reverse('auth_login')) try: registration_profile = RegistrationProfile.objects.get( user=user) except RegistrationProfile.DoesNotExist: return handle_privilege(request, "That user cannot be activated.", '/') if "AlreadyActivated" in registration_profile.activation_key: return handle_privilege(request, "That user cannot be activated.", '/') # Everything's OK. Send the email. from django.core.mail import send_mail from django.contrib.sites.models import Site current_site = Site.objects.get_current() subject = render_to_string( 'registration/activation_email_subject.txt', {'site': current_site}) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) message = render_to_string( 'registration/activation_email.txt', { 'activation_key': registration_profile.activation_key, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, 'site': current_site }) print message send_mail(subject, message, settings.REGISTRATION_FROM_EMAIL, [email]) return handle_privilege(request, "A new activation email has been sent!", reverse('auth_login')) else: form = ResendKeyForm() return render_to_response('registration/request_key.html', {'form': form}, context_instance=RequestContext(request))
def delete_action(request, project_name, action_id): """Allows you to delete the action item. It verifys that the project and action item match.""" project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id action_item = get_object_or_404(ActionItem, id=action_id) if not is_allowed(request, project_id, ActionItem._meta.verbose_name, 'Editable'): return handle_privilege( request, "You do not have privileges to edit action items!", action_item.get_absolute_url()) # If the requested action item is of a different project, return to (a) project page. if action_item.project.id != project.id: return handle_privilege( request, "The action item does not exist in that project!", project.get_absolute_url()) return delete_anything( request, action_item, reverse('action_overview', kwargs={'project_name': project.slug}), reverse('action_details', kwargs={ 'project_name': project.slug, 'action_id': action_id }))
def details(request, project_name, action_id): """Takes in the action item id and shows its details. If the user has permissions, it will allow him/her to delete as well.""" project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id action_item = get_object_or_404(ActionItem, id=action_id) if not is_allowed(request, project_id, ActionItem._meta.verbose_name, 'Viewable'): return handle_privilege( request, "You do not have privileges to view action items!", project.get_absolute_url()) # If the requested action item is of a different project, return to (a) project page. if action_item.project.id != project.id: return handle_privilege( request, "The action item does not exist in that project!", project.get_absolute_url()) if is_allowed(request, project_id, ActionItem._meta.verbose_name, 'Editable'): deletable = True else: deletable = False return render_to_response('action/actiondetails.html', { 'action': action_item, 'project': project, 'deletable': deletable }, context_instance=RequestContext(request))
def details(request, project_name, tele_id, *args, **kwargs): """Takes in the teleconference id and shows its details. If the user has permissions, it will allow him/her to delete the teleconference as well.""" project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id teleconference = get_object_or_404(TeleConference, id=tele_id) # If the requested teleconference is of a different project, return to (a) project page. if teleconference.project.id != project.id: return handle_privilege(request, "That teleconference does not exist!", project.get_absolute_url()) if not is_allowed(request, project_id, TeleConference._meta.verbose_name, 'Viewable'): return handle_privilege(request, "You do not have privileges to view teleconferences!", project.get_absolute_url()) if is_allowed(request, project_id, TeleConference._meta.verbose_name, 'Editable'): deletable = True else: deletable = False if is_allowed(request, project_id, Minutes._meta.verbose_name, 'Editable'): edit_minutes = True else: edit_minutes = False # Take the string of other participants, and create a list out of them (comma separated string) try: other_participants = [S.strip() for S in teleconference.minutes.other_participants.split(',')] # Silly hack below. If minutes.other_participants exists but is empty, then a list with an # empty string gets passed. Need to set that to None. other_participants = [S for S in other_participants if S != u''] except Minutes.DoesNotExist: other_participants = None return render_to_response('teleconference/teledetails.html', {'teleconference': teleconference, 'deletable': deletable, 'edit_minutes': edit_minutes, 'project': project, 'other_participants': other_participants}, context_instance=RequestContext(request))
def details_issueset(request, project_name, issueset_id): """ Takes in the issueset id and shows its details. If the user has permissions, it will allow him/her to delete as well. """ project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id issueset = get_object_or_404(IssueSet, id=issueset_id) # If the requested issueset item is of a different project, return to (a) project page. if issueset.project.id != project.id: return handle_privilege(request, "The issue list does not exist in that project!", project.get_absolute_url()) if not is_allowed(request, project_id, IssueSet._meta.verbose_name, 'Viewable'): return handle_privilege(request, "You do not have privileges to view issue lists!", project.get_absolute_url()) if is_allowed(request, project_id, IssueSet._meta.verbose_name, 'Editable'): deletable = True else: deletable = False if is_allowed(request, project_id, Issue._meta.verbose_name, 'Editable'): new_issue_perm = True else: new_issue_perm = False list_of_issues = issueset.issues.order_by('status', '-updated_date').all() list_of_issues = [{'number': issue.number, 'title': issue.title, 'last_modified': issue.updated_date, 'status': issue.status, 'url': issue.get_absolute_url()} for issue in list_of_issues] return render_to_response('issues/issuesetdetails.html', {'issueset': issueset, 'project': project, 'deletable': deletable, 'new_issue_perm': new_issue_perm, 'list_of_issues': list_of_issues}, context_instance=RequestContext(request))
def details_issueset_flat(request, project_name, issueset_id): """ Takes in the issueset id and shows all the issues - paginated and sorted by date. """ project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id issueset = get_object_or_404(IssueSet, id=issueset_id) # If the requested issueset item is of a different project, return to (a) project page. if issueset.project.id != project.id: return handle_privilege(request, "The issue list does not exist in that project!", project.get_absolute_url()) if not is_allowed(request, project_id, IssueSet._meta.verbose_name, 'Viewable'): return handle_privilege(request, "You do not have privileges to view issue lists!", project.get_absolute_url()) issue_dict = { 'paginate_by': 20, 'queryset': issueset.issues.order_by('-updated_date').all(), 'template_name': 'issues/issueset_latest.html', 'extra_context': {'project': project, 'issueset': issueset}, 'template_object_name': 'issues' } return list_detail.object_list(request, **issue_dict)
def add_edit_action(request, *args, **kwargs): """Takes in the project id and (if editing) the action_id and allows you to add/edit an action item.""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not is_allowed(request, project_id, ActionItem._meta.verbose_name, 'Editable'): return handle_privilege( request, "You do not have privileges to edit action items!", project.get_absolute_url()) if 'action_id' in kwargs: action_id = kwargs['action_id'] action_item = get_object_or_404(ActionItem, id=action_id) # Check if the action item exists in that project! if action_item.project.id != project.id: return handle_privilege( request, "The action item does not exist in that project!", project.get_absolute_url()) edit = True instance = action_item else: edit = False instance = None if request.method == 'POST': form = ActionItemForm(project.id, request.POST, instance=instance) if form.is_valid(): if not edit: action = ActionItem() message = "The action item was added." else: message = "The action item was modified." action = form.save(commit=False) action.project = project action.save() form.save_m2m() request.user.message_set.create(message=message) return HttpResponseRedirect( reverse('action_details', kwargs={ 'project_name': project.slug, 'action_id': action.id })) else: form = ActionItemForm(project.id, instance=instance) return render_to_response('action/add_edit_action.html', { 'form': form, 'edit': edit, 'project': project, 'action': instance }, context_instance=RequestContext(request))
def add_edit_minutes(request, **kwargs): """Takes in the project id and tele_id and allows you to edit/add the minutes for the relevant teleconference.""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id tele_id = kwargs['tele_id'] teleconference = get_object_or_404(TeleConference, id=tele_id) if not is_allowed(request, project_id, Minutes._meta.verbose_name, 'Editable'): return handle_privilege(request, "You do not have privileges to edit the minutes!", teleconference.get_absolute_url()) # Check if the teleconference exists in that project! if teleconference.project.id != project.id: return handle_privilege(request, "That teleconference does not exist!", project.get_absolute_url()) try: teleconference.minutes # The minutes already exist, so we are actually editing them now edit = True instance = teleconference.minutes initial = {'other_participants': teleconference.minutes.other_participants} except Minutes.DoesNotExist: edit = False instance = None initial = None if request.method == 'POST': form = MinutesForm(teleconference.id, request.POST, instance=instance, initial=initial) if form.is_valid(): if not edit: minutes = Minutes() message = "Minutes added!" else: message = "Minutes modified!" minutes = form.save(commit=False) minutes.teleconference = teleconference minutes.other_participants = form.cleaned_data['other_participants'] minutes.save() form.save_m2m() request.user.message_set.create(message=message) print teleconference.get_absolute_url() return HttpResponseRedirect(teleconference.get_absolute_url()) else: form = MinutesForm(teleconference.id, instance=instance, initial=initial) print form.fields['other_participants'].help_text return render_to_response('teleconference/add_edit_minutes.html', {'form': form, 'edit': edit, 'project': project}, context_instance=RequestContext(request))
def issuesets_overview(request, *args, **kwargs): """ Shows all issue lists, with relevant links. """ project_name=kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id=project.id if not is_allowed(request, project_id, IssueSet._meta.verbose_name, 'Viewable'): return handle_privilege(request, "You do not have privileges to view issues!", project.get_absolute_url()) if is_allowed(request, project_id, IssueSet._meta.verbose_name, 'Editable'): editable = True else: editable = False issuesets_list = { 'queryset': IssueSet.objects.filter(project__id=project_id).filter(active=True).order_by('name'), 'template_name': 'issues/overview.html', 'template_object_name': 'active_issuesets', 'extra_context': {'inactive_issuesets': IssueSet.objects.filter(project__id=project_id).filter(active=False).order_by('name'), 'project': project, 'editable': editable}, } return list_detail.object_list(request, **issuesets_list)
def members_download(request, *args, **kwargs): """Get a list of members of that project""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not request.user.is_superuser and (request.user not in project.admin.all()): return handle_privilege( request, "You do not have privileges to access the member list", '/') response = HttpResponse(mimetype='text') response[ 'Content-Disposition'] = 'attachment; filename=' + project.slug + '_memberlist.txt' members_qs = collab.profiles.models.UserProfile.objects.filter( user__projects__id__exact=project_id).order_by('user__last_name') member_list = [(member.user.email, member.user.first_name, member.user.last_name) for member in members_qs] t = loader.get_template('project/all_members.txt') c = Context({'members': member_list}) print t.render(c) response.write(t.render(c)) return response
def edit_doc(request, *args, **kwargs): """View to edit documentation.""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not is_allowed(request, project_id, 'documentation', 'Editable'): return handle_privilege( request, "You do not have privileges to edit the documentation section!", project.get_absolute_url()) view_dict = { 'form_class': DocumentationForm, 'object_id': project_id, 'post_save_redirect': reverse('documentation', kwargs={'project_name': project_name}), 'login_required': True, 'template_name': 'project/doc_edit.html', 'extra_context': { 'project': project }, } return create_update.update_object(request, **view_dict)
def edit_announcement(request, *args, **kwargs): """View for editing announcements""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not is_allowed(request, project_id, 'announcements', 'Editable'): return handle_privilege( request, "You do not have privileges to edit announcements!", project.get_absolute_url()) anonymous = Role.objects.get(project=project, name="AnonymousRole") if not anonymous.privileges.filter(permission_type='Viewable', related_model='announcements'.lower()): announce_warning = True else: announce_warning = False print announce_warning view_dict = { 'form_class': AnnouncementForm, 'object_id': project_id, 'post_save_redirect': project.get_absolute_url(), 'login_required': True, 'template_name': 'project/edit_announce.html', 'extra_context': { 'project': project, 'announce_warning': announce_warning }, } return create_update.update_object(request, **view_dict)
def add_edit_issue(request, *args, **kwargs): """Adds/Edits issues""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id issueset_id = kwargs['issueset_id'] issueset = get_object_or_404(IssueSet, id__exact=issueset_id) if not is_allowed(request, project_id, Issue._meta.verbose_name, 'Editable'): return handle_privilege(request, "You do not have privileges to edit issues!", issueset.get_absolute_url()) if 'issue_id' in kwargs: issue_id = kwargs['issue_id'] issue = get_object_or_404(Issue, id=issue_id) # Check if the issue exists in that project AND issue set! if issue.issueset.project.id != project.id or issue.issueset.id != issueset.id: return handle_privilege(request, "The issue does not match the project or issue list!", project.get_absolute_url()) edit = True instance=issue else: edit = False instance=None if request.method == 'POST': form = IssueForm(request.POST, instance=instance, issueset=issueset) if form.is_valid(): if not edit: issue = Issue() message = "The issue was added." else: message = "The issue was modified." issue = form.save(commit=False) if not edit: issue.reporter = request.user # issue.issueset = issueset issue.save() request.user.message_set.create(message=message) return HttpResponseRedirect(issue.get_absolute_url()) else: form = IssueForm(initial={'issueset': issueset.pk}, instance=instance, issueset=issueset) return render_to_response('issues/add_edit_issue.html', {'form': form, 'edit': edit, 'project': project, 'issueset': issueset, 'issue': instance}, context_instance=RequestContext(request))
def delete_tele(request, project_name, tele_id): """Takes in the teleconference id and allows user with privileges to delete the teleconference.""" project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id teleconference = get_object_or_404(TeleConference, id=tele_id) if not is_allowed(request, project_id, TeleConference._meta.verbose_name, 'Editable'): return handle_privilege(request, "You do not have privileges to edit teleconferences!", project.get_absolute_url()) # If the requested teleconference is of a different project, return to (a) project page. if teleconference.project.id != project.id: return handle_privilege(request, "That teleconference does not exist!", project.get_absolute_url()) return delete_anything(request, teleconference, reverse('tele_overview', kwargs={'project_name': teleconference.project.slug}), reverse('tele_details', kwargs={'project_name': teleconference.project.slug, 'tele_id': teleconference.id}))
def delete_issueset(request, project_name, issueset_id): """ Allows you to delete the action item. It verifys that the project and action item match. """ project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id issueset = get_object_or_404(IssueSet, id=issueset_id) if not is_allowed(request, project_id, IssueSet._meta.verbose_name, 'Editable'): return handle_privilege(request, "You do not have privileges to edit issue lists!", issueset.get_absolute_url()) # If the requested action item is of a different project, return to (a) project page. if issueset.project.id != project.id: return handle_privilege(request, "The issue list does not exist in that project!", project.get_absolute_url()) return delete_anything(request, issueset, reverse('issuesets_overview', kwargs={'project_name': project.slug}), reverse('issueset_details', kwargs={'project_name': project.slug, 'issueset_id': issueset.id}))
def add_edit_issueset(request, *args, **kwargs): """Adds/Edits issue sets""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not is_allowed(request, project_id, IssueSet._meta.verbose_name, 'Editable'): return handle_privilege(request, "You do not have privileges to edit issue lists!", project.get_absolute_url()) if 'issueset_id' in kwargs: issueset_id = kwargs['issueset_id'] issueset = get_object_or_404(IssueSet, id=issueset_id) # Check if the issue set exists in that project! if issueset.project.id != project.id: return handle_privilege(request, "The issue list does not exist in that project!", project.get_absolute_url()) edit = True instance=issueset else: edit = False instance=None if request.method == 'POST': form = IssueSetForm(request.POST, instance=instance) if form.is_valid(): if not edit: issueset = IssueSet() message = "The issue list was added." else: message = "The issue list was modified." issueset = form.save(commit=False) issueset.project = project issueset.save() request.user.message_set.create(message=message) return HttpResponseRedirect(reverse('issuesets_overview', kwargs={'project_name': project.slug})) else: form = IssueSetForm(instance=instance) return render_to_response('issues/add_edit_issueset.html', {'form': form, 'edit': edit, 'project': project, 'issueset': instance}, context_instance=RequestContext(request))
def create_project(request): """View to create a new project. In the past I just linked to the page in the admin, but that doesn't automatically create users and admins for you. And it may be a pain to create project memberships manually. Perhaps the Django admin is customizable enough to fix this, but for now I'll just code it myself. At least this way I can make sure no one (but me) makes any major errors and destroys the site First check if the user is a superuser...""" if not request.user.is_superuser: return handle_privilege( request, "Only the site administrator can create a new project!", '/') if request.method == 'POST': form = CreateProjectForm(request.POST) if form.is_valid(): newproject = CollabProject() newproject = form.save(commit=False) newproject.start_date = datetime.date.today() newproject.save() form.save_m2m() for admin in form.cleaned_data["admins"]: p = ProjectMembership(person=admin, project=newproject, is_admin=True) p.save() return handle_privilege( request, 'The collaboration group "' + newproject.name + '" has been created!', reverse('project_summary', args=[newproject.slug])) else: form = CreateProjectForm() return render_to_response('project/create_project.html', {'form': form}, context_instance=RequestContext(request))
def details_issue(request, project_name, issueset_id, issue_id): """ Takes in the issueset id and shows its details. If the user has permissions, it will allow him/her to delete as well. """ project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id issueset = get_object_or_404(IssueSet, id=issueset_id) issue = get_object_or_404(Issue, id=issue_id) # If the requested issueset is of a different project, return to (a) # project page. if issueset.project.id != project.id or issue.issueset.id != issueset.id: return handle_privilege(request, "The issue, issue list and project do not correspond!", project.get_absolute_url()) if not is_allowed(request, project_id, Issue._meta.verbose_name, 'Viewable'): return handle_privilege(request, "You do not have privileges to view issues!", project.get_absolute_url()) if is_allowed(request, project_id, Issue._meta.verbose_name, 'Editable'): deletable = True else: deletable = False # Any logged in person who can view an issue should be able to # upload to it. if request.user.is_active and request.user.is_authenticated(): logged_in = True else: logged_in = False # Create a flag to allow certain users to delete images. if request.user.is_superuser or request.user in project.admin.all(): delete_image = True else: delete_image = False return render_to_response('issues/issuedetails.html', {'issue': issue, 'project': project, 'deletable': deletable, 'delete_image': delete_image, 'logged_in': logged_in}, context_instance=RequestContext(request))
def upload_image(request, project_name, issueset_id, issue_id): """ View for uploading the image and attaching it to an issue. """ project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id issueset = get_object_or_404(IssueSet, id=issueset_id) issue = get_object_or_404(Issue, id=issue_id) if not is_allowed(request, project_id, Issue._meta.verbose_name, 'Editable'): return handle_privilege(request, "You do not have privileges to edit issues!", issueset.get_absolute_url()) # Check if the issue exists in that project AND issue set! if issue.issueset.project.id != project.id or issue.issueset.id != issueset.id: return handle_privilege(request, "The issue does not match the group or issue list!", project.get_absolute_url()) if request.method == 'POST': form = ImageForm(request.POST, request.FILES) if form.is_valid(): # In Django 1.02, I need the following hack. The reason is # that to decide where to upload the file to, it need to # know what issue it is attached to. When I execute # form.save(commit=False), it fails (although not in the # current SVN). form.cleaned_data["issue"] = issue image = form.save(commit=False) image.issue = issue image.save() message = "The image has been added to the issue." request.user.message_set.create(message=message) return HttpResponseRedirect(issue.get_absolute_url()) else: form = ImageForm() return render_to_response('issues/add_image.html', {'form': form, 'issue': issue, 'project': project}, context_instance=RequestContext(request))
def delete_issue(request, image_id): """ Delete an attachmemt. Currently, you have to be a group admin to do so. """ image = get_object_or_404(IssueImage, id=image_id) project = image.issue.issueset.project issue = image.issue if not (request.user in project.admin.all() or request.user.is_superuser): return handle_privilege(request, "You do not have privileges to delete images!", issue.get_absolute_url()) return delete_anything(request, image, reverse('issue_details', kwargs={'project_name': project.slug, 'issueset_id': issue.issueset.id, 'issue_id': issue.id}), reverse('issue_details', kwargs={'project_name': project.slug, 'issueset_id': issue.issueset.id, 'issue_id': issue.id}), project=project)
def action_overview(request, *args, **kwargs): """Shows a summary of action items, with relevant links""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not is_allowed(request, project_id, ActionItem._meta.verbose_name, 'Viewable'): return handle_privilege( request, "You do not have privileges to view action items!", project.get_absolute_url()) if is_allowed(request, project_id, ActionItem._meta.verbose_name, 'Editable'): editable = True else: editable = False action_items_list = { 'queryset': ActionItem.objects.filter(project__id=project_id).filter( status='Open').order_by('deadline'), 'template_name': 'action/overview.html', 'template_object_name': 'open_action_items', 'extra_context': { 'closed_action_items': ActionItem.objects.filter(project__id=project_id).filter( status='Closed').order_by('-deadline'), 'canceled_action_items': ActionItem.objects.filter(project__id=project_id).filter( status='Canceled').order_by('-deadline'), 'project': project, 'editable': editable }, } return list_detail.object_list(request, **action_items_list)
def subscribe(request, *args, **kwargs): """Asks user if he wants to subscribe to a group, and then sends off the request to the group admin. If the user is anonymous, let him know he has to subscribe!""" if request.user.is_anonymous(): return handle_privilege( request, message= "Please register. You need an account to join a collaboration group.", redirect_url=reverse('registration_register')) project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id # Check if user is already in the group. if project.users.filter(id=request.user.id): message = "You are already in this group!" request.user.message_set.create(message=message) return HttpResponseRedirect(project.get_absolute_url()) if request.method == 'POST': if "Yes" in request.POST: email_to_admin = render_to_string( 'project/subscribe_request.txt', { 'project': project, 'subscriber': request.user }, context_instance=RequestContext(request)) admin_emails = [admin.email for admin in project.admin.all()] send_mail( "User " + request.user.username + " wishes to join " + project.name + ".", email_to_admin, CONTACT_FROM_EMAIL, admin_emails) request.user.message_set.create( message="Your request to join " + project.name + " has been sent. You will be notified if your request is approved." ) return HttpResponseRedirect(project.get_absolute_url()) return render_to_response('project/subscribe.html', {'project': project}, context_instance=RequestContext(request))
def all_teleconferences(request, project_name): """Takes in the the project id and shows all teleconferences (upcoming and archived).""" project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not is_allowed(request, project_id, TeleConference._meta.verbose_name, 'Viewable'): return handle_privilege(request, "You do not have privileges to view teleconferences!", project.get_absolute_url()) if is_allowed(request, project_id, TeleConference._meta.verbose_name, 'Editable'): editable = True else: editable = False teleconferences_list = { 'queryset': TeleConference.objects.filter(project__id=project_id).filter(time__gte=datetime.date.today()).order_by('time'), 'template_name': 'teleconference/alltele.html', 'template_object_name': 'upcoming_tele', 'extra_context': {'past_tele': TeleConference.objects.filter(project__id=project_id).filter(time__lt=datetime.date.today()).order_by('-time'), 'project': project, 'editable': editable}, } return list_detail.object_list(request, **teleconferences_list)
def documentation(request, *args, **kwargs): """View to show any documentation related to a project.""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not is_allowed(request, project_id, 'documentation', 'Viewable'): return handle_privilege( request, "You do not have privileges to view the documentation section!", project.get_absolute_url()) if is_allowed(request, project_id, 'documentation', 'Editable'): edit = True else: edit = False return render_to_response('project/documentation.html', { 'project': project, 'editable': edit }, context_instance=RequestContext(request))
def add_edit_tele(request, **kwargs): """Takes in the project id and (if editing) the tele_id and allows you to add a new teleconference or edit an old one.""" project_name = kwargs['project_name'] project = get_object_or_404(CollabProject, slug=project_name) project_id = project.id if not is_allowed(request, project_id, TeleConference._meta.verbose_name, 'Editable'): return handle_privilege(request, "You do not have privileges to edit teleconferences!", project.get_absolute_url()) if 'tele_id' in kwargs: tele_id = kwargs['tele_id'] teleconference = get_object_or_404(TeleConference, id=tele_id) # Check if the teleconference exists in that project! if teleconference.project.id != int(project_id): return handle_privilege(request, "That teleconference does not exist in this project!", project.get_absolute_url()) edit = True instance = teleconference initial = {'date': teleconference.time, 'time': teleconference.time, 'duration': teleconference.duration} else: edit = False instance = None initial = {} action_text = None see_action = False last_tele = {} if request.method == 'POST': form = TeleConferenceForm(project.id, request.POST, instance=instance, initial=initial) if form.is_valid(): if not edit: tele = TeleConference() message = "Teleconference added!" else: message = "Teleconference modified!" tele = form.save(commit=False) tele.project = project tele.duration = form.cleaned_data['duration'] date = form.cleaned_data['date'] time = form.cleaned_data['time'][0] tz = form.cleaned_data['time'][1] tzs = construct_timezones(date.year) if tz=='Pacific': tz = tzs[0] elif tz=='Mountain': tz = tzs[1] elif tz=='Central': tz = tzs[2] elif tz=='Eastern': tz = tzs[3] elif tz=='UTC': tz = tzs[4] dt = datetime.datetime(year=date.year, month=date.month, day=date.day, hour=time.hour, minute=time.minute, tzinfo=tz) dt = dt.astimezone(tzs[2]) # Convert to Central dt = datetime.datetime.combine(dt.date(), dt.time()) # Convert to timezone-agnostic (MySQL can't handle them) tele.time = dt tele.save() request.user.message_set.create(message=message) return HttpResponseRedirect(reverse('tele_details', kwargs={'project_name': project.slug, 'tele_id': tele.id})) else: # Get action items to be placed in agenda, if desired. if is_allowed(request, project_id, ActionItem._meta.verbose_name, 'Viewable'): see_action = True action_items = ActionItem.objects.filter(project=project, status="Open").all() if action_items: action_text = "\\n* " + "\\n* ".join([action.action for action in action_items]) # Get the most recent (completed) teleconference. queryset = TeleConference.objects.filter(project=project, time__lte=datetime.datetime.now()).order_by('-time') if queryset.count(): prev_tele = queryset.all()[0] if prev_tele: last_tele['agenda'] = prev_tele.agenda.replace('\r\n', '\\n') last_tele['location'] = prev_tele.location last_tele['number'] = prev_tele.phone last_tele['password'] = prev_tele.phone_code last_tele['url'] = prev_tele.online_uri last_tele['userid'] = prev_tele.online_userid last_tele['opassword'] = prev_tele.online_password last_tele['instructions'] = prev_tele.online_instructions.replace('\r\n', '\\n') last_tele['other_instructions'] = prev_tele.other_instructions.replace('\r\n', '\\n') last_tele['notes'] = prev_tele.notes.replace('\r\n', '\\n') last_tele['time_h'] = prev_tele.time.hour last_tele['time_m'] = prev_tele.time.minute if prev_tele.duration: last_tele['duration_h'] = prev_tele.duration.hour last_tele['duration_m'] = prev_tele.duration.minute # Check if there have been two previous teleconferences. If # there have, calculate the difference in time between the # two, and use that as an estimate for the next # teleconference. Otherwise, jut add a week to the last one. if queryset.count() > 1: second_last_tele = queryset.all()[1] difference = prev_tele.time - second_last_tele.time next_tele_date = prev_tele.time + difference else: next_tele_date = prev_tele.time + datetime.timedelta(7) last_tele['year'] = next_tele_date.year last_tele['month'] = next_tele_date.strftime('%B') last_tele['day'] = next_tele_date.day # See bug 51 for why I pass in the project id. form = TeleConferenceForm(project.id, instance=instance, initial=initial) return render_to_response('teleconference/addtele.html', {'form': form, 'edit': edit, 'project': project, 'teleconference': instance, 'action_text': action_text, 'see_action': see_action, 'last_tele': last_tele}, context_instance=RequestContext(request))
def join_leave_projects(request, *args, **kwargs): """A function to allow one to join or leave multiple groups""" if request.user.is_anonymous(): return handle_privilege( request, message= "In order to join or leave a group you need to be registered and logged in.", redirect_url=reverse('auth_login')) task = kwargs['join_or_leave'] if 'join' in task: task = 'add' nochange = "You did not join any groups." template = 'project/join_groups.html' elif 'leave' in task: task = 'remove' nochange = "You did not leave any groups." template = 'project/leave_groups.html' if task == 'add': numprojects = CollabProject.objects.exclude( users__id=request.user.id).count() projects = CollabProject.objects.exclude(users__id=request.user.id) if numprojects == 0: return handle_privilege( request, message="You've joined all the groups there are!", redirect_url=reverse('projects')) elif task == 'remove': numprojects = CollabProject.objects.filter( users__id=request.user.id).count() projects = CollabProject.objects.filter(users__id=request.user.id) if numprojects == 0: return handle_privilege( request, message="You're not a member of any group!", redirect_url=reverse('projects')) if request.method == 'POST': form = BulkSubscriptionForm(projects, request.POST) if form.is_valid(): if form.cleaned_data['projects']: if task == 'add': for project in form.cleaned_data['projects']: email_to_admin = render_to_string( 'project/subscribe_request.txt', { 'project': project, 'subscriber': request.user }, context_instance=RequestContext(request)) admin_emails = [ admin.email for admin in project.admin.all() ] send_mail( "User " + request.user.username + " wishes to join " + project.name + ".", email_to_admin, CONTACT_FROM_EMAIL, admin_emails) request.user.message_set.create( message="Your request to join " + project.name + " has been sent. You will be notified if your request is approved." ) elif task == 'remove': for project in form.cleaned_data['projects']: for role in request.user.roles.filter( project=project).all(): role.users.remove(request.user) p = ProjectMembership.objects.get(person=request.user, project=project) p.delete() request.user.message_set.create( message="Your have been removed from " + project.name + ".") else: request.user.message_set.create(message=nochange) return HttpResponseRedirect(reverse('projects')) else: form = BulkSubscriptionForm(projects) return render_to_response(template, {'form': form}, context_instance=RequestContext(request))