예제 #1
0
def add(request, render):
    
    class CommunityForm(forms.Form):
        id = forms.RegexField(regex='^'+COMMUNITY_REGEX+'$', required=True, max_length=100, validators=[_validate_community])
        name = forms.CharField(required=True, max_length=20)
        description = forms.CharField(required=False, widget=forms.Textarea)
        tags = forms.CharField(required=False, max_length=100)
    
    if request.method == 'POST':
        form = CommunityForm(request.POST)
        if form.is_valid():
            c = form.cleaned_data['id']

            community = Community(key_name=c)
            community.name = form.cleaned_data['name']
            community.description = text_markup.render( form.cleaned_data['description'] )
            community.raw_description = form.cleaned_data['description']
            community.add_tags( form.cleaned_data['tags'] )
            community.created_by = request.user
            community.save()
            
            url = reverse(display, kwargs={'community':c})
            return HttpResponseRedirect(url)
    else:
        form = CommunityForm() # An unbound form

    context = {'form': form, 'user':request.user}
    return render(request, context)
예제 #2
0
파일: area.py 프로젝트: geyuntian/yuntien
def add(request, community, render):
    c = Community.objects.get(key_name=community)
    
    def _validate_area_id(value):
        if value:
            try:
                c.area_set.get(key_name=value)
                raise ValidationError(_(u'%s is already used.') % value)
            except Area.DoesNotExist:
                pass
    
    class AreaForm(forms.Form):
        area_id = forms.RegexField(regex='^'+AREA_ID_REGEX+'$', required=True, validators=[_validate_area_id])
        name = forms.CharField(required=True, max_length=10)
        description = forms.CharField(required=False, widget=forms.Textarea)
        sort = forms.IntegerField(required=True, initial=0)
    
    if request.method == 'POST':
        form = AreaForm(request.POST)
        if form.is_valid():
            area = Area(key_name=form.cleaned_data['area_id'], name=form.cleaned_data['name'])
            area.description = text_markup.render( form.cleaned_data['description'] )
            area.raw_description = form.cleaned_data['description']
            area.sort = form.cleaned_data['sort']
            area.community = c
            area.save()
            
            url = reverse('community-display', kwargs={'community':community})
            return HttpResponseRedirect(url)
    else:
        form = AreaForm() # An unbound form

    context = {'form': form, 'community_obj':c}
    return render(request, context)
예제 #3
0
파일: area.py 프로젝트: geyuntian/yuntien
def edit(request, community, area, render):
    c = Community.objects.get(key_name=community)
    a = c.area_set.get(key_name=area)
    
    class AreaForm(forms.Form):
        name = forms.CharField(required=True, max_length=10)
        description = forms.CharField(required=False, widget=forms.Textarea)
        sort = forms.IntegerField(required=True, initial=0)

    if request.method == 'POST':
        form = AreaForm(request.POST)
        if form.is_valid():
            a.name = form.cleaned_data['name']
            a.description = text_markup.render( form.cleaned_data['description'] )
            a.raw_description = form.cleaned_data['description']
            a.sort = form.cleaned_data['sort']        
            a.save()
                        
            url = reverse('community-display', kwargs={'community':community})
            return HttpResponseRedirect(url)
    else:
        data = {
            'name':a.name,
            'description':a.description,
            'sort': a.sort
        }
        form = AreaForm(initial=data)

    context = {'form': form, 'community_obj':c, 'area_obj':a}
    return render(request, context)  
