Repository: dotkom/onlineweb4

Issue:
Links to company websites doesn't work without http:// 
On a company profile page the link to the company's website will only redirect the user if `http://` is specified when the link is added in the dashboard. For example, the link to AppearTV is written as `www.appeartv.com`, and redirects to `https://online.ntnu.no/company/60/www.appeartv.com`.
There is no information to the user creating an event to add http either, so I can imagine this being a growing problem. 

Links to company websites doesn't work without http:// 
On a company profile page the link to the company's website will only redirect the user if `http://` is specified when the link is added in the dashboard. For example, the link to AppearTV is written as `www.appeartv.com`, and redirects to `https://online.ntnu.no/company/60/www.appeartv.com`.
There is no information to the user creating an event to add http either, so I can imagine this being a growing problem. 



Discussion:
Protocol should be included. Needs more validation. Double check if it is
an URLField.

On Wed, 12 Oct 2016, 13:15 Andrea Nornes, notifications@github.com wrote:

> On a company profile page the link to the company's website will only
> redirect the user if http:// is specified when the link is added in the
> dashboard. For example, the link to AppearTV is written as
> www.appeartv.com, and redirects to
> https://online.ntnu.no/company/60/www.appeartv.com.
> There is no information to the user creating an event to add http either,
> so I can imagine this being a growing problem.
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> https://github.com/dotKom/onlineweb4/issues/1718, or mute the thread
> https://github.com/notifications/unsubscribe-auth/AFK96xbIMPYrpn6TYtkwrHqhOA7VYBklks5qzMFhgaJpZM4KUo96
> .

Tip: https://docs.djangoproject.com/en/1.10/ref/validators/#urlvalidator
Use Django's validators for things like these.

Not using URLField was done deliberately: #695
I just checked though and none of the current URLs use markdown so it's safe to change back to URLField. 

IMO fields like these should be rendered using the [urlize](https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#urlize) filter. 

We can manually grab the hostname without the protocol if that's what that issue targets. This enables us to use the URLValidator.

ATM we hope the url field is a URL, and we create a href to the "webpage". Look at this: https://online.ntnu.no/company/19/.

Which is what this issue targets.

If it's an URL to be placed in the field, let it be validated by the URLValidator.

Protocol should be included. Needs more validation. Double check if it is
an URLField.

On Wed, 12 Oct 2016, 13:15 Andrea Nornes, notifications@github.com wrote:

> On a company profile page the link to the company's website will only
> redirect the user if http:// is specified when the link is added in the
> dashboard. For example, the link to AppearTV is written as
> www.appeartv.com, and redirects to
> https://online.ntnu.no/company/60/www.appeartv.com.
> There is no information to the user creating an event to add http either,
> so I can imagine this being a growing problem.
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> https://github.com/dotKom/onlineweb4/issues/1718, or mute the thread
> https://github.com/notifications/unsubscribe-auth/AFK96xbIMPYrpn6TYtkwrHqhOA7VYBklks5qzMFhgaJpZM4KUo96
> .

Tip: https://docs.djangoproject.com/en/1.10/ref/validators/#urlvalidator
Use Django's validators for things like these.

Not using URLField was done deliberately: #695
I just checked though and none of the current URLs use markdown so it's safe to change back to URLField. 

IMO fields like these should be rendered using the [urlize](https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#urlize) filter. 

We can manually grab the hostname without the protocol if that's what that issue targets. This enables us to use the URLValidator.

ATM we hope the url field is a URL, and we create a href to the "webpage". Look at this: https://online.ntnu.no/company/19/.

Which is what this issue targets.

If it's an URL to be placed in the field, let it be validated by the URLValidator.


Resolving patch:
diff --git a/apps/companyprofile/dashboard/forms.py b/apps/companyprofile/dashboard/forms.py
--- a/apps/companyprofile/dashboard/forms.py
+++ b/apps/companyprofile/dashboard/forms.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 from django.forms import ModelForm
+from django.forms.fields import URLField
 
 from apps.companyprofile.models import Company
 from apps.dashboard.widgets import widget_generator
@@ -7,10 +8,12 @@
 
 
 class CompanyForm(ModelForm):
+    site = URLField(max_length=100)
 
     class Meta(object):
         model = Company
         fields = ('name', 'short_description', 'long_description', 'image', 'site', 'email_address', 'phone_number',)
+
         exclude = ['old_image']
 
         # Widget generator accepts a form widget, and a list of tuples between field name and an attribute dict


Test patch: