Example #1
0
    def create(self):
        """ check customers plan and limit them to the number of website that's accordigng to their plan"""
        "check customers plan, check customers website count"

        if re.match(self.pattern, self.url, flags=0):
            try:
                customer = Customer.get(id=self.customer)
            except DoesNotExist:
                return {"message": "Customer does not exist"}

            website_count = Website.select().where(
                Website.customer == customer.id).count()
            if customer.plan.quantity != 0 and customer.plan.quantity > website_count and customer.renewal_date != None:
                website = Website(url=self.url, customer=self.customer)
                website.save()
                message = "Website created successfully"
                return {"message": message}

            if customer.plan.quantity == 0 and customer.renewal_date != None:
                website = Website(url=self.url, customer=self.customer)
                website.save()
                message = "Website created successfully"
                return {"message": message}

            if customer.renewal_date == None:
                return {"message": "Sorry, your plan has expired"}

            else:
                return {
                    "message":
                    "Sorry, you can't add more websites, your have exceeded your subscription limit"
                }
        else:
            return {"message": "Invalid website"}
Example #2
0
def website_from_profile(profile, cluster):
    website = Website(account_key=profile.account_key,
                      return_url=profile.return_url,
                      website_name=profile.website_name,
                      website_url=profile.website,
                      cluster=cluster)
    website.save()
    return website
Example #3
0
def add(request):
    name=request.POST['name']
    url=request.POST['url']
    number=request.POST['number']
    keywords=request.POST['words']
    """
    If the website already exists, then we update it. Otherwise, we create 
    a new one.
    """
    w1=Website.objects.filter(url=url)
    """
    At this point, the previous entry for this website is deleted, rather than 
    updated. The idea is that it is faster to delete the old record, rather 
    than searching through each of its fields to check which ones need to be 
    updated and which do not.
    """
    if w1!=[]:
        w1.name=name
        w1.number=number
        w1.delete()
    #Now we add the website to the database.
    w1=Website(name=name, url=url, number=number)
    w1.save()
    """Remove blank spaces from words and separate into separate entries in 
    a list, rather than just a string.
    """   
    keywords=stl(keywords)
    """
    Add the keywords that describe this Website. If the keyword already 
    exists, then we find it and name it k1. Otherwise, we create a 
    new Keyword.
    """
    for keyword in keywords:
        try:
            k1=Keyword.objects.get(name=keyword)
            w1.words.add(k1)
        except Keyword.DoesNotExist:
            #Create the new Keyword and save it.
            k1=Keyword(name=keyword)
            k1.save()
            #add this word to the Website
            w1.words.add(k1)
Example #4
0
    def test_clean_website_url(self):

        user = User.objects.create_user(username="******", password='******')
        user.save()

        cluster = WebsiteCluster(creator=user)
        cluster.save()

        website = Website(website_url="http://website.com/", cluster=cluster)
        website.save()

        variants = [
            "http://website.com",
            "https://website.com/",
        ]

        for variant in variants:
            clean = clean_website_url(variant)
            website = Website.objects.get(website_url__contains=clean)
            self.assertTrue(website is not None)
Example #5
0
def success(request):
  website = None
  tmpname = request.POST['website_name']
  tmpurl = request.POST['website_url']
  try:
    website = Website.objects.get(url=tmpurl)
  except Website.DoesNotExist:
    website = Website(name=tmpname, url=tmpurl)
    website.save()
  data = json.loads(request.POST['ads'])
  for ad in data:
    a = Ad(name=ad['fields']['name'],
        age=ad['fields']['age'],
        ethnicity=ad['fields']['ethnicity'],
        phone_number=ad['fields']['phone_number'],
        location=ad['fields']['location'],
        ad=ad['fields']['ad'],
        date=ad['fields']['date'],
        website=website)
    a.save()
  return HttpResponse("Success! <a href=\"/upload/\">Add More</a> <a href=\"/\">Home</a>")
Example #6
0
def signup(request):
    if request.method == 'POST': 
        form = SignupForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            fullname = form.cleaned_data['fullname']
            password = form.cleaned_data['password']
            url = str(form.cleaned_data['url']).lower()
            # creating the fresh user
            user = User(fullname=fullname, email=email, password=password, type=1)
            user.save()
            # creating activation record for the fresh user
            User_Activation(user=user).save()
            
            description =''
            res = get_http_response(url)
            # saving website's description
            if res:
                description=get_site_description(res)[0:510]
                if len(description) >= 507:
                    description=description[0:507]+'...'
                    
            name=extract_website_name(remove_landing_url(url))
            
            # insert the url to websites table in an unverified state 
            # associated to the fresh user -- custom validator made sure that no
            # record with same url is verified yet
            website = Website(url=url, name=name, description=description, type=1)
            website.save()
            
            # saving website's icon
            favicon_url = get_site_favicon_url(remove_landing_url(url)) or ''
            if favicon_url:
                favicon_content = http_read(favicon_url) or ''
                if favicon_content:
                    filename32 = make_random_string(32)+'.png'
                    filename48 = make_random_string(32)+'.png'
                    filename64 = make_random_string(32)+'.png'
                    favicon32 = ContentFile(normalize_img((32,32),favicon_content))
                    favicon48 = ContentFile(normalize_img((48,48),favicon_content))
                    favicon64 = ContentFile(normalize_img((64,64),favicon_content))
                    website.favicon32.save(filename32, favicon32)
                    website.favicon48.save(filename48, favicon48)
                    website.favicon64.save(filename64, favicon64)
            
            # first site screenshot insertion
            screenshot_name = make_random_string(32)+'.png'
            
            screenshot_image_content = site_screenshot(url)
            if screenshot_image_content:
                p = ImageFile.Parser()
                p.feed(screenshot_image_content)
                im=p.close()
                screenshot_image_content = ContentFile(normalize_img((im.size[0]/2,im.size[1]/2),screenshot_image_content))
                wi = Website_Image(name=name, website=website)
                wi.image.save(screenshot_name, screenshot_image_content)
            # the actual user-website association creation
            User_Website(user=user,website=website).save()
            response = HttpResponse('Signup successful, please activate via email')
            return response
    # request.method is GET
    else:
        form = SignupForm() # An unbound form
        
    return render_form('signup_form.html', form, '', request)