예제 #4
0
파일: post.py 프로젝트: geyuntian/yuntien
def add(request, community, widget, render):
    
    community_obj = Community.objects.get(key_name=community)
    widget_config = community_obj.widget_set.get(key_name=widget)
    
    class PostForm(forms.Form):
        title = forms.CharField(max_length=100)
        tags = forms.CharField(required=False, max_length=100)
        content = forms.CharField(required=False, widget=forms.Textarea)
        
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post = Topic(author=request.user)
            post.title = form.cleaned_data['title']
            post.content = text_markup.render( form.cleaned_data['content'] )
            post.raw_content = form.cleaned_data['content']
            post.add_tags( form.cleaned_data['tags'] )
            post.community = community_obj
            post.community_widget = widget_config
            post.save()
            redirect = get_url(post)            
            return HttpResponseRedirect(redirect)
    else:
        form = PostForm() # An unbound form

    context = {'form': form, 'community_obj': community_obj, 'widget_config': widget_config}
    return render(request, context)    
예제 #5
0
파일: post.py 프로젝트: geyuntian/yuntien
def edit(request, community, widget, id, render):
    
    community_obj = Community.objects.get(key_name=community)
    widget_config = community_obj.widget_set.get(key_name=widget)
    post = Topic.objects.get(pk=id)

    class PostForm(forms.Form):
        title = forms.CharField(max_length=100)
        tags = forms.CharField(required=False, max_length=100)
        content = forms.CharField(required=False, widget=forms.Textarea)
    
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post.title = form.cleaned_data['title']
            post.content = text_markup.render( form.cleaned_data['content'] )
            post.raw_content = form.cleaned_data['content']
            post.add_tags( form.cleaned_data['tags'] )
            post.save()
            redirect = get_url(post)            
            return HttpResponseRedirect(redirect)
    else:
        data = {
            'title':post.title,
#            'tags':post.get_tag_str(),
            'content':post.raw_content,
        }
        form = PostForm(initial=data)

    context = {'form':form, 'post':post, 'community_obj': community_obj, 'widget_config': widget_config}
    return render(request, context)
예제 #6
0
파일: user.py 프로젝트: geyuntian/yuntien
def edit(request, user, widget, id, render):
    
    widget_config = request.user.user_widget_set.get(key_name=widget)
    post = Topic.objects.get(pk=id)
    
    class PostForm(forms.Form):
        title = forms.CharField(max_length=100)
        tags = forms.CharField(required=False, max_length=100)
        content = forms.CharField(required=False, widget=forms.Textarea)    
    
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post.title = form.cleaned_data['title']
            post.content = text_markup.render( form.cleaned_data['content'] )
            post.raw_content = form.cleaned_data['content']
            post.add_tags( form.cleaned_data['tags'] )
            post.save()
            params = {'id':str(post.id), 'user':user, 'widget':widget}
            redirect = reverse('note-user-topic', urlconf=APPS[APP_ID]['urls'], kwargs=params)
            return HttpResponseRedirect(redirect)
    else:
        data = {
            'title':post.title,
            'tags':post.get_tag_str(),
            'content':post.raw_content,
        }
        form = PostForm(initial=data)

    context = {'form':form, 'post':post, 'widget_config': widget_config}
    return render(request, context) 
예제 #7
0
파일: user.py 프로젝트: geyuntian/yuntien
def add(request, user, widget, render):
    
    class PostForm(forms.Form):
        title = forms.CharField(max_length=100)
        tags = forms.CharField(required=False, max_length=100)
        content = forms.CharField(required=False, widget=forms.Textarea)
    
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post = Topic()
            post.author = get_current_user()
            post.title = form.cleaned_data['title']
            post.content = text_markup.render( form.cleaned_data['content'] )
            post.raw_content = form.cleaned_data['content']
            post.add_tags( form.cleaned_data['tags'] )
            post.user = get_current_user()
            post.user_widget = post.author.user_widget_set.get(key_name=widget)
            post.save()
            kwargs={
                    'user':user,
                    'widget':widget,
                    'id':str(post.id)}
            redirect = reverse('note-user-topic', urlconf=APPS['note']['urls'], kwargs=kwargs)
            return HttpResponseRedirect(redirect)
    else:
        form = PostForm(initial={}) # An unbound form

    context = {'form': form, 'user':user, 'widget':widget}
    return render(request, context)
