def add_thread(request, suggested_label=None): if request.POST: form = get_add_form()(request.POST) if form.is_valid(): group_id = get_integer(request, "group_id") user_id = get_integer(request, "user_id") if group_id: owner_group = Group.objects.get(pk=group_id) check_access(request.user, obj=owner_group, command="add thread") thread = Thread.objects.create( owner_group=owner_group, owner_user=request.user, name=form.cleaned_data["name"], last_changed_by=request.user, last_changed_time=datetime.now(), ) Watcher.objects.create( user=request.user, object_id=thread.id, owner_user=request.user, owner_group=owner_group, content_type=ContentType.objects.get(name="thread"), ) else: owner_group = request.community check_access(request.user, obj=owner_group, command="add thread") thread = Thread.objects.create( owner_group=owner_group, owner_user=request.user, name=form.cleaned_data["name"], last_changed_by=request.user, last_changed_time=datetime.now(), ) Watcher.objects.create( user=request.user, object_id=thread.id, owner_user=request.user, owner_group=owner_group, content_type=ContentType.objects.get(name="thread"), ) if form.cleaned_data["first_message"] != "": import re replacer = re.compile(" ") body = form.cleaned_data["first_message"] body = replacer.sub(" ", body) Message.objects.create(body=body, parent_thread=thread, owner=request.user) # Handle the labels handle_labels(request, thread) return HttpResponseRedirect(thread.get_absolute_url()) labels = get_string(request, "labels", default="") form = get_add_form()(initial={"title": "", "contents": "", "labels": labels}) return render_to_response(request, "forums/add.html", {"form": form})
def edit_thread(request, thread_id): thread = get_object_or_404_and_check_access(request, Thread, pk=thread_id, command="edit") import django.forms class EditForm(django.forms.Form): name = django.forms.CharField( max_length=1024, label=_("Name"), help_text=_("The title will be visible in the thread list") ) labels = django.forms.CharField( required=False, label=_("Labels"), help_text=_("Help your friends find this item") ) if request.POST: form = EditForm(request.POST) # Handle the labels handle_labels(request, thread) if form.is_valid(): thread.name = form.cleaned_data["name"] thread.save() return HttpResponseRedirect(thread.get_absolute_url()) else: form = EditForm({"name": thread.name, "labels": ", ".join([unicode(label) for label in get_labels(thread)])}) return render_to_response(request, "forums/edit.html", {"form": form, "thread": thread})
def add_set(request, group_id=None): if group_id != None: group = get_object_or_404_and_check_access(request, Group, pk=group_id, command='add') else: group = get_current_community() check_access(request.user, group, command='view') class AddForm(django.forms.Form): title = django.forms.CharField(label=_('Album title'), help_text=_('The title will be visible in the set list')) labels = django.forms.CharField(required=False, label=_('Labels'), help_text=_('Help your friends find this item')) description = django.forms.CharField(required=False, widget = django.forms.Textarea, label=_('Description')) if request.POST: form = AddForm(request.POST) if form.is_valid(): image_set = ImageSet.objects.create(title = form.cleaned_data['title'], description = form.cleaned_data['description'], owner_user = request.user, owner_group = group) #Handle the labels handle_labels(request,image_set,group) return HttpResponseRedirect(image_set.get_absolute_url()) else: form = AddForm(initial={}) print form.fields return render_to_response(request, 'images/add_set.html', {'form':form})
def add_file(request): labels = '' class AddForm(django.forms.Form): title = django.forms.CharField(label=_('Title'), required=True, help_text=_('The title will be visible in the file list')) labels = django.forms.CharField(required=False, label=_('Labels'), help_text=_('Help your friends find this item')) description = django.forms.CharField(required=False, widget = django.forms.Textarea, label=_('Description')) file = django.forms.FileField(required=False, label=_('File')) if request.POST: new_data = request.POST.copy() new_data.update(request.FILES) form = AddForm(new_data) if form.is_valid(): if 'file' in new_data: f = File.objects.create(owner_user=request.user, owner_group=request.community, title=form.cleaned_data['title'], description=form.cleaned_data['description']) save_file_for_object(obj=f, fieldname='file', data=new_data) handle_labels(request,f) return HttpResponseRedirect('/files/') else: try: labels = request.REQUEST['labels'] except: labels = '' form = AddForm(initial={'labels':labels}) return render_to_response(request, 'files/add.html', {'form':form, 'labels':labels})
def edit_file(request, file_id): file = get_object_or_404_and_check_access(request, File, pk=file_id, command='edit') class EditForm(django.forms.Form): title = django.forms.CharField(label=_('Title'), required=True, help_text=_('The title will be visible in the file list')) labels = django.forms.CharField(required=False, label=_('Labels'), help_text=_('Help your friends find this item')) description = django.forms.CharField(widget = django.forms.Textarea, label=_('Description')) if request.POST: form = EditForm(request.POST) if form.is_valid(): file.title = form.cleaned_data['title'] file.description = form.cleaned_data['description'] file.save() #Handle the labels handle_labels(request,file) if file.owner_group: return HttpResponseRedirect('/files/groups/%s/' % (file.owner_group.id,)) else: return HttpResponseRedirect('/files/users/%s/' % (file.owner_user.id,)) else: form = EditForm({'description': file.description, 'title': file.title, 'labels': ', '.join([unicode(label) for label in get_labels(file)])}) return render_to_response(request, 'files/edit.html', {'form':form, 'file': file})
def edit_set(request, set_id, group_id=None): if group_id != None: group = get_object_or_404_and_check_access(request, Group, pk=group_id, command='view') else: group = get_current_community() image_set = ImageSet.objects.get(pk=set_id) check_access(request.user, image_set, command='view') class EditForm(django.forms.Form): title = django.forms.CharField(label=_('Album title'), help_text=_('The title will be visible in the set list')) labels = django.forms.CharField(required=False, label=_('Labels'), help_text=_('Help your friends find this item')) description = django.forms.CharField(required=False, widget = django.forms.Textarea, label=_('Description')) if request.POST: form = EditForm(request.POST) if form.is_valid(): image_set.title = form.cleaned_data['title'] image_set.description = form.cleaned_data['description'] image_set.save() #Handle the labels handle_labels(request,image_set,group) return HttpResponseRedirect(image_set.get_absolute_url()) else: form = EditForm({'title':image_set.title, 'description':image_set.description, 'labels': ', '.join([unicode(label) for label in get_labels(image_set)])}) return render_to_response(request, 'images/edit_set.html', {'owner':get_owner(image_set), 'set':image_set, 'form':form})
def edit_event(request, event_id): event = Event.objects.get(pk=event_id) check_access(request.user, event, command="change event") if not event.event_parent: if request.POST: form = get_event_form()(request.POST) # users, groups = validate_invites(form,event) if not form.errors: event.title = form.data["title"] event.description = form.data["description"] event.start_time = form.data["start_time_0"] + " " + form.data["start_time_1"] event.end_time = form.data["start_time_0"] + " " + form.data["start_time_1"] event.save() # Change all children event_children = event.event_children.all() for child in event_children: try: django.forms.models.save_instance(form, child) except: pass # handle_invites(request.user, event, users, groups) handle_labels(request, event) if event.owner_group != None: return HttpResponseRedirect("/calendars/groups/%s/agenda/" % (event.owner_group.id,)) else: return HttpResponseRedirect("/calendars/users/%s/agenda/" % (event.owner_user.id,)) else: form = get_event_form()( initial={ "start_time": event.start_time, "end_time": event.end_time, "title": event.title, "description": event.description, "all_day": event.all_day, "labels": ", ".join([unicode(label) for label in get_labels(event)]), } ) else: form = get_event_form()( initial={ "start_time": event.start_time, "end_time": event.end_time, "title": event.title, "description": event.description, "all_day": event.all_day, "labels": ", ".join([unicode(label) for label in get_labels(edit)]), } ) return render_to_response(request, "calendars/edit.html", {"event": event, "form": form})
def edit_set(request, set_id, group_id=None): if group_id != None: group = get_object_or_404_and_check_access(request, Group, pk=group_id, command='view') else: group = get_current_community() image_set = ImageSet.objects.get(pk=set_id) check_access(request.user, image_set, command='view') class EditForm(django.forms.Form): title = django.forms.CharField( label=_('Album title'), help_text=_('The title will be visible in the set list')) labels = django.forms.CharField( required=False, label=_('Labels'), help_text=_('Help your friends find this item')) description = django.forms.CharField(required=False, widget=django.forms.Textarea, label=_('Description')) if request.POST: form = EditForm(request.POST) if form.is_valid(): image_set.title = form.cleaned_data['title'] image_set.description = form.cleaned_data['description'] image_set.save() #Handle the labels handle_labels(request, image_set, group) return HttpResponseRedirect(image_set.get_absolute_url()) else: form = EditForm({ 'title': image_set.title, 'description': image_set.description, 'labels': ', '.join([unicode(label) for label in get_labels(image_set)]) }) return render_to_response(request, 'images/edit_set.html', { 'owner': get_owner(image_set), 'set': image_set, 'form': form })
def edit_file(request, file_id): file = get_object_or_404_and_check_access(request, File, pk=file_id, command='edit') class EditForm(django.forms.Form): title = django.forms.CharField( label=_('Title'), required=True, help_text=_('The title will be visible in the file list')) labels = django.forms.CharField( required=False, label=_('Labels'), help_text=_('Help your friends find this item')) description = django.forms.CharField(widget=django.forms.Textarea, label=_('Description')) if request.POST: form = EditForm(request.POST) if form.is_valid(): file.title = form.cleaned_data['title'] file.description = form.cleaned_data['description'] file.save() #Handle the labels handle_labels(request, file) if file.owner_group: return HttpResponseRedirect('/files/groups/%s/' % (file.owner_group.id, )) else: return HttpResponseRedirect('/files/users/%s/' % (file.owner_user.id, )) else: form = EditForm({ 'description': file.description, 'title': file.title, 'labels': ', '.join([unicode(label) for label in get_labels(file)]) }) return render_to_response(request, 'files/edit.html', { 'form': form, 'file': file })
def add_file(request): labels = '' class AddForm(django.forms.Form): title = django.forms.CharField( label=_('Title'), required=True, help_text=_('The title will be visible in the file list')) labels = django.forms.CharField( required=False, label=_('Labels'), help_text=_('Help your friends find this item')) description = django.forms.CharField(required=False, widget=django.forms.Textarea, label=_('Description')) file = django.forms.FileField(required=False, label=_('File')) if request.POST: new_data = request.POST.copy() new_data.update(request.FILES) form = AddForm(new_data) if form.is_valid(): if 'file' in new_data: f = File.objects.create( owner_user=request.user, owner_group=request.community, title=form.cleaned_data['title'], description=form.cleaned_data['description']) save_file_for_object(obj=f, fieldname='file', data=new_data) handle_labels(request, f) return HttpResponseRedirect('/files/') else: try: labels = request.REQUEST['labels'] except: labels = '' form = AddForm(initial={'labels': labels}) return render_to_response(request, 'files/add.html', { 'form': form, 'labels': labels })
def add_event_to_group(request, group_id=None): if group_id != None: group = get_object_or_404_and_check_access(request, Group, pk=group_id, command="add") else: group = request.community check_access(request.user, obj=group, command="add event") if request.POST: form = get_event_form()(request.POST) # users, groups = validate_invites(form) # if form.data['start_time'] > form.data['end_time']: # form.errors['end_time'] = (_('The end of the event has to be after the beginning.'),) if form.is_valid(): event = Event.objects.create( title=form.cleaned_data["title"], description=form.cleaned_data["description"], start_time=form.cleaned_data["start_time"], end_time=form.cleaned_data["start_time"], # form.cleaned_data['end_time'], owner_group=group, owner_user=request.user, all_day=False, ) # all_day=form.cleaned_data['all_day']) handle_invites(request.user, event, group.user_set.all()) handle_labels(request, event) if event.owner_group != None: return HttpResponseRedirect("/calendars/groups/%s/agenda/" % (event.owner_group.id,)) else: return HttpResponseRedirect("/calendars/users/%s/agenda/" % (event.owner_user.id,)) else: form = get_event_form()(initial={}) if "date" in request.GET: form.fields["start_time"].initial = request.GET["date"] + " 12:00" # form.fields['end_time'].initial = form.fields['start_time'].initial else: print form.fields form.fields["start_time"].initial = datetime.now() # form.fields['end_time'].initial = datetime.now() return render_to_response(request, "calendars/add.html", {"form": form})
def add_event_to_group(request, group_id=None): if group_id != None: group = get_object_or_404_and_check_access(request, Group, pk=group_id, command='add') else: group = request.community check_access(request.user, obj=group, command='add event') if request.POST: form = get_event_form()(request.POST) #users, groups = validate_invites(form) #if form.data['start_time'] > form.data['end_time']: # form.errors['end_time'] = (_('The end of the event has to be after the beginning.'),) if form.is_valid(): event = Event.objects.create( title=form.cleaned_data['title'], description=form.cleaned_data['description'], start_time=form.cleaned_data['start_time'], end_time=form.cleaned_data['start_time'],#form.cleaned_data['end_time'], owner_group=group, owner_user=request.user, all_day=False)#all_day=form.cleaned_data['all_day']) handle_invites(request.user, event, group.user_set.all()) handle_labels(request, event) if event.owner_group != None: return HttpResponseRedirect('/calendars/groups/%s/agenda/' % (event.owner_group.id,)) else: return HttpResponseRedirect('/calendars/users/%s/agenda/' % (event.owner_user.id,)) else: form = get_event_form()(initial={}) if 'date' in request.GET: form.fields['start_time'].initial = request.GET['date']+' 12:00' #form.fields['end_time'].initial = form.fields['start_time'].initial else: print form.fields form.fields['start_time'].initial = datetime.now() #form.fields['end_time'].initial = datetime.now() return render_to_response(request, 'calendars/add.html', {'form': form})
def add_set(request, group_id=None): if group_id != None: group = get_object_or_404_and_check_access(request, Group, pk=group_id, command='add') else: group = get_current_community() check_access(request.user, group, command='view') class AddForm(django.forms.Form): title = django.forms.CharField( label=_('Album title'), help_text=_('The title will be visible in the set list')) labels = django.forms.CharField( required=False, label=_('Labels'), help_text=_('Help your friends find this item')) description = django.forms.CharField(required=False, widget=django.forms.Textarea, label=_('Description')) if request.POST: form = AddForm(request.POST) if form.is_valid(): image_set = ImageSet.objects.create( title=form.cleaned_data['title'], description=form.cleaned_data['description'], owner_user=request.user, owner_group=group) #Handle the labels handle_labels(request, image_set, group) return HttpResponseRedirect(image_set.get_absolute_url()) else: form = AddForm(initial={}) print form.fields return render_to_response(request, 'images/add_set.html', {'form': form})
def edit_thread(request, thread_id): thread = get_object_or_404_and_check_access(request, Thread, pk=thread_id, command='edit') import django.forms class EditForm(django.forms.Form): name = django.forms.CharField( max_length=1024, label=_('Name'), help_text=_('The title will be visible in the thread list')) labels = django.forms.CharField( required=False, label=_('Labels'), help_text=_('Help your friends find this item')) if request.POST: form = EditForm(request.POST) #Handle the labels handle_labels(request, thread) if form.is_valid(): thread.name = form.cleaned_data['name'] thread.save() return HttpResponseRedirect(thread.get_absolute_url()) else: form = EditForm({ 'name': thread.name, 'labels': ', '.join([unicode(label) for label in get_labels(thread)]) }) return render_to_response(request, 'forums/edit.html', { 'form': form, 'thread': thread })
def edit_event(request, event_id): event = Event.objects.get(pk=event_id) check_access(request.user, event, command='change event') if not event.event_parent: if request.POST: form = get_event_form()(request.POST) #users, groups = validate_invites(form,event) if not form.errors: event.title=form.data['title'] event.description=form.data['description'] event.start_time=form.data['start_time_0']+' '+form.data['start_time_1'] event.end_time=form.data['start_time_0']+' '+form.data['start_time_1'] event.save() #Change all children event_children = event.event_children.all() for child in event_children: try: django.forms.models.save_instance(form, child) except: pass #handle_invites(request.user, event, users, groups) handle_labels(request, event) if event.owner_group != None: return HttpResponseRedirect('/calendars/groups/%s/agenda/' % (event.owner_group.id,)) else: return HttpResponseRedirect('/calendars/users/%s/agenda/' % (event.owner_user.id,)) else: form = get_event_form()(initial={'start_time':event.start_time, 'end_time':event.end_time, 'title':event.title, 'description':event.description, 'all_day':event.all_day, 'labels': ', '.join([unicode(label) for label in get_labels(event)])}) else: form = get_event_form()(initial={'start_time':event.start_time, 'end_time':event.end_time, 'title':event.title, 'description':event.description, 'all_day':event.all_day, 'labels': ', '.join([unicode(label) for label in get_labels(edit)])}) return render_to_response(request, 'calendars/edit.html', {'event': event, 'form': form})
def add_group(request): meta_community = request.community.meta class GroupForm(django.forms.Form): name = django.forms.CharField(label=_('Name')) #labels = django.forms.CharField(required=False, label=_('Labels')) #logo = django.forms.ImageField(widget = django.forms.FileInput, required=False, label=_('Logo')) check_access(request.user, command='add group') error = 0 if request.POST: new_data = request.POST.copy() new_data.update(request.FILES) form = GroupForm(new_data) if form.is_valid(): error = None if error == None: try: new_group = Group.objects.create(name=form.cleaned_data['name']) meta_group = MetaGroup.objects.create(group=new_group, created_by=request.user) meta_community.children.add(meta_group) meta_community.save() content_type = get_content_type(new_group) except: error = _("There is already a group with this name. Please choose another one.") if error == None: try: presentation = Document.objects.get(owner_group=new_group, owner_user__isnull=True, is_presentation=True) except Document.DoesNotExist: presentation = Document.objects.create(owner_group=new_group, is_presentation=True) name = new_group.name if name.endswith('s'): title=new_group.name+' presentation' else: title = new_group.name+'s presentation' new_version = Version(document=presentation,title=title, contents=_('Write a presentation why don\'t ya?'), owner=request.user) new_version.save() watcher = Watcher(user=request.user, owner_group=new_group, inverse=False) watcher.save() django.forms.models.save_instance(form, meta_group) new_group.user_set.add(request.user) UserPermission.objects.create(user=request.user, command='add', content_type=get_content_type(new_group), object_id=new_group.id) UserPermission.objects.create(user=request.user, command='delete', content_type=get_content_type(new_group), object_id=new_group.id) UserPermission.objects.create(user=request.user, command='view', content_type=get_content_type(new_group), object_id=new_group.id) UserPermission.objects.create(user=request.user, command='edit', content_type=get_content_type(new_group), object_id=new_group.id) #Handle the labels handle_labels(request,new_group) return HttpResponseRedirect('/administration/') return render_to_response(request, 'authentication/add_group.html', {'form':form, 'error':error}) else: form = GroupForm() return render_to_response(request, 'authentication/add_group.html', {'form':form})
def add_group(request): meta_community = request.community.meta class GroupForm(django.forms.Form): name = django.forms.CharField(label=_('Name')) #labels = django.forms.CharField(required=False, label=_('Labels')) #logo = django.forms.ImageField(widget = django.forms.FileInput, required=False, label=_('Logo')) check_access(request.user, command='add group') error = 0 if request.POST: new_data = request.POST.copy() new_data.update(request.FILES) form = GroupForm(new_data) if form.is_valid(): error = None if error == None: try: new_group = Group.objects.create( name=form.cleaned_data['name']) meta_group = MetaGroup.objects.create( group=new_group, created_by=request.user) meta_community.children.add(meta_group) meta_community.save() content_type = get_content_type(new_group) except: error = _( "There is already a group with this name. Please choose another one." ) if error == None: try: presentation = Document.objects.get( owner_group=new_group, owner_user__isnull=True, is_presentation=True) except Document.DoesNotExist: presentation = Document.objects.create( owner_group=new_group, is_presentation=True) name = new_group.name if name.endswith('s'): title = new_group.name + ' presentation' else: title = new_group.name + 's presentation' new_version = Version( document=presentation, title=title, contents=_('Write a presentation why don\'t ya?'), owner=request.user) new_version.save() watcher = Watcher(user=request.user, owner_group=new_group, inverse=False) watcher.save() django.forms.models.save_instance(form, meta_group) new_group.user_set.add(request.user) UserPermission.objects.create( user=request.user, command='add', content_type=get_content_type(new_group), object_id=new_group.id) UserPermission.objects.create( user=request.user, command='delete', content_type=get_content_type(new_group), object_id=new_group.id) UserPermission.objects.create( user=request.user, command='view', content_type=get_content_type(new_group), object_id=new_group.id) UserPermission.objects.create( user=request.user, command='edit', content_type=get_content_type(new_group), object_id=new_group.id) #Handle the labels handle_labels(request, new_group) return HttpResponseRedirect('/administration/') return render_to_response(request, 'authentication/add_group.html', { 'form': form, 'error': error }) else: form = GroupForm() return render_to_response(request, 'authentication/add_group.html', {'form': form})
def add_thread(request, suggested_label=None): if request.POST: form = get_add_form()(request.POST) if form.is_valid(): group_id = get_integer(request, 'group_id') user_id = get_integer(request, 'user_id') if group_id: owner_group = Group.objects.get(pk=group_id) check_access(request.user, obj=owner_group, command='add thread') thread = Thread.objects.create( owner_group=owner_group, owner_user=request.user, name=form.cleaned_data['name'], last_changed_by=request.user, last_changed_time=datetime.now()) Watcher.objects.create( user=request.user, object_id=thread.id, owner_user=request.user, owner_group=owner_group, content_type=ContentType.objects.get(name="thread")) else: owner_group = request.community check_access(request.user, obj=owner_group, command='add thread') thread = Thread.objects.create( owner_group=owner_group, owner_user=request.user, name=form.cleaned_data['name'], last_changed_by=request.user, last_changed_time=datetime.now()) Watcher.objects.create( user=request.user, object_id=thread.id, owner_user=request.user, owner_group=owner_group, content_type=ContentType.objects.get(name="thread")) if form.cleaned_data['first_message'] != '': import re replacer = re.compile(' ') body = form.cleaned_data['first_message'] body = replacer.sub(' ', body) Message.objects.create(body=body, parent_thread=thread, owner=request.user) #Handle the labels handle_labels(request, thread) return HttpResponseRedirect(thread.get_absolute_url()) labels = get_string(request, 'labels', default='') form = get_add_form()(initial={ 'title': '', 'contents': '', 'labels': labels }) return render_to_response(request, 'forums/add.html', {'form': form})