Exemple #1
0
 def process_POST(self):
     guest = self.request.user
     
     text = self.request.POST.get('text', None)
     
     if guest.is_authenticated():
         app = Application.objects.get(short_name = self.appname)
         
         try:
             DataChecker.check_comment(text)
             
             comment = Comment()
             comment.user = guest
             comment.app = app
             comment.text = text
             comment.save()
             
             messages.success(self.request, UserMsgs.COMMENT_ADDED)
             
             if MeritsChecker.check_comments(guest):
                 messages.info(self.request, UserMsgs.MERIT_ACHIEVED)
             
             return HttpResponseRedirect('/app/%s/comments/' % \
                     app.short_name)
         except DataError, error:
             messages.error(self.request, error.msg)
             
             comments = app.comment_set.all().order_by('-time')
             
             return render_to_response('app_comments_list.html', \
                     {'guest': guest, 'app': app, \
                     'comments': comments, 'text': text,}, \
                     context_instance=RequestContext(self.request))
Exemple #2
0
 def process_PUT(self):
     guest = self.request.user
     
     if guest.is_authenticated():
         app = Application.objects.get(short_name = self.appname)
         today = date.today()
         checkapps_no = guest.checkapp_set.filter(user = guest, \
                 time__year = today.year, time__month = today.month, \
                 time__day = today.day).count()
         
         if checkapps_no <= CheckApp_.CHECKAPPS_NUMBER:
             text = self.request.POST.get('comment', '')
             
             try:
                 DataChecker.check_ca_comment(text)
                 
                 checkapp = CheckApp()
                 checkapp.user = guest
                 checkapp.app = app
                 checkapp.text = text
                 checkapp.save()
                 
                 messages.success(self.request, UserMsgs.CHECKAPP_DONE)
                 
                 if MeritsChecker.check_checkapps(guest):
                     messages.info(self.request, UserMsgs.MERIT_ACHIEVED)
                 
                 return HttpResponseRedirect('/app/%s/' % app.short_name)
             except DataError, error:
                 messages.error(self.request, error.msg)
                 
                 try:
                     last_checkapp = guest.checkapp_set.all().order_by('-time')[0]
                 except:
                     last_checkapp = None
                 
                 return render_to_response('checkapp_confirm.html', \
                         {'guest': guest, 'app': app, \
                         'ca_no': checkapps_no, \
                         'last_ca': last_checkapp, 'text': text,}, \
                         context_instance=RequestContext(self.request))
         else:
             messages.warning(self.request, UserMsgs.CHECKAPPS_EXCEEDED)
             return HttpResponseRedirect('/app/%s/' % app.short_name)
Exemple #3
0
 def process_PUT(self):
     guest = self.request.user
     
     if guest.is_authenticated():
         if guest.username == self.username:
             form = {}
             form['fname'] = self.request.POST.get('first_name', None)
             form['lname'] = self.request.POST.get('last_name', None)
             form['email'] = self.request.POST.get('email', None)
             picture = self.request.FILES.get('pic', None)
             password = self.request.POST.get('password', None)
             cpassword = self.request.POST.get('cpassword', None)
             
             try:
                 DataChecker.check_first_name(form['fname'])
                 DataChecker.check_last_name(form['lname'])
                 DataChecker.check_email(form['email'])
                 
                 guest.first_name = form['fname']
                 guest.last_name = form['lname']
                 guest.email = form['email']
                 
                 if picture is not None:
                     print "picture is not None"
                     guest.pic = picture
                 
                 if DataChecker.defined(password):
                     print "password: %s" % password
                     DataChecker.check_password(password, \
                             cpassword)
                     guest.set_password(password)
                 
                 guest.save()
                 
                 messages.success(self.request, UserMsgs.USER_EDITED)
                 return HttpResponseRedirect('/profile/%s/' % self.username)
             except DataError, error:
                 messages.error(self.request, error.msg)
                 
                 return render_to_response('profile_edit_form.html', \
                         {'guest': guest, 'form': form,}, \
                         context_instance=RequestContext(self.request))
         else:
             return HttpResponseRedirect('/profile/%s/' % self.username)