예제 #8
0
def edit(request, community, render):
    c = Community.objects.get(key_name=community)
    
    def _validate_users(value):
        users = value.splitlines()
        users = [u for u in users if u]
        if len(users) > 10:
            raise ValidationError(_(u'Too many users.'))
        for u in users:
            user = None
            try:
                user = get_user_model().objects.get(username=u)
            except:
                raise ValidationError(_(u'%s is not a valid user.') % u)
            role = c.get_role(user)
            if role not in (ROLE_OWNER, ROLE_USER):
                raise ValidationError(_(u"%s hasn't joined this community yet.") % u)
    
    class CommunityForm(forms.Form):
        name = forms.CharField(required=True, max_length=20)
        description = forms.CharField(required=False, widget=forms.Textarea)
        admins = forms.CharField(required=False, widget=forms.Textarea, validators=[_validate_users])
        tags = forms.CharField(required=False, max_length=100)
        style = forms.TypedChoiceField(required=True, choices=[(STYLE_SIMPLE, _(u"Simple")), (STYLE_TAB, _(u"Tab"))], coerce=int)

    if request.method == 'POST':
        form = CommunityForm(request.POST)
        if form.is_valid():
            c.name = form.cleaned_data['name']
            c.description = text_markup.render( form.cleaned_data['description'] )
            c.raw_description = form.cleaned_data['description']
            c.add_tags( form.cleaned_data['tags'] )      
            c.style = form.cleaned_data['style']   

            users = form.cleaned_data['admins'].splitlines()
            users = [u for u in users if u]
            c.set_admins(users)
            
            c.save()
                        
            url = reverse(display, kwargs={'community':community})
            return HttpResponseRedirect(url)
    else:
        admins = [ra.user.username for ra in c.ra_set.filter(role=ROLE_OWNER)]
        
        data = {
            'id':c.key_name,
            'name':c.name,
            'description':c.raw_description,
            'admins':'\n'.join(admins),
            'tags': c.get_tag_str(),
            'style': c.style,
        }
        form = CommunityForm(data)

    context = {'form':form, 'community':c}
    return render(request, context) 
예제 #9
0
def edit(request, id):
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = Comment.objects.get(id=id)
            comment.content = text_markup.render( strip_tags(form.cleaned_data['content']) )
            comment.raw_content = form.cleaned_data['content']
#            comment.save(add_version=True)
            comment.save()
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
    return HttpResponseNotFound()
예제 #10
0
def add(request, id):
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            post = Topic.objects.get(pk=id)
            comment = Comment(topic=post, author=request.user)
            comment.content = text_markup.render( form.cleaned_data['content'] )
            comment.raw_content = form.cleaned_data['content']
            comment.community = post.community
            comment.community_widget = post.community_widget
            comment.save()
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
    return HttpResponseNotFound()
예제 #11
0
파일: widget.py 프로젝트: geyuntian/yuntien
def add(request, community, render):
    c = Community.objects.get(key_name=community)

    def _validate_widget_id(value):
        if value in RESERVED_WIDGET_IDS:
            raise ValidationError(_(u"%s is a reserved widget id.") % value)
        if value:
            try:
                c.widget_set.get(key_name=value)
                raise ValidationError(_(u"%s is already used.") % value)
            except Widget.DoesNotExist:
                pass

    def _validate_app_id(value):
        app = APPS.get(value)
        if not app:
            raise ValidationError(_(u"%s is not a valid app.") % app)
        if not app["multiple_widgets"] and c.get_widgets(value):
            raise ValidationError(_(u"%s is already used.") % app["name"])

    class WidgetForm(forms.Form):
        widget_id = forms.RegexField(regex="^" + WIDGET_ID_REGEX + "$", required=True, validators=[_validate_widget_id])
        app_id = forms.ModelChoiceField(required=True, queryset=App.objects.all(), empty_label=None)
        area_id = forms.ChoiceField(required=True, choices=[(area.key_name, area.name) for area in c.area_set.all()])
        name = forms.CharField(required=True, max_length=20)
        description = forms.CharField(required=False, widget=forms.Textarea)
        sort = forms.IntegerField(required=True, initial=0)
        privacy_type = forms.TypedChoiceField(required=True, choices=PRIVACY_TYPE_CHOICES, coerce=int)

    if request.method == "POST":
        form = WidgetForm(request.POST)
        if form.is_valid():
            widget = Widget(
                key_name=form.cleaned_data["widget_id"], app=form.cleaned_data["app_id"], name=form.cleaned_data["name"]
            )
            widget.area = c.area_set.get(key_name=form.cleaned_data["area_id"])
            widget.community = c
            widget.description = text_markup.render(form.cleaned_data["description"])
            widget.raw_description = form.cleaned_data["description"]
            widget.sort = form.cleaned_data["sort"]
            widget.privacy_type = form.cleaned_data["privacy_type"]
            widget.save()

            url = reverse("community-display", kwargs={"community": community})
            return HttpResponseRedirect(url)
    else:
        form = WidgetForm()  # An unbound form

    context = {"form": form, "community_obj": c}
    return render(request, context)
예제 #12
0
파일: user.py 프로젝트: geyuntian/yuntien
def set_user_info(request, render):
    user_obj = request.user
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user_obj.description = text_markup.render( form.cleaned_data['description'] )
            user_obj.raw_description = form.cleaned_data['description']
            user_obj.save()
            url = reverse('user-display', kwargs={'user':user_obj.username})
            return HttpResponseRedirect(url)
    else:
        form = UserForm(initial={'description':user_obj.raw_description}) # An unbound form

    context = {'form': form, 'user_obj':user_obj}
    return render(request, context)    
예제 #13
0
def add(request, id, parent=''):
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            post = Topic.objects.get(id=id)
            p = post
            comment = Comment(topic=post)
            comment.community = post.community
            comment.community_widget = post.community_widget
            comment.author = request.user
            comment.content = text_markup.render( strip_tags(form.cleaned_data['content']) )
            comment.raw_content = form.cleaned_data['content']
            
            if parent:
                c = Comment.objects.get(id=parent)
                if c:
                    comment.parent = c
                    comment.level = c.level + 1
            
            comment.save()
#            deferred.defer(_calc_total_points, comment.key().id())
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
    return HttpResponseNotFound()
예제 #14
0
파일: widget.py 프로젝트: geyuntian/yuntien
def edit(request, community, widget, render):
    c = Community.objects.get(key_name=community)
    w = c.widget_set.get(key_name=widget)

    class WidgetForm(forms.Form):
        area_id = forms.ChoiceField(required=True, choices=[(area.key_name, area.name) for area in c.area_set.all()])
        name = forms.CharField(required=True, max_length=20)
        description = forms.CharField(required=False, widget=forms.Textarea)
        sort = forms.IntegerField(required=True, initial=0)
        privacy_type = forms.TypedChoiceField(required=True, choices=PRIVACY_TYPE_CHOICES, coerce=int)

    if request.method == "POST":
        form = WidgetForm(request.POST)
        if form.is_valid():
            w.area = c.area_set.get(key_name=form.cleaned_data["area_id"])
            w.name = form.cleaned_data["name"]
            w.description = text_markup.render(form.cleaned_data["description"])
            w.raw_description = form.cleaned_data["description"]
            w.sort = form.cleaned_data["sort"]
            w.privacy_type = form.cleaned_data["privacy_type"]
            w.save()

            url = reverse("community-display", kwargs={"community": community})
            return HttpResponseRedirect(url)
    else:
        data = {
            "area_id": w.area.key_name,
            "name": w.name,
            "description": w.raw_description,
            "sort": w.sort,
            "privacy_type": w.privacy_type,
        }
        form = WidgetForm(initial=data)

    context = {"form": form, "community_obj": c, "widget_obj": w}
    return render(request, context)