Exemple #4
0
 def process_PUT(self):
     guest = self.request.user
     
     if guest.is_authenticated():
         app = Application.objects.get(short_name = self.appname)
         comment = Comment.objects.get(app = app, order = self.commentno)
         
         try:
             text = self.request.POST.get('text', '')
             
             DataChecker.check_comment(text)
             
             comment.text = text
             comment.save()
             
             return HttpResponseRedirect('/app/%s/comment/%s/' % \
                     (app.short_name, comment.order))
         except DataError, error:
             messages.error(self.request, error.msg)
             
             return render_to_response('comment.html', \
                     {'guest': guest, 'app': app, \
                     'comment': comment, 'edit': True, 'text': text,}, \
                     context_instance=RequestContext(self.request))
 def process_POST(self):
     form = {}
     form['uname'] = self.request.POST.get('username', None)
     form['fname'] = self.request.POST.get('first_name', None)
     form['lname'] = self.request.POST.get('last_name', None)
     form['email'] = self.request.POST.get('email', None)
     picture = self.request.FILES.get('pic', None)
     password = self.request.POST.get('password', None)
     cpassword = self.request.POST.get('cpassword', None)
     
     try:
         DataChecker.check_username(form['uname'])
         DataChecker.user_exists(form['uname'])
         DataChecker.check_first_name(form['fname'])
         DataChecker.check_last_name(form['lname'])
         DataChecker.check_email(form['email'])
         DataChecker.check_password(password, cpassword)
         
         user = Profile()
         user.username = form['uname']
         user.first_name = form['fname']
         user.last_name = form['lname']
         user.email = form['email']
         user.set_password(password)
         
         if picture:
             user.pic = picture
         
         user.save()
         
         # User is logged in without typing again its data
         user = authenticate(username=form['uname'], password=password)
         login(self.request, user)
         
         messages.success(self.request, UserMsgs.USER_CREATED)
         return HttpResponseRedirect('/profile/%s/' % user.username)
     except DataError, error:
         messages.error(self.request, error.msg)
         
         return render_to_response('profile_creation_form.html', \
                 {'form': form,}, \
                 context_instance=RequestContext(self.request))
Exemple #6
0
 def process_POST(self):
     guest = self.request.user
     
     form = {}
     form['sname'] = self.request.POST.get('app_sname', None)
     form['name'] = self.request.POST.get('app_name', None)
     logo = self.request.FILES.get('logo', None)
     form['cat'] = self.request.POST.get('category', None)
     form['plats'] = self.request.POST.getlist('platform')
     form['devel'] = self.request.POST.get('devel', None)
     form['version'] = self.request.POST.get('version', None)
     form['license'] = self.request.POST.get('license', None)
     form['url'] = self.request.POST.get('url', None)
     form['wiki'] = self.request.POST.get('wiki', None)
     form['blog'] = self.request.POST.get('blog', None)
     form['desc'] = self.request.POST.get('description', None)
     
     try:
         DataChecker.check_short_name(form['sname'])
         DataChecker.check_name(form['name'])
         DataChecker.check_category(form['cat'])
         
         if not form['plats']:
             raise DataError("You have to pick a platform")
         for i in form['plats']:
             DataChecker.check_platform(i)
         
         if not DataChecker.defined(form['url']):
             raise DataError("Website cannot be empty")
         
         DataChecker.check_url(form['url'])
         DataChecker.check_url(form['wiki'])
         DataChecker.check_url(form['blog'])
         DataChecker.check_description(form['desc'])
         
         app = Application()
         app.short_name = form['sname']
         app.name = form['name']
         app.description = form['desc']
         app.developer = form['devel']
         app.version = form['version']
         app.license = form['license']
         app.url = form['url']
         app.wiki = form['wiki']
         app.blog = form['blog']
         app.owner = guest
         
         category = Category.objects.get(name=form['cat'])
         app.category = category
         
         app.save()
         
         for i in form['plats']:
             platform = Platform.objects.get(name=i)
             app.platform.add(platform)
         
         if logo is not None:
             print "logo is not None"
             app.logo = logo
         
         app.save()
         
         messages.success(self.request, UserMsgs.APP_ADDED)
         return HttpResponseRedirect('/app/%s/' % app.short_name)
     except DataError, error:
         messages.error(self.request, error.msg)
         
         categories = Category.objects.all().order_by('name')
         platforms = Platform.objects.all().order_by('name')
         
         return render_to_response('application_form.html', \
                 {'guest': guest, 'form': form, \
                 'cats': categories, 'plats': platforms,}, \
                 context_instance=RequestContext(self.request))